09 - Post-Training & Fine-Tuning
A pretrained base model continues text; it does not follow instructions, refuse harmful requests, or reason step by step on demand. Post-training adds those behaviours: supervised fine-tuning on demonstrations, preference optimization, and reinforcement learning - including the RL-with-verifiable-rewards recipe behind today's reasoning models. The second half of the module does it by hand with the Hugging Face stack: LoRA and QLoRA configuration, instruction data with masked losses, reading loss curves, and benchmarking a fine-tune against its base - then the full SFT, DPO and GRPO sequence with TRL.
Learning objectives 14-18 hours (notes + labs, plus GPU time)
By the end of this module you will be able to:- Explain the post-training pipeline from SFT to preference tuning to RL, and what each stage changes in the model
- Compare RLHF with PPO, DPO-family methods and GRPO by what they need (reward model, critic, online samples) and what they cost
- Describe how RL with verifiable rewards produces long chain-of-thought reasoning
- Configure and run LoRA and QLoRA fine-tunes with masked instruction data, and diagnose runs from loss curves
- Benchmark a fine-tune against base and prompted baselines on quality, latency, VRAM and cost, and run SFT, DPO and GRPO with TRL
Prerequisites
- Foundation Models and PyTorch Fundamentals
- Pretraining at Scale - especially the training memory math
Chapter Map
Methods
| # | Note | Topic | Level |
|---|---|---|---|
| 1 | SFT & Parameter-Efficient Fine-Tuning | When to fine-tune, SFT and loss masking, LoRA and QLoRA, PEFT comparison, evaluating fine-tunes; a map of preference tuning and RL | Intermediate |
| 2 | Preference Optimization | Bradley-Terry reward models, DPO derivation and β, IPO, KTO, SimPO, ORPO, offline vs online | Advanced |
| 3 | RL for LLMs | PPO-RLHF, GRPO, RLVR, DAPO / Dr. GRPO / GSPO, reward sources and hacking, RL systems | Advanced |
| 4 | Reasoning Models & Test-Time Compute | R1-Zero and R1 recipes, distillation, self-consistency, best-of-N, budget forcing, effort dials, failure modes | Advanced |
Fine-Tuning in Practice
| # | Note | Topic | Level |
|---|---|---|---|
| 5 | HuggingFace Ecosystem | AutoModelForCausalLM/AutoTokenizer, tokenization, chat templates, datasets, the Hub | Beginner |
| 6 | LoRA & QLoRA Hands-On | LoRA config (rank/alpha/dropout/target modules), QLoRA (NF4, double quant), merging vs serving adapters | Intermediate |
| 7 | Instruction Data & Training Runs | Formatting instruction data, prompt/completion masking, reading loss curves, a hand-written PEFT training loop | Intermediate |
| 8 | Benchmarking Base vs Tuned | Held-out eval sets, quality delta, measured latency/tokens-per-sec, VRAM and cost-per-1k-requests | Advanced |
Code Labs
- QLoRA Fine-Tune - hands-on PEFT + QLoRA fine-tune with a base-vs-tuned benchmark, formatting and loss masking done by hand
- SFT, DPO & GRPO with TRL - the three post-training stages with TRL, including verifiable math rewards
Recommended Learning Paths
Path A: Theory, Then a First Fine-Tune
- Notes 1-4 in order - the methods and why each stage exists
- HuggingFace Ecosystem and LoRA & QLoRA Hands-On - the tools and what you are configuring
- Instruction Data & Training Runs - format your data and run the training loop
- QLoRA Fine-Tune Code Lab, then SFT, DPO & GRPO with TRL
- Benchmarking Base vs Tuned - prove the fine-tune actually helped
Path B: Interview Preparation (Accelerated)
- SFT & PEFT and Preference Optimization - the derivations interviewers ask for
- LoRA & QLoRA Hands-On - config parameters and merge-vs-serve questions are very common
- Benchmarking Base vs Tuned - "how do you know it worked" is a favorite follow-up question
- Q&A Review Bank - drill every question
Key Cross-References
- VRAM estimation and precision formats → Pretraining: GPU Memory & Hardware
- The raw-PyTorch training loop the hand-written PEFT loop extends → PyTorch Fundamentals: Training Loop From Scratch
- Measuring a fine-tune with a standard harness → Eval Harness lab - rerun it with your own fine-tune as the candidate
- Agent RL, which reuses GRPO and verifiers → Verifiers, Environments and Agent RL
Review
- Q&A Review Bank - interview-style questions across post-training and hands-on fine-tuning
- Module quiz - every Check Yourself question in this module
- Summary & Key Terms - a quick recap of this module and its essential vocabulary
Next Topic
Previous: 08 - Training LLMs from Scratch · Next: 10 - Introduction to AI Agents