maywell/korean_textbooks
Viewer • Updated • 4.42M • 1.19k • 124
How to use Eunma/korean-model with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("unsloth/qwen2.5-1.5b-instruct-unsloth-bnb-4bit")
model = PeftModel.from_pretrained(base_model, "Eunma/korean-model")How to use Eunma/korean-model with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Eunma/korean-model to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Eunma/korean-model to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Eunma/korean-model to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="Eunma/korean-model",
max_seq_length=2048,
)Qwen/Qwen2.5-1.5B-Instruct 를 기반으로 maywell/korean_textbooks 데이터셋, 그리고 LoRA(저랭크 적응) 기법을 사용해 파인튜닝한 어댑터(LoRA 가중치) 입니다. 베이스 가중치는 포함되지 않으며, 베이스 + 어댑터로 로드하여 사용합니다.
참고: 학습에는 Unsloth/TRL/PEFT 스택을 사용했고, 추론은 HF Transformers + PEFT만으로 가능합니다.
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
BASE = "Qwen/Qwen2.5-1.5B-Instruct"
ADAPTER = "Eunma/korean-model"
tokenizer = AutoTokenizer.from_pretrained(BASE)
base = AutoModelForCausalLM.from_pretrained(
BASE,
load_in_4bit=True,
device_map="auto",
trust_remote_code=True
)
model = PeftModel.from_pretrained(base, ADAPTER)
model.eval()
messages = [
{ "role": "system", "content": "한국어로 정확하고 친절하게 설명하는 교육 도우미입니다." },
{ "role": "user", "content": "2의 거듭제곱에 대해 간단히 설명해줘." },
]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
enc = tokenizer(prompt, return_tensors="pt").to(model.device)
if "attention_mask" not in enc:
enc["attention_mask"] = torch.ones_like(enc["input_ids"])
with torch.inference_mode():
out = model.generate(
**enc,
max_new_tokens=256,
do_sample=True, temperature=0.7, top_p=0.9,
pad_token_id=tokenizer.eos_token_id,
use_cache=True
)
print(tokenizer.decode(out[0], skip_special_tokens=True))
이 모델은 베이스 모델인 Qwen2.5-1.5B의 라이선스를 따릅니다.