|
|
--- |
|
|
license: apache-2.0 |
|
|
base_model: Qwen/Qwen2.5-1.5B-Instruct |
|
|
tags: |
|
|
- qwen |
|
|
- qwen2.5 |
|
|
- lora |
|
|
- unsloth |
|
|
- korean |
|
|
- education |
|
|
- textbook |
|
|
language: |
|
|
- ko |
|
|
datasets: |
|
|
- maywell/korean_textbooks |
|
|
library_name: peft |
|
|
pipeline_tag: text-generation |
|
|
--- |
|
|
|
|
|
# ํ๊ตญ์ด ๊ต์ก ์๋ฃ ํ์ธํ๋ ๋ชจ๋ธ (Qwen2.5-1.5B + LoRA) |
|
|
|
|
|
## ๋ชจ๋ธ ์๊ฐ |
|
|
|
|
|
**Qwen/Qwen2.5-1.5B-Instruct** ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก **maywell/korean_textbooks** ๋ฐ์ดํฐ์
, ๊ทธ๋ฆฌ๊ณ |
|
|
**LoRA(์ ๋ญํฌ ์ ์)** ๊ธฐ๋ฒ์ ์ฌ์ฉํด ํ์ธํ๋ํ **์ด๋ํฐ(LoRA ๊ฐ์ค์น)** ์
๋๋ค. |
|
|
๋ฒ ์ด์ค ๊ฐ์ค์น๋ ํฌํจ๋์ง ์์ผ๋ฉฐ, **๋ฒ ์ด์ค + ์ด๋ํฐ**๋ก ๋ก๋ํ์ฌ ์ฌ์ฉํฉ๋๋ค. |
|
|
- ํ์ต ๋ฐฉ์: LoRA (QLoRA, 4bit ๋ก๋ฉ) |
|
|
- ์ฃผ์ ๋ชฉ์ : ํ๊ตญ์ด ๊ต์ก/์ค๋ช
ํ ์๋ต ํ์ง ํฅ์ |
|
|
|
|
|
> ์ฐธ๊ณ : ํ์ต์๋ Unsloth/TRL/PEFT ์คํ์ ์ฌ์ฉํ๊ณ , ์ถ๋ก ์ HF Transformers + PEFT๋ง์ผ๋ก ๊ฐ๋ฅํฉ๋๋ค. |
|
|
|
|
|
## ์ฌ์ฉ ๋ฐฉ๋ฒ |
|
|
|
|
|
### 1) ๋ชจ๋ธ ๋ก๋(4bit + PEFT) |
|
|
```python |
|
|
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)) |
|
|
``` |
|
|
|
|
|
## ํ๋ จ ์ ๋ณด |
|
|
|
|
|
- **๋ฒ ์ด์ค ๋ชจ๋ธ**: Qwen/Qwen2.5-1.5B |
|
|
- **ํ๋ จ ์คํ
**: 30 steps |
|
|
- **์ตํฐ๋ง์ด์ **: adamw_8bit |
|
|
- **์ค์ผ์ค๋ฌ**: linear |
|
|
- **LoRA ์ค์ **: r=8, alpha=16 |
|
|
- **ํ๊ฒ ๋ชจ๋**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
|
- **๋ฐ์ดํฐ์
**: maywell/korean_textbooks |
|
|
|
|
|
|
|
|
## ์์คํ
์๊ตฌ์ฌํญ |
|
|
|
|
|
- **GPU ๋ฉ๋ชจ๋ฆฌ**: ์ต์ 6GB (๊ถ์ฅ 8GB+) |
|
|
- ํ์ต(QLoRA, 4bit): GPU 12โ16GB ๊ถ์ฅ(T4 16GB์์ ํ์ธ) |
|
|
- **Python**: 3.10+ |
|
|
- **์ฃผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ**: transformers, peft, torch, bitsandbytes, accelerate |
|
|
|
|
|
## ์ฃผ์์ฌํญ |
|
|
1. ํ๊ตญ์ด ์ค์ฌ์ผ๋ก ํ๋. ํ ์ธ์ด ์๋ต ํ์ง์ ์ ํ์ ์ผ ์ ์์. |
|
|
2. ๋ฒ ์ด์ค ๋ผ์ด์ ์ค ๋ฐ ์ฌ์ฉ ์ ์ฑ
์ค์ |
|
|
3. ์ด๋ํฐ๋ง ํฌํจ๋์ด ์์ผ๋ฏ๋ก ๋ฒ ์ด์ค ๋ชจ๋ธ๊ณผ ํจ๊ป ๋ก๋ |
|
|
4. ์ฌ์ค์ฑ ๊ฒ์ฆ ํ์. |
|
|
|
|
|
## ๊ด๋ จ ๋งํฌ |
|
|
|
|
|
- **๋ฒ ์ด์ค ๋ชจ๋ธ**: [Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct) |
|
|
- **๋ฐ์ดํฐ์
**: [maywell/korean_textbooks](https://huggingface.co/datasets/maywell/korean_textbooks) |
|
|
- **PEFT(LoRA)**: https://github.com/huggingface/peft |
|
|
- **Transformers**: https://github.com/huggingface/transformers |
|
|
|
|
|
## ๐ ๋ผ์ด์ ์ค |
|
|
|
|
|
์ด ๋ชจ๋ธ์ ๋ฒ ์ด์ค ๋ชจ๋ธ์ธ Qwen2.5-1.5B์ ๋ผ์ด์ ์ค๋ฅผ ๋ฐ๋ฆ
๋๋ค. |
|
|
|