burtenshaw HF Staff commited on
Commit
283e370
ยท
verified ยท
1 Parent(s): 0c84c04

Upload train_qwen3_codeforces.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_qwen3_codeforces.py +94 -0
train_qwen3_codeforces.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # dependencies = [
3
+ # "trl>=0.18.0",
4
+ # "peft>=0.7.0",
5
+ # "transformers>=4.51.0",
6
+ # "accelerate>=0.24.0",
7
+ # "trackio",
8
+ # "bitsandbytes",
9
+ # ]
10
+ # ///
11
+
12
+ import trackio
13
+ from datasets import load_dataset
14
+ from peft import LoraConfig
15
+ from trl import SFTTrainer, SFTConfig
16
+
17
+ # Load dataset
18
+ print("๐Ÿ“ฆ Loading dataset...")
19
+ dataset = load_dataset("open-r1/codeforces-cots", split="train")
20
+ print(f"โœ… Dataset loaded: {len(dataset)} examples")
21
+
22
+ # Create train/eval split
23
+ print("๐Ÿ”€ Creating train/eval split...")
24
+ dataset_split = dataset.train_test_split(test_size=0.02, seed=42)
25
+ train_dataset = dataset_split["train"]
26
+ eval_dataset = dataset_split["test"]
27
+ print(f" Train: {len(train_dataset)} examples")
28
+ print(f" Eval: {len(eval_dataset)} examples")
29
+
30
+ # Training configuration
31
+ config = SFTConfig(
32
+ # Hub settings
33
+ output_dir="qwen3-codeforces-cots-sft",
34
+ push_to_hub=True,
35
+ hub_model_id="burtenshaw/qwen3-codeforces-cots-sft",
36
+ hub_strategy="every_save",
37
+
38
+ # Training parameters
39
+ num_train_epochs=1,
40
+ per_device_train_batch_size=2,
41
+ gradient_accumulation_steps=8,
42
+ learning_rate=2e-4,
43
+ max_length=4096,
44
+
45
+ # Logging & checkpointing
46
+ logging_steps=25,
47
+ save_strategy="steps",
48
+ save_steps=500,
49
+ save_total_limit=2,
50
+
51
+ # Evaluation
52
+ eval_strategy="steps",
53
+ eval_steps=500,
54
+
55
+ # Optimization
56
+ warmup_ratio=0.05,
57
+ lr_scheduler_type="cosine",
58
+ bf16=True,
59
+ gradient_checkpointing=True,
60
+
61
+ # Monitoring
62
+ report_to="trackio",
63
+ project="codeforces-sft",
64
+ run_name="qwen3-0.6b-codeforces-cots",
65
+ )
66
+
67
+ # LoRA configuration
68
+ peft_config = LoraConfig(
69
+ r=32,
70
+ lora_alpha=64,
71
+ lora_dropout=0.05,
72
+ bias="none",
73
+ task_type="CAUSAL_LM",
74
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
75
+ )
76
+
77
+ # Initialize and train
78
+ print("๐ŸŽฏ Initializing trainer...")
79
+ trainer = SFTTrainer(
80
+ model="Qwen/Qwen3-0.6B",
81
+ train_dataset=train_dataset,
82
+ eval_dataset=eval_dataset,
83
+ args=config,
84
+ peft_config=peft_config,
85
+ )
86
+
87
+ print("๐Ÿš€ Starting training...")
88
+ trainer.train()
89
+
90
+ print("๐Ÿ’พ Pushing to Hub...")
91
+ trainer.push_to_hub()
92
+
93
+ print("โœ… Complete! Model at: https://huggingface.co/burtenshaw/qwen3-codeforces-cots-sft")
94
+ print("๐Ÿ“Š View metrics at: https://huggingface.co/spaces/burtenshaw/trackio")