The Training Loop with TRL
The capstone of Pillar 2. Run a complete, instrumented SFT job with TRL's SFTTrainer — dataset to merged model — and learn to read the loss curve, choose the TrainingArguments levers, and diagnose the three failure modes (loss not decreasing, exploding, plateauing).
TRL is the canonical post-training library and SFTTrainer is the workhorse. v1.0 (March 31, 2026) ships 75+ methods, ~3M downloads/month, a Stability Contract, and a production CLI. It automates the steering mechanics — chat templates, completion masking, PEFT attachment, packing — so you spend time on data and hyperparameters, not glue code.
The loss curve is the EKG of your run, and three failure modes account for almost every bad run. Loss not decreasing → LR too low, data problem, or template bug (FT07). Loss exploding (NaN/spike) → LR too high, FP16 overflow (use BF16), or EOS/template bug. Loss plateauing → converged (eval flat and low) or stuck (eval rising = overfitting). The grad norm spike is the early-warning canary before the NaN.
The method sets the LR band, and mismatching them is the most common ticket. Full FT: 1e-5 to 5e-5. LoRA: 1e-4 to 5e-4 (an order of magnitude higher — adapters are small and random, needing faster learning against a frozen base). Full-FT LR on LoRA = no learning; LoRA LR on full FT = explosion.
Save, merge, and load are three operations with three purposes. Save writes what was trained (adapter or full). merge_and_unload folds the adapter into the base for single-model deployment. PeftModel.from_pretrained loads an adapter for hot-swapping — the FT00 swappability property in code.