epinfomax commited on
Commit
90068b2
·
verified ·
1 Parent(s): 270c052

Upload train_script.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_script.py +83 -0
train_script.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio", "datasets"]
3
+ # ///
4
+
5
+ from datasets import load_dataset
6
+ from peft import LoraConfig
7
+ from trl import SFTTrainer, SFTConfig
8
+ import trackio
9
+
10
+ # 데이터셋 로드
11
+ print("데이터셋 로드 중...")
12
+ dataset = load_dataset("epinfomax/youtube-thumbnail-analysis", split="train")
13
+ print(f"데이터셋 크기: {len(dataset)}개")
14
+
15
+ # 학습/검증 분리
16
+ dataset_split = dataset.train_test_split(test_size=0.1, seed=42)
17
+
18
+ # LoRA 설정
19
+ peft_config = LoraConfig(
20
+ r=16,
21
+ lora_alpha=32,
22
+ lora_dropout=0.05,
23
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
24
+ task_type="CAUSAL_LM"
25
+ )
26
+
27
+ # 학습 설정
28
+ training_args = SFTConfig(
29
+ output_dir="./outputs",
30
+
31
+ # Hub 저장 (필수!)
32
+ push_to_hub=True,
33
+ hub_model_id="epinfomax/youtube-thumbnail-trend-analyzer",
34
+ hub_strategy="every_save",
35
+
36
+ # 학습 파라미터
37
+ num_train_epochs=3,
38
+ per_device_train_batch_size=2,
39
+ gradient_accumulation_steps=4,
40
+ learning_rate=2e-4,
41
+ warmup_ratio=0.1,
42
+
43
+ # 평가
44
+ eval_strategy="steps",
45
+ eval_steps=20,
46
+
47
+ # 저장
48
+ save_strategy="steps",
49
+ save_steps=50,
50
+ save_total_limit=2,
51
+
52
+ # 최적화
53
+ gradient_checkpointing=True,
54
+ bf16=True,
55
+
56
+ # Trackio 모니터링
57
+ report_to="trackio",
58
+ run_name="youtube-thumbnail-trainer",
59
+
60
+ # 로깅
61
+ logging_steps=10,
62
+ )
63
+
64
+ # 트레이너 생성
65
+ print("트레이너 초기화 중...")
66
+ trainer = SFTTrainer(
67
+ model="Qwen/Qwen2.5-0.5B",
68
+ train_dataset=dataset_split["train"],
69
+ eval_dataset=dataset_split["test"],
70
+ peft_config=peft_config,
71
+ args=training_args,
72
+ )
73
+
74
+ # 학습 시작
75
+ print("학습 시작!")
76
+ trainer.train()
77
+
78
+ # Hub에 최종 모델 저장
79
+ print("모델 Hub에 저장 중...")
80
+ trainer.push_to_hub()
81
+
82
+ print("학습 완료!")
83
+ print(f"모델 저장됨: https://huggingface.co/epinfomax/youtube-thumbnail-trend-analyzer")