|
|
|
|
|
|
|
|
|
|
|
|
|
|
from datasets import load_dataset |
|
|
from peft import LoraConfig |
|
|
from trl import SFTTrainer, SFTConfig |
|
|
import trackio |
|
|
|
|
|
|
|
|
print("데이터셋 로드 중...") |
|
|
dataset = load_dataset("epinfomax/youtube-thumbnail-analysis", split="train") |
|
|
print(f"데이터셋 크기: {len(dataset)}개") |
|
|
|
|
|
|
|
|
dataset_split = dataset.train_test_split(test_size=0.1, seed=42) |
|
|
|
|
|
|
|
|
peft_config = LoraConfig( |
|
|
r=16, |
|
|
lora_alpha=32, |
|
|
lora_dropout=0.05, |
|
|
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"], |
|
|
task_type="CAUSAL_LM" |
|
|
) |
|
|
|
|
|
|
|
|
training_args = SFTConfig( |
|
|
output_dir="./outputs", |
|
|
|
|
|
|
|
|
push_to_hub=True, |
|
|
hub_model_id="epinfomax/youtube-thumbnail-trend-analyzer", |
|
|
hub_strategy="every_save", |
|
|
|
|
|
|
|
|
num_train_epochs=3, |
|
|
per_device_train_batch_size=2, |
|
|
gradient_accumulation_steps=4, |
|
|
learning_rate=2e-4, |
|
|
warmup_ratio=0.1, |
|
|
|
|
|
|
|
|
eval_strategy="steps", |
|
|
eval_steps=20, |
|
|
|
|
|
|
|
|
save_strategy="steps", |
|
|
save_steps=50, |
|
|
save_total_limit=2, |
|
|
|
|
|
|
|
|
gradient_checkpointing=True, |
|
|
bf16=True, |
|
|
|
|
|
|
|
|
report_to="trackio", |
|
|
run_name="youtube-thumbnail-trainer", |
|
|
|
|
|
|
|
|
logging_steps=10, |
|
|
) |
|
|
|
|
|
|
|
|
print("트레이너 초기화 중...") |
|
|
trainer = SFTTrainer( |
|
|
model="Qwen/Qwen2.5-0.5B", |
|
|
train_dataset=dataset_split["train"], |
|
|
eval_dataset=dataset_split["test"], |
|
|
peft_config=peft_config, |
|
|
args=training_args, |
|
|
) |
|
|
|
|
|
|
|
|
print("학습 시작!") |
|
|
trainer.train() |
|
|
|
|
|
|
|
|
print("모델 Hub에 저장 중...") |
|
|
trainer.push_to_hub() |
|
|
|
|
|
print("학습 완료!") |
|
|
print(f"모델 저장됨: https://huggingface.co/epinfomax/youtube-thumbnail-trend-analyzer") |
|
|
|