Update README.md
Browse files
README.md
CHANGED
@@ -20,3 +20,62 @@ tags:
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
```
|
25 |
+
model = FastLanguageModel.get_peft_model(
|
26 |
+
model,
|
27 |
+
r=8, # 0λ³΄λ€ ν° μ΄λ€ μ«μλ μ ν κ°λ₯! 8, 16, 32, 64, 128μ΄ κΆμ₯λ©λλ€.
|
28 |
+
lora_alpha=16, # LoRA μν κ°μ μ€μ ν©λλ€.
|
29 |
+
lora_dropout=0.05, # λλ‘μμμ μ§μν©λλ€.
|
30 |
+
target_modules=[
|
31 |
+
"q_proj",
|
32 |
+
"k_proj",
|
33 |
+
"v_proj",
|
34 |
+
"o_proj",
|
35 |
+
"gate_proj",
|
36 |
+
"up_proj",
|
37 |
+
"down_proj",
|
38 |
+
], # νκ² λͺ¨λμ μ§μ ν©λλ€.
|
39 |
+
bias="none", # λ°μ΄μ΄μ€λ₯Ό μ§μν©λλ€.
|
40 |
+
# True λλ "unsloth"λ₯Ό μ¬μ©νμ¬ λ§€μ° κΈ΄ 컨ν
μ€νΈμ λν΄ VRAMμ 30% λ μ¬μ©νκ³ , 2λ°° λ ν° λ°°μΉ ν¬κΈ°λ₯Ό μ§μν©λλ€.
|
41 |
+
use_gradient_checkpointing="unsloth",
|
42 |
+
random_state=123, # λμ μνλ₯Ό μ€μ ν©λλ€.
|
43 |
+
use_rslora=False, # μμ μμ ν LoRAλ₯Ό μ§μν©λλ€.
|
44 |
+
loftq_config=None, # LoftQλ₯Ό μ§μν©λλ€.
|
45 |
+
)
|
46 |
+
|
47 |
+
from trl import SFTTrainer
|
48 |
+
from transformers import TrainingArguments
|
49 |
+
|
50 |
+
tokenizer.padding_side = "right" # ν ν¬λμ΄μ μ ν¨λ©μ μ€λ₯Έμͺ½μΌλ‘ μ€μ ν©λλ€.
|
51 |
+
|
52 |
+
# SFTTrainerλ₯Ό μ¬μ©νμ¬ λͺ¨λΈ νμ΅ μ€μ
|
53 |
+
trainer = SFTTrainer(
|
54 |
+
model=model, # νμ΅ν λͺ¨λΈ
|
55 |
+
tokenizer=tokenizer, # ν ν¬λμ΄μ
|
56 |
+
train_dataset=dataset, # νμ΅ λ°μ΄ν°μ
|
57 |
+
eval_dataset=dataset,
|
58 |
+
dataset_text_field="text", # λ°μ΄ν°μ
μμ ν
μ€νΈ νλμ μ΄λ¦
|
59 |
+
max_seq_length=max_seq_length, # μ΅λ μνμ€ κΈΈμ΄
|
60 |
+
dataset_num_proc=2, # λ°μ΄ν° μ²λ¦¬μ μ¬μ©ν νλ‘μΈμ€ μ
|
61 |
+
packing=False, # 짧μ μνμ€μ λν νμ΅ μλλ₯Ό 5λ°° λΉ λ₯΄κ² ν μ μμ
|
62 |
+
args=TrainingArguments(
|
63 |
+
per_device_train_batch_size=2, # κ° λλ°μ΄μ€λΉ νλ ¨ λ°°μΉ ν¬κΈ°
|
64 |
+
gradient_accumulation_steps=4, # κ·ΈλλμΈνΈ λμ λ¨κ³
|
65 |
+
warmup_steps=5, # μμ
μ€ν
μ
|
66 |
+
num_train_epochs=3, # νλ ¨ μν μ
|
67 |
+
max_steps=120, # μ΅λ μ€ν
μ
|
68 |
+
do_eval=True,
|
69 |
+
evaluation_strategy="steps",
|
70 |
+
logging_steps=1, # logging μ€ν
μ
|
71 |
+
learning_rate=2e-4, # νμ΅λ₯
|
72 |
+
fp16=not torch.cuda.is_bf16_supported(), # fp16 μ¬μ© μ¬λΆ, bf16μ΄ μ§μλμ§ μλ κ²½μ°μλ§ μ¬μ©
|
73 |
+
bf16=torch.cuda.is_bf16_supported(), # bf16 μ¬μ© μ¬λΆ, bf16μ΄ μ§μλλ κ²½μ°μλ§ μ¬μ©
|
74 |
+
optim="adamw_8bit", # μ΅μ ν μκ³ λ¦¬μ¦
|
75 |
+
weight_decay=0.01, # κ°μ€μΉ κ°μ
|
76 |
+
lr_scheduler_type="cosine", # νμ΅λ₯ μ€μΌμ€λ¬ μ ν
|
77 |
+
seed=123, # λλ€ μλ
|
78 |
+
output_dir="outputs", # μΆλ ₯ λλ ν 리
|
79 |
+
),
|
80 |
+
)
|
81 |
+
```
|