wheattoast11 commited on
Commit
ae70733
·
verified ·
1 Parent(s): fe2d96b

Upload train_lfm_v2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_lfm_v2.py +99 -0
train_lfm_v2.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "trl>=0.12.0",
5
+ # "peft>=0.7.0",
6
+ # "transformers>=4.36.0",
7
+ # "accelerate>=0.24.0",
8
+ # "trackio",
9
+ # "datasets",
10
+ # ]
11
+ # ///
12
+
13
+ """
14
+ Agent Zero SFT v2: LiquidAI/LFM2.5-1.2B-Instruct
15
+ LoRA fine-tuning on mixed agent-zero-sft-v2 dataset.
16
+
17
+ Changes from v1:
18
+ - Mixed dataset: 40% agent + 40% math (MetaMathQA) + 20% general (OpenHermes)
19
+ - LoRA r=8 (was 16), alpha=16 (was 32) — reduced rank to prevent overfitting
20
+ - 2 epochs (was 3)
21
+ - lr=1e-4 (was 2e-4) — gentler updates
22
+ """
23
+
24
+ import os
25
+
26
+ import trackio
27
+ from datasets import load_dataset
28
+ from huggingface_hub import login
29
+ from peft import LoraConfig
30
+ from trl import SFTTrainer, SFTConfig
31
+
32
+ token = os.getenv("HF_TOKEN")
33
+ if token:
34
+ login(token=token)
35
+
36
+ # Load v2 mixed dataset
37
+ print("Loading dataset...")
38
+ train_ds = load_dataset("wheattoast11/agent-zero-sft-v2", split="train")
39
+ val_ds = load_dataset("wheattoast11/agent-zero-sft-v2", split="validation")
40
+ print(f"Train: {len(train_ds)}, Val: {len(val_ds)}")
41
+
42
+ config = SFTConfig(
43
+ output_dir="agent-zero-lfm-1.2b-v2",
44
+ push_to_hub=True,
45
+ hub_model_id="wheattoast11/agent-zero-lfm-1.2b-v2",
46
+ hub_strategy="every_save",
47
+ hub_private_repo=True,
48
+
49
+ # v2: 2 epochs (was 3)
50
+ num_train_epochs=2,
51
+ per_device_train_batch_size=4,
52
+ gradient_accumulation_steps=4, # effective batch size 16
53
+ # v2: lr=1e-4 (was 2e-4)
54
+ learning_rate=1e-4,
55
+ bf16=True,
56
+
57
+ logging_steps=10,
58
+ save_strategy="steps",
59
+ save_steps=200,
60
+ save_total_limit=2,
61
+
62
+ eval_strategy="steps",
63
+ eval_steps=200,
64
+
65
+ warmup_ratio=0.1,
66
+ lr_scheduler_type="cosine",
67
+
68
+ report_to="trackio",
69
+ project="agent-zero-finetune",
70
+ run_name="lfm-1.2b-sft-v2",
71
+ )
72
+
73
+ # v2: r=8 (was 16), alpha=16 (was 32), ratio stays 2.0
74
+ peft_config = LoraConfig(
75
+ r=8,
76
+ lora_alpha=16,
77
+ lora_dropout=0.05,
78
+ bias="none",
79
+ task_type="CAUSAL_LM",
80
+ target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
81
+ )
82
+
83
+ print("Initializing trainer...")
84
+ trainer = SFTTrainer(
85
+ model="LiquidAI/LFM2.5-1.2B-Instruct",
86
+ train_dataset=train_ds,
87
+ eval_dataset=val_ds,
88
+ args=config,
89
+ peft_config=peft_config,
90
+ )
91
+
92
+ print("Starting training...")
93
+ trainer.train()
94
+
95
+ print("Pushing to Hub...")
96
+ trainer.push_to_hub()
97
+
98
+ trackio.finish()
99
+ print("Done! Model at: https://huggingface.co/wheattoast11/agent-zero-lfm-1.2b-v2")