Upload train_design_sft.py with huggingface_hub
Browse files- train_design_sft.py +98 -0
train_design_sft.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio", "datasets", "accelerate"]
|
| 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 |
+
# Load the validated Tailwind dataset (already in messages format)
|
| 13 |
+
tailwind_ds = load_dataset("summykai/tailwind-v4-sft-mix-001", split="train")
|
| 14 |
+
print(f"Tailwind dataset: {len(tailwind_ds)} examples")
|
| 15 |
+
|
| 16 |
+
# Load the high-quality UI generation dataset
|
| 17 |
+
uigen_ds = load_dataset("smirki/UIGEN-T1.1-TAILWIND", split="train")
|
| 18 |
+
print(f"UIGEN dataset: {len(uigen_ds)} examples")
|
| 19 |
+
|
| 20 |
+
# Format UIGEN dataset to messages format
|
| 21 |
+
def format_uigen_to_messages(example):
|
| 22 |
+
# Extract code from markdown code blocks if present
|
| 23 |
+
answer = example["answer"]
|
| 24 |
+
if answer.startswith("```html"):
|
| 25 |
+
answer = answer[7:] # Remove ```html
|
| 26 |
+
if answer.endswith("```"):
|
| 27 |
+
answer = answer[:-3] # Remove trailing ```
|
| 28 |
+
|
| 29 |
+
# Include the reasoning as part of a richer response
|
| 30 |
+
response = answer.strip()
|
| 31 |
+
|
| 32 |
+
return {
|
| 33 |
+
"messages": [
|
| 34 |
+
{"role": "user", "content": example["question"]},
|
| 35 |
+
{"role": "assistant", "content": response}
|
| 36 |
+
]
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
print("Formatting UIGEN dataset...")
|
| 40 |
+
uigen_formatted = uigen_ds.map(
|
| 41 |
+
format_uigen_to_messages,
|
| 42 |
+
remove_columns=uigen_ds.column_names
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Combine datasets
|
| 46 |
+
print("Combining datasets...")
|
| 47 |
+
combined_dataset = concatenate_datasets([tailwind_ds, uigen_formatted])
|
| 48 |
+
combined_dataset = combined_dataset.shuffle(seed=42)
|
| 49 |
+
|
| 50 |
+
print(f"Total training examples: {len(combined_dataset)}")
|
| 51 |
+
|
| 52 |
+
# Create train/eval split
|
| 53 |
+
dataset_split = combined_dataset.train_test_split(test_size=0.05, seed=42)
|
| 54 |
+
print(f"Train: {len(dataset_split['train'])}, Eval: {len(dataset_split['test'])}")
|
| 55 |
+
|
| 56 |
+
print("Initializing trainer...")
|
| 57 |
+
trainer = SFTTrainer(
|
| 58 |
+
model="chaddy81/qwen3-0.6b-multicode-sft",
|
| 59 |
+
train_dataset=dataset_split["train"],
|
| 60 |
+
eval_dataset=dataset_split["test"],
|
| 61 |
+
peft_config=LoraConfig(
|
| 62 |
+
r=32,
|
| 63 |
+
lora_alpha=64,
|
| 64 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 65 |
+
lora_dropout=0.05,
|
| 66 |
+
bias="none",
|
| 67 |
+
task_type="CAUSAL_LM"
|
| 68 |
+
),
|
| 69 |
+
args=SFTConfig(
|
| 70 |
+
output_dir="qwen3-0.6b-design-sft",
|
| 71 |
+
push_to_hub=True,
|
| 72 |
+
hub_model_id="chaddy81/qwen3-0.6b-design-sft",
|
| 73 |
+
num_train_epochs=3,
|
| 74 |
+
per_device_train_batch_size=2,
|
| 75 |
+
gradient_accumulation_steps=8,
|
| 76 |
+
learning_rate=2e-4,
|
| 77 |
+
lr_scheduler_type="cosine",
|
| 78 |
+
warmup_ratio=0.1,
|
| 79 |
+
max_length=4096,
|
| 80 |
+
logging_steps=10,
|
| 81 |
+
eval_strategy="steps",
|
| 82 |
+
eval_steps=100,
|
| 83 |
+
save_strategy="steps",
|
| 84 |
+
save_steps=200,
|
| 85 |
+
bf16=True,
|
| 86 |
+
gradient_checkpointing=True,
|
| 87 |
+
report_to="trackio",
|
| 88 |
+
run_name="qwen3-design-sft-v1",
|
| 89 |
+
)
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
print("Starting training...")
|
| 93 |
+
trainer.train()
|
| 94 |
+
|
| 95 |
+
print("Pushing to Hub...")
|
| 96 |
+
trainer.push_to_hub()
|
| 97 |
+
|
| 98 |
+
print("Training complete!")
|