Section 09

Optimizing against the reward

Chasing a reward without breaking the model

The previous chapter gave us a learned reward: a number that scores how good a response is, distilled from human comparisons. That’s half of RLHF. The other half is the part we’ve carefully avoided naming so far: the algorithm that takes that reward and actually changes the model to earn more of it. That algorithm is Proximal Policy Optimization (PPO), and the next several chapters lean on it constantly. This short chapter gives you a working understanding of what it does and why, so the name stops being a black box. The full, rigorous construction (where the update rule comes from) is built from the ground up later, in the RL fundamentals section; here we just want the shape of the idea.

The goal: make high-reward responses more likely

Recall the framing from chapter 2: the model is a policypolicyIn RL, the thing that chooses actions — here, the language model itself, viewed as a distribution over next tokens given the context. RL post-training optimizes the policy.See in glossary → πθ\pi_\theta that, given a prompt, defines a probability distribution over responses. We now have a reward r(y)r(y) for any response yy. The objective is exactly what you’d guess. Produce responses the reward likes:

maximizeθ    Eyπθ[r(y)]\text{maximize}_\theta \;\; \mathbb{E}_{y \sim \pi_\theta}\big[\, r(y) \,\big]

Let’s read that off piece by piece. maximizeθ\text{maximize}_\theta means “adjust the parameters θ\theta to make the following quantity as large as possible.” θ\theta is the only thing we get to change. E\mathbb{E} is an expectation (an average) and the subscript yπθy \sim \pi_\theta says what we’re averaging over: responses yy sampled from the policy πθ\pi_\theta (the "\sim" is read “drawn from”). Inside the brackets, r(y)r(y) is the reward of one such response. Put together: it’s the expected reward the policy earns, averaged over all the responses it might generate, and we want to pick the weights that push that average up. Nothing here is new; it’s the expectation from chapter 2, now with a real reward attached.

The basic move to increase it is intuitive, and you don’t need any heavy machinery to picture it. Sample some responses from the current model. Score each with the reward. Then adjust the weights so that the responses that scored well become a little more probable, and the ones that scored badly become a little less probable. Repeat. Over many rounds, probability mass flows toward the kind of answers the reward rewards. (That “nudge up what worked, down what didn’t” is the seed of the policy gradientpolicy gradientA family of RL methods that directly adjust the policy’s parameters in the direction that increases expected reward, using the score-function (REINFORCE) estimator.See in glossary →, which the RL section explains in full.)

The danger: optimize too hard and the model breaks

If that were the whole story, you could just crank the optimizer. The catch is that the reward is a learned, imperfect proxy, and an optimizer pushed hard enough will find and exploit its flaws. Take steps that are too large, or run too long, and the policy drifts off into reward-hackingreward hackingWhen a policy finds ways to score high on the reward model without actually being better — exploiting quirks of an imperfect proxy. A central danger of RL post-training.See in glossary → territory: text that scores 9.8 under the reward model while being repetitive, sycophantic, or outright gibberish to a human. The optimizer is doing its job perfectly; the measure is the thing that’s wrong.

So the real problem RLHF has to solve isn’t “increase the reward”: that part is easy. It’s “increase the reward without wandering off into nonsense.” Everything distinctive about PPO is machinery for taking that walk carefully.

PPO’s answer: small steps, on a leash

PPOPPOProximal Policy Optimization (Schulman, 2017) — nudges the policy toward higher reward in small, clipped steps with a KL leash to a reference model. The RLHF workhorse: stable, simple, widely used.See in glossary → is the algorithm that does this carefully, and its name is the whole idea: proximal means stay close to where you are. It keeps two safeguards bolted onto the basic “nudge toward reward” loop:

  • Clipped updates. PPO refuses to move any single response’s probability too far in one step. Even if the reward says “make this way more likely,” the update is clipped to a modest change. This keeps each step inside a region the model can trust, so the optimizer takes many small, safe steps instead of a few reckless ones.
  • A KL penaltyKL penaltyA term added to the RLHF reward that subtracts β times the KL divergence from the reference policy, keeping the optimized model from drifting too far while chasing reward.See in glossary → to a reference. A frozen copy of the model from before RL — the reference modelreference modelA frozen copy of the policy (usually the SFT model) that RLHF and DPO stay close to via a KL penalty, preventing the optimized policy from drifting into degenerate text.See in glossary → (usually the SFT checkpoint) — acts as an anchor. PPO adds a penalty that grows as the policy’s output distribution drifts away from that reference, measured by the KL divergenceKL divergenceKullback–Leibler divergence — a measure of how far one probability distribution is from another. Used in post-training as a "leash" that keeps a model close to a reference policy.See in glossary → we met in chapter 3. The reward pulls the policy toward higher scores; the KL penalty pulls it back toward fluent, sensible language. The balance between the two is the leash.

