Upload train_qwen3_codeforces.py with huggingface_hub
Browse files- train_qwen3_codeforces.py +19 -1
train_qwen3_codeforces.py
CHANGED
|
@@ -17,8 +17,13 @@ Dataset: Competitive programming with chain-of-thought reasoning.
|
|
| 17 |
import trackio
|
| 18 |
from datasets import load_dataset
|
| 19 |
from peft import LoraConfig
|
|
|
|
| 20 |
from trl import SFTTrainer, SFTConfig
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Load dataset with Python solutions (decontaminated)
|
| 23 |
print("Loading dataset open-r1/codeforces-cots...")
|
| 24 |
dataset = load_dataset(
|
|
@@ -28,6 +33,18 @@ dataset = load_dataset(
|
|
| 28 |
)
|
| 29 |
print(f"Dataset loaded: {len(dataset)} examples")
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Create train/eval split
|
| 32 |
print("Creating train/eval split...")
|
| 33 |
dataset_split = dataset.train_test_split(test_size=0.05, seed=42)
|
|
@@ -83,7 +100,7 @@ peft_config = LoraConfig(
|
|
| 83 |
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 84 |
)
|
| 85 |
|
| 86 |
-
# Initialize trainer
|
| 87 |
print("Initializing trainer with Qwen/Qwen3-0.6B...")
|
| 88 |
trainer = SFTTrainer(
|
| 89 |
model="Qwen/Qwen3-0.6B",
|
|
@@ -91,6 +108,7 @@ trainer = SFTTrainer(
|
|
| 91 |
eval_dataset=eval_dataset,
|
| 92 |
args=config,
|
| 93 |
peft_config=peft_config,
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
print("Starting training...")
|
|
|
|
| 17 |
import trackio
|
| 18 |
from datasets import load_dataset
|
| 19 |
from peft import LoraConfig
|
| 20 |
+
from transformers import AutoTokenizer
|
| 21 |
from trl import SFTTrainer, SFTConfig
|
| 22 |
|
| 23 |
+
# Load tokenizer first to apply chat template
|
| 24 |
+
print("Loading tokenizer...")
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6B")
|
| 26 |
+
|
| 27 |
# Load dataset with Python solutions (decontaminated)
|
| 28 |
print("Loading dataset open-r1/codeforces-cots...")
|
| 29 |
dataset = load_dataset(
|
|
|
|
| 33 |
)
|
| 34 |
print(f"Dataset loaded: {len(dataset)} examples")
|
| 35 |
|
| 36 |
+
# Formatting function to convert messages to text using chat template
|
| 37 |
+
def formatting_func(example):
|
| 38 |
+
"""Apply chat template to convert messages to text format."""
|
| 39 |
+
messages = example["messages"]
|
| 40 |
+
# Apply the tokenizer's chat template
|
| 41 |
+
text = tokenizer.apply_chat_template(
|
| 42 |
+
messages,
|
| 43 |
+
tokenize=False,
|
| 44 |
+
add_generation_prompt=False
|
| 45 |
+
)
|
| 46 |
+
return text
|
| 47 |
+
|
| 48 |
# Create train/eval split
|
| 49 |
print("Creating train/eval split...")
|
| 50 |
dataset_split = dataset.train_test_split(test_size=0.05, seed=42)
|
|
|
|
| 100 |
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# Initialize trainer with formatting function
|
| 104 |
print("Initializing trainer with Qwen/Qwen3-0.6B...")
|
| 105 |
trainer = SFTTrainer(
|
| 106 |
model="Qwen/Qwen3-0.6B",
|
|
|
|
| 108 |
eval_dataset=eval_dataset,
|
| 109 |
args=config,
|
| 110 |
peft_config=peft_config,
|
| 111 |
+
formatting_func=formatting_func,
|
| 112 |
)
|
| 113 |
|
| 114 |
print("Starting training...")
|