File size: 1,491 Bytes
e78dff9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# /// script
# dependencies = [
# "trl>=0.12.0",
# "peft>=0.7.0",
# "transformers>=4.36.0",
# "datasets>=2.14.0",
# ]
# ///
from datasets import load_dataset
from peft import LoraConfig
from trl import SFTTrainer, SFTConfig
import os
print("π Starting quick demo training...")
# Load a tiny subset of data
dataset = load_dataset("trl-lib/Capybara", split="train[:50]")
print(f"β
Dataset loaded: {len(dataset)} examples")
# Training configuration
config = SFTConfig(
# CRITICAL: Hub settings
output_dir="demo-qwen-sft",
push_to_hub=True,
hub_model_id="evalstate/demo-qwen-sft",
# Quick demo settings
max_steps=10, # Just 10 steps for quick demo
per_device_train_batch_size=2,
learning_rate=2e-5,
# Logging
logging_steps=2,
save_strategy="no", # Don't save checkpoints for quick demo
# Optimization
warmup_steps=2,
lr_scheduler_type="constant",
)
# LoRA configuration (reduces memory)
peft_config = LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM",
target_modules=["q_proj", "v_proj"],
)
# Initialize and train
trainer = SFTTrainer(
model="Qwen/Qwen2.5-0.5B",
train_dataset=dataset,
args=config,
peft_config=peft_config,
)
print("π Training for 10 steps...")
trainer.train()
print("πΎ Pushing to Hub...")
trainer.push_to_hub()
print("β
Complete! Model at: https://huggingface.co/evalstate/demo-qwen-sft")
|