The Practitioner's LLM Curriculum All weeks · Week 4
Week 04 · 9 hours · 8 sections · last reviewed 2026-04-01

RL for LLMs

Understand the modern RL stack — DPO over PPO, GRPO with verifiable rewards, and reward hacking as the universal failure mode.

Why this week is positioned where it is. The story has changed dramatically twice in the last three years. In 2022, RLHF (PPO + reward model + KL constraint) was the holy grail and the only path to a chat model worth serving. In 2024, DPO came out and showed you could skip the reward model entirely; most teams switched within a year. In 2025–26, reasoning models retrained the world: GRPO + verifiable rewards became central to producing models that could actually reason, and the RL story stopped being only about preferences and started being about correctness. This week is about that arc.


1. The RL story has changed twice

Three eras to understand:

2022–2024: The RLHF era. Train a base model with SFT. Train a reward model on human preferences. Use PPO to optimize the policy against the reward model, with a KL constraint to keep it close to the SFT model. This was hard. The hyperparameters are brittle, the reward model overfits, and you need three or four copies of the model in memory at training time. But it worked, and ChatGPT, Claude 1, and the early open-weight chat models all used it.

2024–2025: The DPO era. Direct Preference Optimization showed that if your goal is to optimize a KL-regularized reward, you can skip the reward model entirely and train on preference pairs directly. The math gives you a closed-form objective. Most teams switched. Variants proliferated — IPO, KTO, ORPO, SimPO — each with small refinements. By mid-2025, most production preference-tuning happened with one of these, not PPO.

2025–2026: The verifiable-reward era. Reasoning models changed the field. Models like DeepSeek-R1 and the o-series showed that you could train reasoning capability with RL on tasks where you can programmatically check the answer (math, code, formal verification). This decoupled "RL on LLMs" from the preference-tuning use case. The dominant algorithm here is GRPO — Group Relative Policy Optimization — which DeepSeek introduced and which has become the de facto choice for reasoning RL. It pairs perfectly with verifiable rewards: no value function, no reward model, just sample N completions and reward the ones that solve the task.

The practitioner question is no longer "how do I do RLHF" — it's "what kind of RL do I need, if any, and which flavor."


2. SFT vs preference tuning vs RL — the modern decision

Three categories of training-after-pretraining, with different prerequisites:

SFT (supervised fine-tuning). You have correct outputs to imitate. This is the easy one. Most teams stop here. We covered it Week 3.

Preference tuning (DPO and family). You have ranked pairs but can't write the perfect output. "Output A is better than output B" is easier to produce than "the perfect output is X." Useful for style, tone, brevity, formatting consistency, and most subjective quality goals.

RL with verifiable rewards. You have a programmatic way to check whether an output is correct. Math problems with known answers, code with passing tests, function calls with valid schemas. The reward signal is automatic and mostly un-hackable.

RL with a learned reward model (RLHF). You have a reward model trained on preferences and you're optimizing against it. Mostly frontier-lab territory in 2026; most production teams choose DPO instead.

The decision tree for a practitioner with a quality gap: 1. Can you write correct outputs? → SFT. 2. Can you rank outputs but not write the best? → DPO. 3. Can you programmatically verify outputs? → GRPO with verifiable rewards. 4. None of the above? → Stay with prompting; RL won't save you.


3. DPO and the preference-tuning family

DPO is the workhorse. Worth understanding the math, even if you'll mostly call a library.

The setup: you have a reference model π_ref (typically your SFT checkpoint), and you want to train a new policy π_θ that's better aligned to preferences. You have data of the form (prompt, chosen, rejected).

The DPO loss for a single pair:

L_DPO = -log σ(β · ((log π_θ(chosen) - log π_ref(chosen))
                  - (log π_θ(rejected) - log π_ref(rejected))))

The thing in the inner parentheses is the margin — how much more the policy prefers the chosen response than the reference does, minus the same for the rejected response. The loss pushes the margin up: chosen log-probs increase relative to reference, rejected log-probs decrease relative to reference.

The β parameter (typically 0.1–0.5) controls how aggressively the loss pulls the policy away from the reference. Higher β = tighter coupling to reference; lower β = bigger updates. Tuning β is the main knob.

Why this works without a reward model: under the math (Bradley–Terry assumption + KL regularization), the optimal RLHF policy has a closed form. DPO is just regressing toward that closed form directly. No reward model, no PPO, no rollouts.

Variants worth knowing:

In practice, DPO + careful data is hard to beat. The variants exist mostly as small wins on specific problems.

When DPO underperforms:

QuickCheck

You have 8,000 preference pairs from human annotators ranking outputs from your customer-support model. You want to align the model to those preferences. What's the right tool, and why?

  • PPO with a learned reward model — the canonical RLHF stack from 2022 is the proven choice for this exact task.

  • DPO — recovers most of PPO's benefit at a fraction of the engineering complexity, and 8,000 pairs is well above the dataset floor.

  • GRPO with verifiable rewards — modern RL has moved past preferences to verifiable signals.

  • SFT on the chosen responses only — preferences are noisy; just train on what you wanted.

Correct. DPO is the modern default for preference tuning at this scale. PPO works but at much higher engineering cost. GRPO is for verifiable rewards (math, code, etc.), not subjective preferences. SFT on chosen-only loses the contrastive signal that makes preference tuning effective.


4. Reward modeling done right (when you actually need it)

You need a reward model when:

Reward models are typically trained with the Bradley–Terry loss:

L = -log σ(r(chosen) - r(rejected))

where r(·) is a scalar produced by a transformer's last hidden state via a linear head. Training data: human preference pairs. Output: a function from text to scalar.

The fundamental risks:

Mitigations:


5. PPO and why it's mostly gone

