chaddy81 commited on
Commit
8034635
·
verified ·
1 Parent(s): c534541

Upload train_qwen3_multidata.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_qwen3_multidata.py +90 -0
train_qwen3_multidata.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio", "datasets", "transformers", "accelerate", "bitsandbytes"]
3
+ # ///
4
+
5
+ from datasets import load_dataset, concatenate_datasets
6
+ from peft import LoraConfig
7
+ from trl import SFTTrainer, SFTConfig
8
+ import trackio
9
+
10
+ print("Loading datasets...")
11
+
12
+ # Dataset 1: Codeforces competitive programming (messages format)
13
+ ds1 = load_dataset(
14
+ "open-r1/codeforces-cots",
15
+ "solutions_w_editorials_py_decontaminated",
16
+ split="train"
17
+ )
18
+ ds1 = ds1.select_columns(["messages"])
19
+ print(f"Codeforces: {len(ds1)} examples")
20
+
21
+ # Dataset 2: Golang coder (messages format)
22
+ ds2 = load_dataset("smcleod/golang-coder", split="train")
23
+ ds2 = ds2.select_columns(["messages"])
24
+ print(f"Golang: {len(ds2)} examples")
25
+
26
+ # Dataset 3: Vue/Nuxt/Tailwind (text format - needs conversion)
27
+ ds3_raw = load_dataset("kevind13/vuejs-nuxt-tailwind-codellama", split="train")
28
+ # Convert text format to messages format for consistency
29
+ def text_to_messages(example):
30
+ return {"messages": [{"role": "user", "content": "Continue the code."}, {"role": "assistant", "content": example["text"]}]}
31
+ ds3 = ds3_raw.map(text_to_messages, remove_columns=ds3_raw.column_names)
32
+ print(f"Vue/Nuxt/Tailwind: {len(ds3)} examples")
33
+
34
+ # Dataset 4: React code instructions (messages format)
35
+ ds4 = load_dataset("cfahlgren1/react-code-instructions", split="train")
36
+ ds4 = ds4.select_columns(["messages"])
37
+ print(f"React: {len(ds4)} examples")
38
+
39
+ # Concatenate all datasets
40
+ combined = concatenate_datasets([ds1, ds2, ds3, ds4])
41
+ combined = combined.shuffle(seed=42)
42
+ print(f"Combined dataset: {len(combined)} examples")
43
+
44
+ # Create train/eval split
45
+ dataset_split = combined.train_test_split(test_size=0.05, seed=42)
46
+ print(f"Train: {len(dataset_split['train'])}, Eval: {len(dataset_split['test'])}")
47
+
48
+ print("Starting training...")
49
+
50
+ trainer = SFTTrainer(
51
+ model="Qwen/Qwen3-0.6B",
52
+ train_dataset=dataset_split["train"],
53
+ eval_dataset=dataset_split["test"],
54
+ peft_config=LoraConfig(
55
+ r=16,
56
+ lora_alpha=32,
57
+ lora_dropout=0.05,
58
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
59
+ bias="none",
60
+ task_type="CAUSAL_LM",
61
+ ),
62
+ args=SFTConfig(
63
+ output_dir="qwen3-0.6b-multicode",
64
+ push_to_hub=True,
65
+ hub_model_id="chaddy81/qwen3-0.6b-multicode-sft",
66
+ hub_private_repo=False,
67
+ num_train_epochs=1,
68
+ per_device_train_batch_size=2,
69
+ per_device_eval_batch_size=2,
70
+ gradient_accumulation_steps=8,
71
+ gradient_checkpointing=True,
72
+ learning_rate=2e-4,
73
+ lr_scheduler_type="cosine",
74
+ warmup_ratio=0.05,
75
+ logging_steps=10,
76
+ save_strategy="steps",
77
+ save_steps=500,
78
+ eval_strategy="steps",
79
+ eval_steps=500,
80
+ hub_strategy="every_save",
81
+ bf16=True,
82
+ report_to="trackio",
83
+ project="qwen3-multicode",
84
+ run_name="qwen3-0.6b-sft-multicode",
85
+ )
86
+ )
87
+
88
+ trainer.train()
89
+ trainer.push_to_hub()
90
+ print("Training complete! Model pushed to Hub.")