Put together, the thing PPO actually optimizes is, in spirit:

Eyπθ[min ⁣(ρ(y)r(y),    clip ⁣(ρ(y),1ε,1+ε)r(y))]chase the reward, in clipped steps    βDKL(πθπref)don’t drift too far\underbrace{\mathbb{E}_{y \sim \pi_\theta}\Big[\, \min\!\big(\, \rho(y)\, r(y),\;\; \operatorname{clip}\!\big(\rho(y),\, 1-\varepsilon,\, 1+\varepsilon\big)\, r(y) \,\big) \Big]}_{\text{chase the reward, in clipped steps}} \;-\; \beta \cdot \underbrace{D_{\mathrm{KL}}\big(\pi_\theta \,\|\, \pi_{\text{ref}}\big)}_{\text{don't drift too far}}

Here ρ(y)=πθ(y)/πθold(y)\rho(y) = \pi_\theta(y) / \pi_{\theta_{\text{old}}}(y) is the probability ratio: how much more (or less) likely the update in progress has made response yy, compared to before the step. The clip\operatorname{clip} is the first safeguard written in symbols. Once ρ\rho leaves the band [1ε,1+ε][1-\varepsilon,\, 1+\varepsilon] (with ε\varepsilon typically around 0.20.2), the clipped term goes flat, and the min\min takes that cautious branch, so the objective stops rewarding any further movement of this response’s probability in this step. That is all “clipped updates” means: the gradient simply shuts off outside the band. (The exact objective swaps r(y)r(y) for a per-token advantage; chapter 17 builds it properly.) The coefficient β\beta sets how tight the leash is. The slider below lets you feel that tradeoff: too loose and the policy sprints off to game the reward; too tight and it never improves; the useful gains live in the middle. The step buttons show the other safeguard at work: clipped updates creep along the frontier toward the target, while a single unclipped leap overshoots it and lands in gibberish.

RLHF reward-vs-KL tradeoff
β is the KL-penalty coefficient — the leash length. Slide it to move the target, then step the optimizer to see why the steps are clipped.
clip windowKL from reference (drift) →raw reward →β=0.20 targetpolicy
policy: KL 0.00 · reward 0.00
Each clipped update moves the policy at most the width of the shaded window, walking it safely along the frontier toward the β target. An unclipped update takes the leap the reward gradient asks for.
Raw reward at target
0.875
KL from reference
1.300
Net = reward − β·KL
0.615
referencepolicy driftdegeneration
RLHF optimizes reward(x) − β·KL(π ‖ π_ref). β is the leash length. Pull it too loose and the policy sprints up the reward model's gradient into weird, off-distribution text — it games the proxy reward instead of getting genuinely better. Pull it too tight and the model never leaves the reference, so it barely improves. The net objective peaks in the middle: the concave frontier means each extra unit of drift buys less and less real reward, so there's a sweet-spot β where the leash is just long enough. Clipping is the second safeguard: it bounds how far any single update can move the policy (the shaded window), so the optimizer reaches the target in many small, trustworthy steps rather than one lurch that lands off the frontier.

The takeaway

That’s the working picture of PPO. Strip the names away and it’s just careful hill-climbing on the reward: sample responses, score them, nudge the policy toward the ones that scored well, but in proximal (small, clipped) steps, kept on a leash by a KL penalty to a frozen reference, so the policy gets better at the reward without drifting into nonsense. Two words — proximal and leashed — and the name stops being a mystery.

We’ve taken the update rule itself largely on faith here: why nudging toward higher-scoring samples is the right move, exactly what it means to “clip a step,” and how to judge whether a single response was good. Those are real questions with real answers, but the intuition above is enough to use “PPO” confidently as the optimizer that turns a reward into a better model.