PPO (Proximal Policy Optimization) was the algorithm of choice for RLHF in 2022–2023. The architecture: a policy, a value function (critic), a reward model, and a reference model — four model copies in memory. The core idea is conservative policy updates: each step is clipped so the policy doesn't move too far from the previous iteration.

Why it's mostly gone:

When you'd still reach for PPO:

For most practitioners in 2026, PPO is a piece of history to understand, not a tool to use.


6. GRPO and the reasoning revolution

The arrival of reasoning models redrew the map. Models like DeepSeek-R1 and the o-series showed that for tasks with verifiable rewards (math, code, formal logic), you can train reasoning capability with RL alone — sometimes without any preceding SFT at all.

The dominant algorithm: GRPO (Group Relative Policy Optimization), introduced by DeepSeek. The big simplifications versus PPO:

The training loop is roughly:

for batch in problems:
    completions = sample N from policy for each problem
    rewards = verifier(completions)            # 0 or 1
    advantages = rewards - mean_reward_per_group
    loss = -mean(advantages * log_prob(completions)) \
           + beta * KL(policy || ref)
    update policy

That's it. Compared to PPO this is dramatically simpler — you've eliminated the value function and the reward model. The price is that you need a verifier.

What this enabled:

What it doesn't do:


7. Reward hacking — the universal failure mode

Every RL method has one core failure mode: reward hacking. The policy optimizes the reward signal you specified, but in a way that fails the goal you actually wanted. The signal and the goal diverge, and the optimizer ruthlessly exploits the gap.

Classic examples:

The mitigations are imperfect:

There is no unhackable reward. The engineering question is what your reward signal can't be hacked into.

QuickCheck

During RLHF training, you notice your model's responses are getting steadily longer over training steps, even though length wasn't an explicit reward signal. What's most likely happening, and what should you do?

  • The model is learning to be more thorough; this is good. Continue training.

  • The reward model has a length bias from its preference data; retrain the reward model on length-normalized pairs.

  • The policy is reward-hacking length as a proxy for quality; tighten the KL constraint and add a length penalty.

  • The optimizer is unstable; lower the learning rate.

Correct. Length-creep during RLHF is the canonical reward-hacking signature. The fix isn't usually retraining the reward model (it'll learn a new bias) — it's tightening the KL constraint to bound policy drift and adding an explicit length penalty. The "fix the reward model" path tends to play whack-a-mole with new biases.


8. The practitioner playbook

What this all means in practice:

Default: don't reach for RL. SFT covers most needs. The operational complexity of RL is a 5–10× multiplier on training infrastructure and an even bigger multiplier on debugging time.

If you need preference tuning, use DPO. Not PPO. The DPO + LoRA combination is the modern preference-tuning stack — small enough to run on commodity infrastructure, expressive enough for most production needs.

If you need reasoning capability, use GRPO with verifiable rewards. Don't use PPO. Don't train a reward model unless you've exhausted alternatives.

Reward hacking is inevitable. Build evals that don't share signal with your training reward. Watch for the moment your policy gets very good at the reward and very bad at the held-out task. That's the moment to stop training, not push harder.

Keep the reference model. The KL constraint to a sane reference is the most important component of any RL training run. Tighten β when you see drift; loosen it when you need bigger updates.

Iterate. The 2026 best practice is "iterative RL": train, deploy, collect new preference data on policy outputs, retrain reward (if you have one), retrain policy. The first round is never the production model.


Build this week

Pick at least two:

  1. DPO from scratch. Implement DPO loss in PyTorch (it's a one-liner once you understand the math). Train on a small preference dataset like UltraFeedback. Compare to the reference model with pairwise eval.

  2. GRPO on a math task. Use TRL's GRPO trainer. Pick a math benchmark with verifiable answers (GSM8k, MATH). Train Llama 3.2 3B or Qwen 2.5 3B for a few hundred steps. See what changes.

  3. Reward hacking audit. Take a fine-tuned model (yours or open-source) that was trained with RLHF/DPO. Build a held-out eval that doesn't share signal with the training reward. Find the gap. Write up what was hacked.

  4. DPO vs SFT comparison. Take the same dataset, train one model with SFT and another with DPO using the SFT outputs as "chosen" and the original base model outputs as "rejected." Compare. The SFT-then-DPO pattern is common; understanding what each step does is valuable.

  5. Verifier design. Pick a non-trivial task (SQL generation, JSON extraction, regex matching). Design a verifier. Identify three ways the verifier could be gamed. This is the most important skill for verifiable-reward RL — and the easiest to underestimate.


Read this


Interview prompts

  1. Walk through the difference between SFT, DPO, and PPO. When is each appropriate, and what are their relative costs?
  2. Why did DPO largely replace PPO for preference tuning? What's the math behind it?
  3. What is reward hacking? Give three concrete examples and walk through the mitigations.
  4. Explain GRPO. What does it eliminate vs PPO, and what does it require in return?
  5. You're training a code-generation model with verifiable rewards (test pass/fail). What are three ways the policy might game this, and how do you guard against each?
  6. Walk through the modern training pipeline for a reasoning model. What's SFT, what's RL, what's the order?
  7. KL constraint in RLHF — what does it do, and what happens if you remove it?
  8. You have 5,000 preference pairs and need to ship in two weeks. Walk through your approach.
  9. Bradley–Terry reward modeling — what's the loss, what are the failure modes, how do you mitigate?
  10. A model trained with RLHF starts producing increasingly long, citation-heavy outputs that don't actually help users. What's happening and how do you fix it?

What "done" looks like

By the end of this week you should be able to:

If you can do those, you're ready for Week 5 — RAG, where we build the retrieval pipeline that handles most "model doesn't know" problems and the production-grade evaluation infrastructure that everything afterward will rely on.