9.2 RLHF
Three stages. Only PPO samples the current policy. β=0 is reward hacking.
These notes match the lecture slides. Use (slides) on the course hub for the deck.
RLHF (InstructGPT / ChatGPT-style) is a three-stage stack: SFT, a reward model, then a policy optimized with RL (usually PPO) so sampled replies score high under the RM without wandering too far from SFT.
1. What RLHF is
RLHF is three stages, not one loss.
- SFT on instruction pairs (note 8.1). Call this .
- RM on chosen/rejected pairs (note 9.1).
- PPO: sample , score with , update .
After SFT and an RM, you sample from the current policy, score with , and update to raise reward minus KL to a frozen reference. Only stage 3 needs samples from the current policy. Stages 1–2 use a fixed dataset. If your code loads a CSV of completions and never calls generate inside the PPO loop, it is not on-policy RLHF.
PPO is on-policy: you need fresh rollouts from the current . That is expensive (generate, reward, critic). The critic (value head) estimates advantages so the policy gradient has lower variance. You do not need to derive PPO in this course; you need the picture and the KL term. InstructGPT is this stack at company scale; a seminar project usually stops at best-of- or DPO.
2. Why we use it
SFT does not explore. It copies answers that were already in the file. Best-of- uses only at decode: the policy itself never learns. RLHF trains to look high-reward as it samples, so the next draw is already better, not merely reranked.
PPO still exists because on-policy sampling can find replies that were never in the pair file. That is the conceptual parent of the week: preferences a scalar of “better” a policy that maximizes it with a leash. It works at company scale and is finicky in a seminar: sampling, KL, reward scale, and a moving policy. DPO (next note) skips the RM and the loop. Keep the three-box picture even if you never run PPO.
On-policy also means last week’s samples are stale: moved, so you generate again. That is the cost people are avoiding with DPO. For a project, running full PPO on an LLM is usually out of scope. Best-of- with a tiny RM, or DPO on a small classifier, is enough to show you understood the stack.
3. Architecture
Three frozen-or-moving pieces sit together at the PPO stage:
- Policy (moving).
- Reference (usually SFT, frozen).
- RM (frozen in the PPO stage).
- Optional critic / value head for advantages.

Why not the raw pretrained LM: the RM was trained on SFT-style answers. Leashing to the base model pulls you back to web-text, not to the assistant you already paid for. The three boxes are SFT, RM, and RL. Best-of- is already a strong baseline in AlpacaFarm-style studies; it is not a fourth box in this loop.
4. How it works, step by step
- Run SFT. Freeze that checkpoint as and as .
- Train the RM on pairs. Freeze .
- PPO loop. Sample a batch of new from the current . Score with . Estimate advantages with the critic. Update the policy with a clipped objective. Subtract a KL penalty toward .
- Read . Large stays near SFT; small chases reward. In code this is often a per-token penalty .
- If , there is no leash. Expect reward to rise while KL explodes and the text becomes a caricature of the raters: long, flattering, or degenerate. That is reward hacking, not “learning faster.”
Without a constraint, hacks . The KL term is the method, not a footnote. You do not derive the PPO clip in this course; you need to know that a clip plus an advantage estimate is how the policy step is usually written, and that is the failure mode to name.
5. Mathematical formulas
The usual RLHF objective looks like
or, sampling from the current policy,
KL cartoon, two-word vocab . , :
Penalty . If , you subtract from reward; if , you subtract nothing and can spike. If , KL is 0 and the leash is silent at that instant.
6. Positive points and negative points
Positive.
- Can beat SFT on preference evals because the policy learns while it samples, not only at decode.
- On-policy rollouts can find replies that were never in the pair file.
- The KL leash is an explicit knob between “stay an assistant” and “chase the RM.”
- Best-of- remains a fair baseline on the same RM; PPO has to beat it.
Negative.
- Unstable and expensive: generate, reward, critic, and stale samples every time moves.
- RM misspecification becomes policy misspecification. Reward hacking is what looks like.
- Using the pretrained base as after SFT already moved the policy pulls you back to web-text.
- Drawing RLHF as one loss hides that only stage 3 is RL.
- Full PPO on an LLM is usually out of scope for a seminar project, which is why people look to DPO.
When not to. If you have pairs and a GPU but no appetite for a PPO stack, skip to DPO (next note) or stop at best-of-. If “to learn faster,” you are not running RLHF; you are maximizing a misspecified RM.
7. Teaching this note
About 35 minutes at the board: three boxes (SFT, RM, PPO), then write the KL objective and set vs large . Play the same Karpathy RLHF window 21:05–25:43 (and a minute after if he is still on comparisons). DPO is next; do not derive PPO.
8. Worked example
Stage check: a batch of instruction pairs SFT. A batch of RM. A batch of new samples from PPO. If your code loads a CSV of completions and never calls generate inside the PPO loop, it is not on-policy RLHF.
KL cartoon: two distributions on a 2-word vocab . , .
Penalty . If , you subtract from reward; if , you subtract nothing and can spike.
The three boxes are SFT, RM, and RL. Best-of- is already a strong baseline in AlpacaFarm-style studies. PPO still exists because on-policy sampling can find replies that were never in the pair file. InstructGPT is this stack at company scale; a seminar project usually stops at best-of- or DPO.
Why not the raw pretrained LM: the RM was trained on SFT-style answers. Leashing to the base model pulls you back to web-text, not to the assistant you already paid for.
9. Where students get stuck
- Drawing RLHF as one loss. It is three stages; only the last is RL.
- Setting “to learn faster” and then being surprised by reward hacking.
- Using the pretrained base as after SFT already moved the policy.
10. Video
Karpathy — Intro to Large Language Models. Play 21:05–25:43 (RLHF, comparison labels). Pause on the three-stage story: write, compare, then a loop that uses those comparisons. This clip will not derive PPO; the board does the KL leash.
11. Practice
-
Which of the three stages needs samples from the current policy, not a fixed dataset?
-
If , what failure mode should you expect?
-
Why is the SFT model rather than the raw pretrained LM?
-
, . What is , and what does that say about the leash at this instant?
-
Reward , , . What scalar is the objective ? If you raise to 4, who wins: the RM or the reference?