Update README.md
Browse files
README.md
CHANGED
|
@@ -93,79 +93,4 @@ tags:
|
|
| 93 |
|
| 94 |
</details>
|
| 95 |
|
| 96 |
-
<details>
|
| 97 |
-
<summary>Fine-Tuning with Unsloth(SFT Trainer)</summary>
|
| 98 |
-
|
| 99 |
-
```python
|
| 100 |
-
|
| 101 |
-
from unsloth import FastLanguageModel
|
| 102 |
-
import torch
|
| 103 |
-
from trl import SFTTrainer
|
| 104 |
-
from transformers import TrainingArguments
|
| 105 |
-
|
| 106 |
-
max_seq_length = 256
|
| 107 |
-
dtype = None
|
| 108 |
-
load_in_4bit = False
|
| 109 |
-
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 110 |
-
model_name="HuggingFaceH4/zephyr-7b-beta",
|
| 111 |
-
max_seq_length=max_seq_length,
|
| 112 |
-
dtype=dtype,
|
| 113 |
-
load_in_4bit=load_in_4bit,
|
| 114 |
-
#token = ,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
model = FastLanguageModel.get_peft_model(
|
| 118 |
-
model,
|
| 119 |
-
r=32,
|
| 120 |
-
lora_alpha=64,
|
| 121 |
-
lora_dropout=0.05,
|
| 122 |
-
target_modules=[
|
| 123 |
-
"q_proj",
|
| 124 |
-
"k_proj",
|
| 125 |
-
"v_proj",
|
| 126 |
-
"o_proj",
|
| 127 |
-
"gate_proj",
|
| 128 |
-
"up_proj",
|
| 129 |
-
"down_proj",
|
| 130 |
-
], # 타겟 모듈
|
| 131 |
-
bias="none",
|
| 132 |
-
use_gradient_checkpointing="unsloth",
|
| 133 |
-
random_state=123,
|
| 134 |
-
use_rslora=False,
|
| 135 |
-
loftq_config=None,
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
tokenizer.padding_side = "right"
|
| 139 |
|
| 140 |
-
trainer = SFTTrainer(
|
| 141 |
-
model=model,
|
| 142 |
-
tokenizer=tokenizer,
|
| 143 |
-
train_dataset=dataset,
|
| 144 |
-
dataset_text_field="text",
|
| 145 |
-
max_seq_length=max_seq_length,
|
| 146 |
-
dataset_num_proc=2,
|
| 147 |
-
packing=False,
|
| 148 |
-
args=TrainingArguments(
|
| 149 |
-
per_device_train_batch_size=20,
|
| 150 |
-
gradient_accumulation_steps=2,
|
| 151 |
-
warmup_steps=5,
|
| 152 |
-
num_train_epochs=3,
|
| 153 |
-
max_steps = 1761,
|
| 154 |
-
logging_steps = 10,
|
| 155 |
-
learning_rate=2e-5,
|
| 156 |
-
fp16=not torch.cuda.is_bf16_supported(),
|
| 157 |
-
bf16=torch.cuda.is_bf16_supported(),
|
| 158 |
-
optim="adamw_8bit",
|
| 159 |
-
weight_decay=0.01,
|
| 160 |
-
lr_scheduler_type="cosine",
|
| 161 |
-
seed=123,
|
| 162 |
-
output_dir="outputs",
|
| 163 |
-
),
|
| 164 |
-
)
|
| 165 |
-
|
| 166 |
-
trainer.train()
|
| 167 |
-
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
</details>
|
|
|
|
| 93 |
|
| 94 |
</details>
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|