train-sft — SFT recipe
Use the working template at scripts/train_sft.py. Do not write the
trainer from scratch — TRL renames things every release.
Sequence (no shortcuts)
- Research — fire
research-recipeif you don't already have a paper- backed recipe. Capture: dataset, method, hyperparameters, reference URL. - Audit —
python scripts/inspect_dataset.py <dataset>. Confirm:- Columns match SFT format (
messages,text, orprompt+completion). - p95 sequence length informs
max_seq_length.
- Columns match SFT format (
- Config — copy
configs/sft_default.yamltoconfigs/<run-name>.yamland overridemodel.name_or_path,dataset.name, hyperparameters, and (when ready to ship)train.push_to_hub: true+train.hub_model_id. - Smoke test locally:
Loss must come down. Ifpython scripts/train_sft.py --config configs/<run-name>.yaml \ --max-steps 20 --max-samples 256push_to_hubis on, the smoke test creates the repo — that's fine. - Pre-flight block — print this to the user before scaling:
- Reference implementation: <paper / GH URL> - Dataset format verified : <yes — columns: …> - Model verified : <repo_id, arch, tokenizer> - push_to_hub : True, hub_model_id=<…> - Timeout : <≥2h> - Monitoring : Trackio dashboard URL - Scale — either:
- Local:
accelerate launch scripts/train_sft.py --config configs/<run>.yaml - HF Jobs:
python scripts/launch_hf_job.py --script scripts/train_sft.py --config configs/<run>.yaml --hardware <flavor> --timeout <≥2h> --hub-model-id <user/repo>
- Local:
Logging discipline (don't change)
In every TrainingArguments / SFTConfig:
disable_tqdm=True
logging_strategy="steps"
logging_first_step=True
logging_steps=10
report_to=["trackio"] # or ["wandb"] if WANDB_API_KEY is set
Loss prints as plain text lines you can grep.
OOM
Apply in this order, never changing the user's request:
- Halve
per_device_train_batch_size, doublegradient_accumulation_steps. gradient_checkpointing=True.optim="adamw_8bit"(bitsandbytes).bf16=True(Ampere+).- Larger GPU tier.
Do not silently switch full SFT to LoRA, drop max_seq_length, or remove
monitoring. Those change what the user gets.