Views
No views yet
pip install transformers accelerate bitsandbytes torch1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_name = "nxtcloud-org/kanana-safeguard-siren-8b-4bit"
5
6# BitsAndBytesConfig 설정
7bnb_config = BitsAndBytesConfig(
8 load_in_4bit=True,
9 bnb_4bit_use_double_quant=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.bfloat16
12)
13
14# 모델과 토크나이저 로드
15tokenizer = AutoTokenizer.from_pretrained(model_name)
16model = AutoModelForCausalLM.from_pretrained(
17 model_name,
18 quantization_config=bnb_config,
19 device_map="auto",
20 trust_remote_code=True
21)
22
23# 사용 예시 - 안전성 검증
24text = "이것은 검증할 텍스트입니다."
25inputs = tokenizer(text, return_tensors="pt")
26
27with torch.no_grad():
28 outputs = model.generate(
29 **inputs,
30 max_length=512,
31 temperature=0.7,
32 do_sample=True,
33 pad_token_id=tokenizer.eos_token_id
34 )
35
36result = tokenizer.decode(outputs[0], skip_special_tokens=True)
37print(result)Copyright 2025 Kakao Corp. (Original model)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.1@misc{kakao-kanana-safeguard-siren-8b,
2 title={Kanana Safeguard Siren 8B},
3 author={Kakao Corp},
4 year={2024},
5 publisher={Hugging Face},
6 url={https://huggingface.co/kakaocorp/kanana-safeguard-8b}
7}