Contents
Map

09 · Post-Training & Fine-Tuning

Overview

View as:

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

Chapter Map

Methods

#NoteTopicLevel
1SFT & Parameter-Efficient Fine-TuningWhen to fine-tune, SFT and loss masking, LoRA and QLoRA, PEFT comparison, evaluating fine-tunes; a map of preference tuning and RLIntermediate
2Preference OptimizationBradley-Terry reward models, DPO derivation and β, IPO, KTO, SimPO, ORPO, offline vs onlineAdvanced
3RL for LLMsPPO-RLHF, GRPO, RLVR, DAPO / Dr. GRPO / GSPO, reward sources and hacking, RL systemsAdvanced
4Reasoning Models & Test-Time ComputeR1-Zero and R1 recipes, distillation, self-consistency, best-of-N, budget forcing, effort dials, failure modesAdvanced

Fine-Tuning in Practice

#NoteTopicLevel
5HuggingFace EcosystemAutoModelForCausalLM/AutoTokenizer, tokenization, chat templates, datasets, the HubBeginner
6LoRA & QLoRA Hands-OnLoRA config (rank/alpha/dropout/target modules), QLoRA (NF4, double quant), merging vs serving adaptersIntermediate
7Instruction Data & Training RunsFormatting instruction data, prompt/completion masking, reading loss curves, a hand-written PEFT training loopIntermediate
8Benchmarking Base vs TunedHeld-out eval sets, quality delta, measured latency/tokens-per-sec, VRAM and cost-per-1k-requestsAdvanced

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

Path A: Theory, Then a First Fine-Tune

  1. Notes 1-4 in order - the methods and why each stage exists
  2. HuggingFace Ecosystem and LoRA & QLoRA Hands-On - the tools and what you are configuring
  3. Instruction Data & Training Runs - format your data and run the training loop
  4. QLoRA Fine-Tune Code Lab, then SFT, DPO & GRPO with TRL
  5. Benchmarking Base vs Tuned - prove the fine-tune actually helped

Path B: Interview Preparation (Accelerated)

  1. SFT & PEFT and Preference Optimization - the derivations interviewers ask for
  2. LoRA & QLoRA Hands-On - config parameters and merge-vs-serve questions are very common
  3. Benchmarking Base vs Tuned - "how do you know it worked" is a favorite follow-up question
  4. Q&A Review Bank - drill every question

Key Cross-References

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

⚡AI-assisted content - always verify, always explore multiple perspectives·