| | |
| | |
| | |
| |
|
| | from datasets import load_dataset |
| | from peft import LoraConfig |
| | from trl import SFTTrainer, SFTConfig |
| | import trackio |
| |
|
| | |
| | dataset = load_dataset( |
| | "open-r1/codeforces-cots", |
| | name="solutions_w_editorials_decontaminated", |
| | split="train" |
| | ) |
| |
|
| | |
| | dataset_split = dataset.train_test_split(test_size=0.1, seed=42) |
| |
|
| | |
| | peft_config = LoraConfig( |
| | r=16, |
| | lora_alpha=32, |
| | lora_dropout=0.05, |
| | target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"], |
| | task_type="CAUSAL_LM" |
| | ) |
| |
|
| | |
| | training_args = SFTConfig( |
| | output_dir="qwen3-0.6b-codeforces-instruct", |
| | |
| | |
| | num_train_epochs=3, |
| | per_device_train_batch_size=4, |
| | per_device_eval_batch_size=4, |
| | gradient_accumulation_steps=4, |
| | gradient_checkpointing=True, |
| | |
| | |
| | learning_rate=2e-4, |
| | lr_scheduler_type="cosine", |
| | warmup_ratio=0.1, |
| | optim="paged_adamw_8bit", |
| | |
| | |
| | eval_strategy="steps", |
| | eval_steps=100, |
| | logging_steps=10, |
| | save_strategy="steps", |
| | save_steps=200, |
| | save_total_limit=3, |
| | |
| | |
| | push_to_hub=True, |
| | hub_model_id="kneeraj/qwen3-0.6b-codeforces-instruct", |
| | hub_strategy="every_save", |
| | hub_private_repo=False, |
| | |
| | |
| | report_to="trackio", |
| | project="codeforces-finetuning", |
| | run_name="qwen3-0.6b-codeforces-sft", |
| | |
| | |
| | bf16=True, |
| | max_grad_norm=1.0, |
| | |
| | |
| | max_seq_length=2048, |
| | dataset_text_field="messages", |
| | packing=False, |
| | ) |
| |
|
| | |
| | trainer = SFTTrainer( |
| | model="Qwen/Qwen2.5-0.5B-Instruct", |
| | train_dataset=dataset_split["train"], |
| | eval_dataset=dataset_split["test"], |
| | peft_config=peft_config, |
| | args=training_args, |
| | ) |
| |
|
| | print("Starting training...") |
| | print(f"Training samples: {len(dataset_split['train'])}") |
| | print(f"Evaluation samples: {len(dataset_split['test'])}") |
| |
|
| | |
| | trainer.train() |
| |
|
| | |
| | print("Pushing final model to Hub...") |
| | trainer.push_to_hub() |
| |
|
| | print("Training complete! Model saved to: kneeraj/qwen3-0.6b-codeforces-instruct") |
| |
|