AI Alignment
Part II: Foundations

Draft complete but not yet reviewed; expect revisions

Reinforcement Learning

In brief

Ideas
  • Reinforcement learning trains assistants and reasoning models, so it is where a learner acquires what was specified or a proxy that scored the same; a policy gradient makes better-than-expected actions more probable (§12.1).
  • The KL-regularized optimum reweights the reference policy by exp⁡(r/β)\exp(r/\beta), and rarity protects only logarithmically: a response of reference probability p0p_0 dominates once its reward lead exceeds βlog⁡(1/p0)\beta \log(1/p_0) (§12.3).
  • Read as Bayesian updating, the optimum keeps the reference's odds among equally rewarded responses, but at the small KL weights of reasoning training it no longer predicts that training only sharpens (§12.4.2).
  • DPO reaches nearly the same reweighting by fitting a policy's implied reward to comparisons, with no reward model or sampling loop; best-of-n reweights by reward rank instead (§12.6.1).
Evidence
  • Theorem: the reweighted reference uniquely maximizes expected reward minus β\beta times KL, and no policy within the same KL budget earns more expected reward (§12.3.2).
  • Theorem: at the optimum, the probability of solving a training problem in kk attempts never falls below the reference policy's, for any kk and any β\beta (§12.7.4).
  • Experiment: in a 2025 preprint, GRPO on Qwen2.5-7B raised pass@1 on its training problems from 9.9 to 42.5 percent while pass@256 fell from 67.2 to 64.3, which no optimum does (§12.7.4).
Open
  • Limit: the KL penalty limits how far the policy moves, not which way the reward's errors point; the exact optimum can raise a proxy reward while the true reward peaks and falls (§12.8.1).
  • Limit: with verifiable rewards the grader is the specification: a flaw one sampled response finds gets a large advantage, larger the rarer the success in its group, and spreads (§12.7.5).

The previous chapters gave the reader two pieces: an agent that acts in an environment and receives reward (Chapter 7), and a language model that writes text one token at a time (Chapter 11). Reinforcement learning joins them. It is the family of methods that changes a policy, the rule by which a system chooses its actions, so that actions followed by higher reward become more probable. Assistants are fine-tuned this way from human preferences, and reasoning models are trained this way on problems whose answers a program can check. Most of what the book calls instillation, getting a learner to acquire what was specified rather than a proxy that scored the same in training, happens in this step. Nearly every claim in this chapter is therefore about the first of the book's three relationships: the training process and the signal it optimizes.

One equation carries much of the rest of the book. When reward is maximized with a penalty for moving away from the starting model, the best policy has a closed form: the starting model's probabilities, reweighted by exponentiated reward. The chapter builds up to that equation from the simplest learner, reads the methods that train today's assistants and reasoning models through it, and ends with what the penalty does not guarantee, where the chapter on optimization pressure (Chapter 15) takes over.

12.1 Learning from reward by gradient #

Gradient descent (Section 8.3) needs a loss whose slope it can compute with respect to every parameter. In supervised learning the data say what the output should have been, and the loss measures the difference. Learning from reward has neither. No one says what the right action was: the system tries an action, and the world returns a number. And the number cannot be differentiated, because the action was sampled, a discrete choice drawn at random, and the reward was computed outside the model, by a unit test, a person, or a game engine. No chain of derivatives runs from the reward back to the weights. This section shows how to follow the reward uphill anyway.

12.1.1 The idea: make what worked more probable #

Start small. A website can show one of five versions of a page per visit, and each visit ends in a noisy number, such as the time the visitor spent, with a fixed average for each version. The engineer wants a rule that shows the best version more often. In the vocabulary of reinforcement learning this is a bandit (after the slot machine, the one-armed bandit): five arms, one choice per round, and a reward after each choice.

A natural rule keeps a probability for each arm and, after each round, nudges the probability of the arm it just pulled: up if the reward was better than usual, down if it was worse. The table of probabilities is the policy, a rule that maps the current situation (here there is only one) to a probability distribution over actions. Each nudge is noisy, but over many rounds the nudges point, on average, toward the arms that pay more. The rest of the section makes "on average" exact.

12.1.2 The score-function estimator #

Write the policy as a softmax over a vector of parameters θ\theta, one number per arm, so that πθ(a)=eθa/∑a′eθa′\pi_\theta(a) = e^{\theta_a} / \sum_{a'} e^{\theta_{a'}} (the softmax of Section 8.1, which turns any vector of numbers into probabilities). Let r(a)r(a) be the reward of arm aa, and let the objective be the expected reward of the policy, J(θ)=Ea∼πθ[r(a)]=∑aπθ(a) r(a)J(\theta) = \E_{a \sim \pi_\theta}[r(a)] = \sum_a \pi_\theta(a)\, r(a). Gradient ascent on JJ would raise expected reward, but ∇θJ\nabla_\theta J requires knowing every r(a)r(a), which is exactly what the learner does not know. The trick is to rewrite the gradient as an expectation under the policy itself, so that a single sampled action gives an unbiased estimate of it.

Derivation The score-function estimator

Assume finitely many actions, a reward r(a)r(a) that does not depend on θ\theta (the world's response to an action does not change when the policy does), and πθ(a)>0\pi_\theta(a) > 0 for every aa, which the softmax guarantees.

  1. The objective is a finite sum, so the gradient passes inside it, and only the policy depends on θ\theta: ∇θJ=∑ar(a) ∇θπθ(a)\nabla_\theta J = \sum_a r(a)\, \nabla_\theta \pi_\theta(a).
  2. The derivative of a logarithm is the derivative of its argument divided by the argument, so ∇θlog⁡πθ(a)=∇θπθ(a)/πθ(a)\nabla_\theta \log \pi_\theta(a) = \nabla_\theta \pi_\theta(a) / \pi_\theta(a), and therefore ∇θπθ(a)=πθ(a) ∇θlog⁡πθ(a)\nabla_\theta \pi_\theta(a) = \pi_\theta(a)\, \nabla_\theta \log \pi_\theta(a). This is the log-derivative trick.
  3. Substituting turns the sum back into an expectation under the policy:
∇θJ(θ)=∑aπθ(a) r(a) ∇θlog⁡πθ(a)=Ea∼πθ[r(a) ∇θlog⁡πθ(a)].\nabla_\theta J(\theta) = \sum_a \pi_\theta(a)\, r(a)\, \nabla_\theta \log \pi_\theta(a) = \E_{a \sim \pi_\theta}\big[r(a)\, \nabla_\theta \log \pi_\theta(a)\big].
(12.1)

If the reward is noisy, r(a)r(a) in steps 1 to 3 is its mean, and a single observed reward is an unbiased draw of it, so nothing changes. Sampling one action a∼πθa \sim \pi_\theta, observing its reward rr, and computing r ∇θlog⁡πθ(a)r\, \nabla_\theta \log \pi_\theta(a) therefore gives an unbiased estimate of the gradient. For the softmax policy the last factor is simple. Taking the logarithm, log⁡πθ(a)=θa−log⁡∑a′eθa′\log \pi_\theta(a) = \theta_a - \log \sum_{a'} e^{\theta_{a'}}, and differentiating with respect to one parameter θj\theta_j gives ∂log⁡πθ(a)/∂θj=1[j=a]−πθ(j)\partial \log \pi_\theta(a) / \partial \theta_j = \mathbb{1}[j = a] - \pi_\theta(j), where the indicator 1[j=a]\mathbb{1}[j = a] is 1 when j=aj = a and 0 otherwise. The update raises the parameter of the pulled arm and lowers every other arm's parameter in proportion to its probability.

The vector ∇θlog⁡πθ(a)\nabla_\theta \log \pi_\theta(a) is called the score of the action, hence the estimator's name. Equation (12.1) is the rule of the previous subsection made exact: move the parameters in the direction that makes the sampled action more probable, by an amount proportional to the reward it earned. Williams set out algorithms of this form in 1992 under the name REINFORCE (Williams, 1992). Methods that follow such an estimate are policy-gradient methods, and the policy gradient theorem extends them to policies represented by function approximators acting over many steps (Sutton et al., 1999).

12.1.3 Baselines and the advantage #

The estimator is unbiased but noisy, and one source of noise is avoidable. If every arm pays between 0.8 and 1.5, every sampled arm is pushed up, and which arm is better shows only in the relative sizes of the pushes. Comparing each reward with what was expected would push a mediocre arm down and a good one up. Subtracting a baseline bb from the reward does this, at no cost in bias.

Derivation A baseline leaves the gradient unbiased

Let bb be any number that does not depend on the action aa about to be sampled. It may depend on θ\theta, on past rewards, or on the situation the policy is in. Then

Ea∼πθ[b ∇θlog⁡πθ(a)]=b∑aπθ(a) ∇θlog⁡πθ(a)=b∑a∇θπθ(a)=b ∇θ∑aπθ(a)=b ∇θ1=0.\E_{a \sim \pi_\theta}\big[b\, \nabla_\theta \log \pi_\theta(a)\big] = b \sum_a \pi_\theta(a)\, \nabla_\theta \log \pi_\theta(a) = b \sum_a \nabla_\theta \pi_\theta(a) = b\, \nabla_\theta \sum_a \pi_\theta(a) = b\, \nabla_\theta 1 = 0.

The first step takes bb outside the expectation, which is allowed because it does not depend on aa; the second is the log-derivative trick read backward; the third moves the gradient outside a finite sum; and the probabilities sum to one for every θ\theta. Subtracting bb from the reward in Equation (12.1) therefore changes no expectation, only the noise. If bb depended on the sampled action, the first step would fail, and so would the guarantee.

Williams proved the same condition for his algorithms: the update stays an unbiased estimate of the gradient whenever the baseline does not depend on the output about to be sampled (Williams, 1992). A good baseline is the reward the policy expects to earn, so that the quantity multiplying the score,

A(a)=r(a)−b,A(a) = r(a) - b,

is how much better the action did than expected. This is the advantage. In a problem with many states, the expected reward from a state is the value function V(s)V(s) of Section 7.4, and a network trained to predict it, often called a critic or value model, serves as a learned baseline.

one training runaverage of the 20 runsexact gradient0.00.20.40.60.81.0probability of the best arm050100150200250300update stepstart (uniform)These 20 runs after 300 steps: the best arm's probability averages 0.73, with a spread (standarddeviation) of 0.36 between runs; 5 of 20 runs end below one half.
one training runaverage of the 20 runsexact gradient0.00.20.40.60.81.0probability of the best arm0100200300update stepstart (uniform)These 20 runs after 300 steps: the best arm'sprobability averages 0.73, with a spread (standarddeviation) of 0.36 between runs; 5 of 20 runs endbelow one half.
Figure 12.1 Twenty training runs of a softmax policy on a five-armed bandit whose arms pay rewards with means 1.0, 1.2, 0.8, 1.5, and 1.1 (the fourth is best), each with normal noise of standard deviation 1. Thin blue lines are single runs, the thick blue line their average, and the dashed line the path of the exact gradient. The average falls below the exact path because some runs lock onto a wrong arm early and stay near zero. Turn the baseline on (an exponential moving average of past rewards): every update keeps the same expected direction, and fewer runs lock on. The readout describes the twenty runs shown; New runs draws another twenty. Everything is computed from the stated model; the means are illustrative.

Figure 12.1 runs the estimator on this bandit. Averaged over 4,000 runs (200 draws of twenty) at the default learning rate, the best arm's probability after 300 updates is 0.73 without a baseline, and 23 percent of runs end with it below one half. With a baseline, an exponential moving average of past rewards, the average is 0.86 and 7 percent of runs end below one half. The baseline did not change where updates point on average, only how far a single run strays, and that decides where some runs end: a few lucky rewards from a poor arm can push its probability so high that the run rarely samples anything else again.

Key idea

A policy gradient makes sampled actions that did better than expected more probable and those that did worse less probable; the baseline changes how noisy that signal is, not where it points.

12.1.4 Taking several steps safely: PPO #

Samples are expensive: for a language model, each one is a generated response. It is tempting to take several gradient steps on one batch, but after the first step the samples no longer come from the current policy. The authors of proximal policy optimization (PPO) report, in a 2017 preprint, that several steps on the plain policy-gradient loss with the same trajectories often lead to destructively large policy updates (Schulman et al., 2017). An earlier method, trust region policy optimization, constrained each update by the KL divergence between the new and the old policy (Schulman et al., 2015b), a measure of how far one distribution has moved from another (Section 6.3) that this chapter returns to at length.

PPO keeps the trust region's effect with a simpler device. Let ω(θ)=πθ(a)/πθold(a)\omega(\theta) = \pi_\theta(a) / \pi_{\theta_{\text{old}}}(a) be the ratio of the new policy's probability of a sampled action to the probability under the policy that sampled it. PPO maximizes the clipped surrogate objective

LCLIP(θ)=E[min⁡(ω(θ) A,  clip⁡(ω(θ),1−ϵ,1+ϵ) A)],L^{\text{CLIP}}(\theta) = \E\Big[\min\big(\omega(\theta)\, A,\; \operatorname{clip}\big(\omega(\theta), 1 - \epsilon, 1 + \epsilon\big)\, A\big)\Big],
(12.2)

where clip⁡\operatorname{clip} limits the ratio to the interval [1−ϵ,1+ϵ][1-\epsilon, 1+\epsilon] and the paper suggests values such as ϵ=0.2\epsilon = 0.2 (Schulman et al., 2017). Read it for one action with a positive advantage: the objective grows as the action becomes more probable, until its probability is 20 percent above where it was, and then it stops growing, so the optimizer has no reason to push further on this batch. A negative advantage is treated the same way from below. The clipping removes the incentive for moving the ratio outside the interval and makes the objective a pessimistic lower bound on the unclipped one. That lets PPO alternate between sampling and several passes (epochs) of minibatch updates over the same samples; in the authors' experiments, a variant that penalized the KL divergence instead performed worse (Schulman et al., 2017). PPO became the optimizer of the language-model pipeline in the next section.

12.1.5 Credit assignment #

One problem survives every refinement above. A language model often receives a single number for a response of a thousand tokens, and the estimator gives every token the same advantage. It cannot tell which tokens earned the reward and which merely came along. Assigning credit within a long response is the reason for per-token value functions, for rewards on each reasoning step rather than only the answer (Section 12.7), and for the token-level reading of preference methods (Section 12.6).

The advantage, reward received minus reward expected, has a proposed counterpart in the brain: the abstract of a 1997 paper by Schultz, Dayan, and Montague reports that the fluctuating output of dopamine neurons in primates apparently signals changes or errors in the predictions of future rewarding events (Schultz et al., 1997). Section 29.3 teaches that correspondence, and Section 29.5 the rival reading of what dopamine signals.

Sources cited in Section 12.1 5
  1. Williams (1992) Simple statistical gradient-following algorithms for connectionist reinforcement learning
  2. Sutton et al. (1999) Policy Gradient Methods for Reinforcement Learning with Function Approximation
  3. Schulman et al. (2017) Proximal Policy Optimization Algorithms
  4. Schulman et al. (2015b) Trust Region Policy Optimization
  5. Schultz et al. (1997) A Neural Substrate of Prediction and Reward

12.2 Language models as policies #

Everything above was written for arms and actions. To train a language model with it, the vocabulary has to be translated, and the translation has one choice in it that later sections depend on. In problems with many steps, an episode is one complete run from the first decision to the end, and its return is the total reward it collects (Section 7.4).

Table 12.1 Reinforcement learning terms and what they mean for a language model
Term For a language model
state ss the prompt xx and the tokens written so far
action aa the next token
policy πθ(a ∣ s)\pi_\theta(a \given s) the model's next-token distribution
episode one response yy to one prompt
reward usually one number r(x,y)r(x, y) for the whole response, given at the end
return that same number, since nothing is earned before the end
the policy over episodes πθ(y ∣ x)=∏tπθ(yt ∣ x,y<t)\pi_\theta(y \given x) = \prod_t \pi_\theta(y_t \given x, y_{<t})

The last row is the chain rule of probability (Section 6.1), applied to the autoregressive model of Section 11.1: the probability of a sequence is the product of each token's probability given the tokens before it, so its logarithm is a sum. That gives two views of one problem. In the bandit view, the whole response is one action, scored once; Equation (12.1) applies with yy in place of aa, and every token's score is multiplied by the same advantage. In the token-level view, each token is a decision in a process whose state grows one token at a time, and per-token value functions can assign credit within the response. Later sections use both.

12.2.1 The pipeline that made assistants #

Reinforcement learning from human feedback (RLHF) is the pipeline that turned pretrained language models into assistants. The developers of InstructGPT, at OpenAI, describe it as three steps (Ouyang et al., 2022). First, supervised fine-tuning: continue training the pretrained model by maximum likelihood on responses written by people as demonstrations of the desired behavior. Second, train a reward model: a network, written rϕr_\phi with parameters ϕ\phi, that reads a prompt and a response and outputs a score, fitted so that score differences predict which of two responses people preferred. Third, optimize the fine-tuned model with PPO against the reward model. How the reward model is fitted is taught in Chapter 13.

The method has a short lineage. A reward model learned from non-expert comparisons of short clips of an agent's behavior let agents solve Atari games and simulated locomotion without access to the true reward, with human feedback on less than one percent of their interactions (Christiano et al., 2017). Its likelihood follows the Bradley-Terry model of pairwise preference (Christiano et al., 2017), in which the probability that one item is preferred to another is the logistic function σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}) of the difference of their scores. Researchers at OpenAI applied the approach to pretrained language models in a 2019 preprint (Ziegler et al., 2019), to summarization in a 2020 paper (Stiennon et al., 2020), and to instruction following in the InstructGPT paper of 2022 (Ouyang et al., 2022). A 2022 preprint by Anthropic applied it to a helpful and harmless assistant of its own (Bai et al., 2022b).

The objective of the third step, in the form the paper gives for its models trained with PPO alone, adds one term to the reward (Ouyang et al., 2022):

Ex∼D,  y∼πθ(⋅ ∣ x)[rϕ(x,y)−βlog⁡πθ(y ∣ x)π0(y ∣ x)],\E_{x \sim \D,\; y \sim \pi_\theta(\cdot \given x)}\left[r_\phi(x, y) - \beta \log \frac{\pi_\theta(y \given x)}{\pi_0(y \given x)}\right],
(12.3)

where D\D is the distribution of prompts, π0\pi_0 the fine-tuned model training starts from, and β>0\beta > 0 the weight of the penalty. The paper describes its environment in the bandit view, one response per episode, but applies the term as a per-token KL penalty from the supervised model, added to mitigate over-optimization of the reward model (Ouyang et al., 2022). The models the paper calls InstructGPT also mix in the pretraining objective, to reduce regressions on public benchmarks (Ouyang et al., 2022). The expectation of the log-ratio under the policy is the KL divergence of the policy from the reference,

KL⁡(πθ ∥ π0)=Ey∼πθ[log⁡πθ(y)π0(y)],\KL(\pi_\theta \,\Vert\, \pi_0) = \E_{y \sim \pi_\theta}\left[\log \frac{\pi_\theta(y)}{\pi_0(y)}\right],

the expected log-ratio of the two distributions, which is zero exactly when they agree and grows as the policy puts probability where the reference puts little (Section 6.3). So Equation (12.3) is expected reward minus β\beta times a KL divergence. From here on the book writes the policy π\pi, the reference policy it is anchored to π0\pi_0 (the model training starts from and is penalized for leaving), a reward rr, a learned reward model rϕr_\phi, and the penalty β KL⁡(π ∥ π0)\beta\,\KL(\pi \,\Vert\, \pi_0).

In the developer's own human evaluation, by its contracted labelers on prompts submitted to its application programming interface (API), outputs of the 1.3-billion-parameter InstructGPT model were preferred to those of the 175-billion-parameter GPT-3, despite having over 100 times fewer parameters (Ouyang et al., 2022). The result is about following the instructions of that developer's users as its labelers judged them, not about capability in general, but on that measure a small fine-tuned model beat a large untuned one.

The same papers recorded the first warnings. In the 2019 preprint, summarization models trained with 60,000 comparisons could, in the authors' description, "roughly be described as 'smart copiers'": they copied whole sentences from the input while skipping irrelevant preamble. Labelers preferred them even to human-written reference summaries, though not to a baseline that simply copies the first three sentences (Ziegler et al., 2019). The authors give two explanations: copying is an easy way to be accurate when labelers are told to penalize inaccuracy but not copying, and some labelers may check for copying as a fast heuristic for accuracy (Ziegler et al., 2019). On the second reading, it is an early case of a policy finding what its grader rewards rather than what its grader meant, the pattern Chapter 30 follows to its present form (inference). In the 2020 summarization study, light optimization against a reward model improved summaries as people judged them, but as optimization increased, the labelers' preferences fell below what the reward model predicted, and eventually the reward model became anti-correlated with human preferences (Stiennon et al., 2020). Section 15.6 measures this curve.

12.2.2 Why the penalty #

Without the penalty, the optimum of expected reward is a policy that puts all of its probability on whatever response the reward model scores highest. The 2019 preprint shows what that looks like in practice: fine-tuned against a sentiment reward with no KL penalty, the model's samples were, in the authors' words, "gibberish even if we include an entropy bonus", a bonus for keeping the output distribution spread out (Ziegler et al., 2019). The anchor did not begin with language models: an earlier method treated a pretrained sequence model's next-token distribution as a prior policy to stay close to while it improved melodies and molecules (Jaques et al., 2017). The 2020 summarization paper gives two reasons for the term: it acts as an entropy bonus that encourages exploration and deters collapse to a single mode, and it keeps the policy's outputs close to the ones the reward model saw in training (Stiennon et al., 2020). A 2022 analysis states the first in general form: naive maximization of expected reward unavoidably leads to distribution collapse, a degenerate distribution concentrated on the highest-reward sequences (Korbak et al., 2022). The next section asks what the penalized objective produces instead.

Sources cited in Section 12.2 7
  1. Ouyang et al. (2022) Training language models to follow instructions with human feedback
  2. Christiano et al. (2017) Deep reinforcement learning from human preferences
  3. Ziegler et al. (2019) Fine-Tuning Language Models from Human Preferences
  4. Stiennon et al. (2020) Learning to summarize from human feedback
  5. Bai et al. (2022b) Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback
  6. Jaques et al. (2017) Sequence Tutor: Conservative Fine-Tuning of Sequence Generation Models with KL-control
  7. Korbak et al. (2022) RL with KL penalties is better viewed as Bayesian inference

12.3 The KL-regularized objective and its optimum #

Training against Equation (12.3) runs a noisy optimizer for a finite time. Before asking how well it does, ask what it aims at: which policy maximizes the penalized objective exactly? The question separates by prompt, since the objective averages over prompts and the policy may choose its response distribution for each prompt independently. So fix a prompt xx, drop it from the notation, and ask which distribution π\pi over responses maximizes

J(π)=Ey∼π[r(y)]−β KL⁡(π ∥ π0).J(\pi) = \E_{y \sim \pi}\big[r(y)\big] - \beta\,\KL(\pi \,\Vert\, \pi_0).

12.3.1 The idea: reward as a temperature-scaled reweighting #

The answer has a familiar shape. Sampling a language model at temperature TT raises each next-token distribution to the power 1/T1/T and renormalizes it (Section 11.1), a reweighting whose sharpness the temperature sets. The optimum of JJ applies a reweighting of the same shape to whole responses: it reweights the reference policy by the exponential of reward divided by β\beta, so the penalty weight acts as a temperature for the reward.

A two-response example shows the effect before the formula. Let the reference policy give an adequate response probability 0.9 and a better one probability 0.1, with rewards 0 and 1. At β=1\beta = 1 the better response's weight is 0.1×e1≈0.270.1 \times e^{1} \approx 0.27 against 0.90.9 for the other, so after renormalizing the optimum gives it probability about 0.23. At β=0.25\beta = 0.25 its weight is 0.1×e4≈5.50.1 \times e^{4} \approx 5.5, and its probability rises to about 0.86. The optimum never jumps straight to the best response, and it never ignores the reference: it moves probability in proportion to exp⁡(r/β)\exp(r/\beta), starting from where the reference policy put it.

12.3.2 The closed form #

For each prompt xx, the maximizer of JJ over all distributions on responses is

π∗(y ∣ x)=1Z(x) π0(y ∣ x) exp⁡ ⁣(r(x,y)/β),Z(x)=∑yπ0(y ∣ x) exp⁡ ⁣(r(x,y)/β).\pi^\ast(y \given x) = \frac{1}{Z(x)}\,\pi_0(y \given x)\,\exp\!\big(r(x,y)/\beta\big), \qquad Z(x) = \sum_{y} \pi_0(y \given x)\,\exp\!\big(r(x,y)/\beta\big).
(12.4)

A reweighting by the exponential of a function is called an exponential tilt, and the book calls π∗\pi^\ast the tilt of π0\pi_0 for short. Z(x)Z(x) is the normalizing constant: the sum that makes the reweighted probabilities add up to one. It is a sum over every possible response, too many to compute for a language model, so the derivations below use it only as a symbol, and Section 12.6 shows how to avoid it entirely.

Derivation The optimum of the KL-regularized objective

Fix the prompt and drop xx. Assume finitely many responses (or a convergent sum), so that ZZ is finite, and consider only policies π\pi that put probability on a response only where π0\pi_0 does; any other policy has infinite KL divergence from π0\pi_0 (Section 6.3) and so J=−∞J = -\infty.

  1. Write both terms of JJ as one sum over responses, using the definition of KL: J(π)=∑yπ(y) r(y)−β∑yπ(y)log⁡π(y)π0(y)J(\pi) = \sum_y \pi(y)\,r(y) - \beta \sum_y \pi(y) \log \frac{\pi(y)}{\pi_0(y)}.
  2. Factor out −β-\beta and use r(y)=βlog⁡er(y)/βr(y) = \beta \log e^{r(y)/\beta}: J(π)=−β∑yπ(y)log⁡π(y)π0(y) er(y)/βJ(\pi) = -\beta \sum_y \pi(y) \log \frac{\pi(y)}{\pi_0(y)\, e^{r(y)/\beta}}.
  3. By the definition Equation (12.4), the denominator is π0(y) er(y)/β=Z π∗(y)\pi_0(y)\, e^{r(y)/\beta} = Z\,\pi^\ast(y). Split off the constant: J(π)=−β∑yπ(y)log⁡π(y)π∗(y)+βlog⁡Z∑yπ(y)J(\pi) = -\beta \sum_y \pi(y) \log \frac{\pi(y)}{\pi^\ast(y)} + \beta \log Z \sum_y \pi(y).
  4. The first sum is KL⁡(π ∥ π∗)\KL(\pi \,\Vert\, \pi^\ast) and the second is 1, so
J(π)=−β KL⁡(π ∥ π∗)+βlog⁡Z.J(\pi) = -\beta\,\KL(\pi \,\Vert\, \pi^\ast) + \beta \log Z.
(12.5)

The KL divergence is non-negative and zero exactly when its two arguments are equal (Section 6.3). The second term does not depend on π\pi. So JJ is maximized exactly at π=π∗\pi = \pi^\ast, uniquely, and its maximum value is βlog⁡Z\beta \log Z.

The same policy answers a second question, which is often the one a designer actually asks: what is the most reward a policy can earn without moving more than a given distance from the reference? Call the allowed distance a KL budget. The penalty form and the budget form trace the same set of best policies, as the next derivation shows without any machinery beyond the previous one. (In the language of constrained optimization, β\beta is the Lagrange multiplier of the budget constraint.)

Derivation The penalty and the budget give the same frontier

Fix β\beta and let K∗=KL⁡(π∗ ∥ π0)K^\ast = \KL(\pi^\ast \,\Vert\, \pi_0). Take any policy π\pi within the same budget, KL⁡(π ∥ π0)≤K∗\KL(\pi \,\Vert\, \pi_0) \le K^\ast.

  1. π∗\pi^\ast maximizes JJ, so J(π)≤J(π∗)J(\pi) \le J(\pi^\ast), which reads Eπ[r]−β KL⁡(π ∥ π0)≤Eπ∗[r]−βK∗\E_\pi[r] - \beta\,\KL(\pi \,\Vert\, \pi_0) \le \E_{\pi^\ast}[r] - \beta K^\ast.
  2. Rearranging, Eπ[r]≤Eπ∗[r]−β(K∗−KL⁡(π ∥ π0))\E_\pi[r] \le \E_{\pi^\ast}[r] - \beta\big(K^\ast - \KL(\pi \,\Vert\, \pi_0)\big).
  3. The bracket is non-negative by the budget assumption and β>0\beta > 0, so Eπ[r]≤Eπ∗[r]\E_\pi[r] \le \E_{\pi^\ast}[r].

No policy within the budget earns more expected reward than π∗\pi^\ast. As β\beta falls from very large to very small, K∗K^\ast rises continuously from 0 (the next box shows that it rises) toward log⁡(1/π0(Ymax⁡))\log\big(1 / \pi_0(\mathcal{Y}_{\max})\big), the divergence of the policy that keeps only the highest-reward responses Ymax⁡\mathcal{Y}_{\max} in their reference proportions. Every budget below that limit is met by some β\beta, so the two forms trace the same frontier of expected reward against KL; a larger budget buys nothing more.

12.3.3 Reward and divergence from one function #

Every quantity a later chapter needs about the optimum follows from the normalizing constant. Write κ=1/β\kappa = 1/\beta, the inverse KL weight, so that a large κ\kappa means a weak anchor, and treat log⁡Z\log Z as a function of κ\kappa.

Derivation Expected reward and KL from log Z

With Z(κ)=∑yπ0(y) eκr(y)Z(\kappa) = \sum_y \pi_0(y)\, e^{\kappa r(y)} and π∗(y)=π0(y) eκr(y)/Z\pi^\ast(y) = \pi_0(y)\, e^{\kappa r(y)} / Z:

  1. Differentiate the logarithm of a finite sum term by term: ddκlog⁡Z=1Z∑yπ0(y) r(y) eκr(y)=∑yπ∗(y) r(y)=Eπ∗[r]\frac{d}{d\kappa} \log Z = \frac{1}{Z} \sum_y \pi_0(y)\, r(y)\, e^{\kappa r(y)} = \sum_y \pi^\ast(y)\, r(y) = \E_{\pi^\ast}[r].
  2. Differentiate again. By the quotient rule and step 1, ddκπ∗(y)=π∗(y)(r(y)−Eπ∗[r])\frac{d}{d\kappa}\pi^\ast(y) = \pi^\ast(y)\big(r(y) - \E_{\pi^\ast}[r]\big), so ddκEπ∗[r]=∑yr(y)ddκπ∗(y)=Eπ∗[r2]−Eπ∗[r]2=Var⁡π∗(r)≥0\frac{d}{d\kappa} \E_{\pi^\ast}[r] = \sum_y r(y) \frac{d}{d\kappa}\pi^\ast(y) = \E_{\pi^\ast}[r^2] - \E_{\pi^\ast}[r]^2 = \Var_{\pi^\ast}(r) \ge 0. Expected reward never falls as the anchor weakens.
  3. Take the log-ratio inside the KL: log⁡π∗(y)π0(y)=κr(y)−log⁡Z\log \frac{\pi^\ast(y)}{\pi_0(y)} = \kappa r(y) - \log Z, so
KL⁡(π∗ ∥ π0)=κ Eπ∗[r]−log⁡Z.\KL(\pi^\ast \,\Vert\, \pi_0) = \kappa\,\E_{\pi^\ast}[r] - \log Z.
(12.6)
  1. Differentiating with steps 1 and 2: ddκKL⁡(π∗ ∥ π0)=Eπ∗[r]+κVar⁡π∗(r)−Eπ∗[r]=κVar⁡π∗(r)≥0\frac{d}{d\kappa}\KL(\pi^\ast \,\Vert\, \pi_0) = \E_{\pi^\ast}[r] + \kappa \Var_{\pi^\ast}(r) - \E_{\pi^\ast}[r] = \kappa \Var_{\pi^\ast}(r) \ge 0. The divergence never falls as the anchor weakens either.

So one function of one parameter traces the whole frontier: log⁡Z\log Z and its derivative give the expected reward and the KL of the optimum at every β\beta, and both rise together as β\beta falls. Two limits complete the picture. As β→∞\beta \to \infty the reweighting flattens and π∗→π0\pi^\ast \to \pi_0. As β→0\beta \to 0 it sharpens until all probability sits on the highest-reward responses that π0\pi_0 can produce, shared among them in proportion to their reference probabilities.

Later chapters use two further facts about the optimum. First, it never gives probability to a response the reference policy gives none, since π∗\pi^\ast is π0\pi_0 times a positive factor. For a language model this constraint is weak: a softmax gives every finite response some probability (sampling methods that cut off the distribution's tail aside). What matters is the second fact, the reward it takes to make a rare response common.

Derivation The price of rarity

Let a response y1y_1 have reference probability p0=π0(y1)p_0 = \pi_0(y_1), and let its reward exceed the reward of every other response by at least Δ>0\Delta > 0.

  1. Every other response yy has r(y)≤r(y1)−Δr(y) \le r(y_1) - \Delta, so the normalizing constant is at most Z≤p0 er(y1)/β+(1−p0) e(r(y1)−Δ)/βZ \le p_0\, e^{r(y_1)/\beta} + (1 - p_0)\, e^{(r(y_1) - \Delta)/\beta}.
  2. By Equation (12.4), π∗(y1)=p0 er(y1)/β/Z\pi^\ast(y_1) = p_0\, e^{r(y_1)/\beta} / Z. Replacing ZZ by the larger bound can only lower this, and dividing top and bottom by e(r(y1)−Δ)/βe^{(r(y_1) - \Delta)/\beta} gives $\pi^\ast(y_1) \ge p_0, e^{\Delta/\beta} \big/ \big(p_0, e^{\Delta/\beta}
    • 1 - p_0\big)$.
  3. The right side is at least one half when p0 eΔ/β≥1−p0p_0\, e^{\Delta/\beta} \ge 1 - p_0. For a response with p0<1/2p_0 < 1/2, taking logarithms, that is when β≤Δ/log⁡((1−p0)/p0)\beta \le \Delta / \log\big((1 - p_0)/p_0\big). For two responses whose rewards differ by exactly Δ\Delta, the bound in step 1 is an equality and this condition is exact. Since log⁡(1/p0)\log(1/p_0) is larger than log⁡((1−p0)/p0)\log\big((1 - p_0)/p_0\big), the condition holds in particular whenever
β<Δlog⁡(1/p0).\beta < \frac{\Delta}{\log(1/p_0)}.
(12.7)

The same algebra bounds what the optimum can do to any response. The log-ratio is log⁡(π∗(y)/π0(y))=r(y)/β−log⁡Z\log\big(\pi^\ast(y)/\pi_0(y)\big) = r(y)/\beta - \log Z, and since ZZ is the average of er(y)/βe^{r(y)/\beta} under π0\pi_0, log⁡Z\log Z lies between the smallest and the largest reward divided by β\beta. So no response's probability changes by a factor larger than e(rmax⁡−rmin⁡)/βe^{(r_{\max} - r_{\min})/\beta}, where rmax⁡r_{\max} and rmin⁡r_{\min} are the largest and smallest rewards.

A response with reference probability p0p_0 whose reward exceeds every alternative by Δ\Delta dominates the optimum once β<Δ/log⁡(1/p0)\beta < \Delta / \log(1/p_0). Rarity therefore protects only logarithmically. Making a response a thousand times rarer raises the reward gap it needs by βlog⁡1000≈6.9β\beta \log 1000 \approx 6.9\beta; a response with reference probability one in a billion dominates once β\beta falls below Δ/20.7\Delta/20.7. Read the other way, at a given β\beta a reward gap Δ\Delta holds a response off only if its reference probability is below e−Δ/βe^{-\Delta/\beta}. Whether rarity protects thus depends on the ratio of the reward gap to β\beta, which Section 12.4.2 takes up, and Section 30.2.2 applies the same arithmetic to an exploit that a grader overpays.

reference π₀optimum π*0.000.020.040.060.08probability30 responses by reward r, evenly spaced from 0 to 10.20.40.60.81.0expected reward048KL from π₀ (nats)π* as κ variesπ₀κ = 5 (β = 0.2): KL(π* ‖ π₀) = 0.34 nats, expected reward 0.45 (under π₀: 0.31).
reference π₀optimum π*0.000.020.040.060.08probability30 responses by reward r, evenly spaced from 0 to 10.20.40.60.81.0expected reward0246810KL from π₀ (nats)π* as κ variesπ₀κ = 5 (β = 0.2): KL(π* ‖ π₀) = 0.34 nats, expectedreward 0.45 (under π₀: 0.31).
Figure 12.2 The optimum of Equation (12.4) for one prompt with thirty possible responses, whose rewards r are evenly spaced from 0 to 1 in the order drawn. The violet outline is the reference policy π₀ and the blue bars are the optimum π*. Drag the inverse KL weight κ = 1/β to the right, weakening the anchor, and the bars slide toward the high-reward responses that π₀ makes rare. The second panel traces expected reward against KL divergence for every κ, with the current optimum marked in blue and the reference policy's expected reward as the dotted violet line. The frontier bends over because each further nat of divergence buys less reward: its slope is β. The reference policy and the rewards are a stated illustrative model; everything else is computed exactly.

Figure 12.2 computes the optimum for a reference policy over thirty responses whose best response has reference probability about 1.7×10−51.7 \times 10^{-5}. Divergences are in nats, the unit of information when logarithms are natural (Section 6.2). At β=1\beta = 1 (κ=1\kappa = 1) the optimum is barely distinguishable from the reference: it spends 0.01 nats of KL and raises the expected reward from 0.31 to 0.34. At β=0.1\beta = 0.1 (κ=10\kappa = 10) it spends 1.39 nats and reaches 0.59, and at β=0.05\beta = 0.05 (κ=20\kappa = 20) it spends 4.76 nats and reaches 0.82. The frontier in the second panel bends over, and the derivation above says by how much: dividing step 2 by step 4, its slope is 1/κ=β1/\kappa = \beta, so at the optimum for a given β\beta, one more nat of divergence buys about β\beta more expected reward.

The closed form describes exact optimization of a fixed reward over all distributions. Training is none of these: the network represents only some distributions, the gradient is estimated from samples, and the run stops. The 2019 preprint that brought RLHF to language models measured the gap once, by estimating the reward of the KL-constrained optimum through sampling and reweighting. On a mock sentiment task with a 124-million-parameter model, it found a significant gap between its PPO policies and the optimum after two million episodes, largely closed by further training (Ziegler et al., 2019). As of October 2026, we found no comparable measurement of reward for frontier post-training. Section 12.7.4 reports a measurement of a different kind, which shows reasoning training falling short of the optimum on its own training problems.

Sources cited in Section 12.3 1
  1. Ziegler et al. (2019) Fine-Tuning Language Models from Human Preferences

12.4 Post-training as Bayesian updating #

The closed form invites a reading. Equation (12.4) multiplies one distribution by a non-negative factor and renormalizes, which is exactly the shape of Bayes' rule (Section 6.1): a posterior is proportional to a prior times a likelihood. This section asks what that reading says about what post-training does to a pretrained model, and where the reading stops.

12.4.1 Prior, likelihood, and posterior #

Read π0\pi_0 as a prior over responses: what the pretrained or fine-tuned model already found likely. Read exp⁡(r(y)/β)\exp(r(y)/\beta) as a likelihood: how strongly a response is supported by a piece of evidence, here the fact that the reward favors it, with β\beta setting how much that evidence counts. Then π∗\pi^\ast is the posterior, the prior updated on the evidence. Korbak et al. (2022) make this reading precise. They show that KL-regularized reinforcement learning is equivalent to variational inference, the method of choosing, from a family of distributions one can work with, the one closest to a posterior one cannot compute directly. The family here is whatever the network can represent, and the closeness is measured in KL. Equation (12.5) already says so: maximizing JJ is minimizing KL⁡(π ∥ π∗)\KL(\pi \,\Vert\, \pi^\ast), the direction of KL that Section 6.3 showed concentrates on regions where the target is high when the family cannot match it everywhere.

The authors use the reading to explain the penalty: it turns reward maximization, which collapses the model (Section 12.2.2), into matching a target distribution, which they argue explains why KL-regularized fine-tuning keeps the fluency and diversity of the original model. They suggest that reinforcement learning may not be an adequate formal framework for fine-tuning language models (Korbak et al., 2022). This is an argument about the objective, not an experiment.

12.4.2 What the reading predicts #

Three consequences follow, each a property of the optimum, not of any particular training run.

The first is that the prior survives. Take any two responses yy and y′y'. From Equation (12.4),

π∗(y)π∗(y′)=π0(y)π0(y′)  e(r(y)−r(y′))/β.\frac{\pi^\ast(y)}{\pi^\ast(y')} = \frac{\pi_0(y)}{\pi_0(y')}\; e^{(r(y) - r(y'))/\beta}.

The reward decides between levels of reward; the prior decides within them. Responses the reward scores equally keep exactly the odds the reference policy gave them, at every β\beta.

Example 12.1 Two equally rewarded styles

A reference policy answers a question in a formal style with probability 0.2, in a casual style with probability 0.1, and unhelpfully with probability 0.7. The reward gives both helpful answers 1 and the unhelpful one 0. At β=0.5\beta = 0.5 the weights are 0.2e2≈1.480.2 e^{2} \approx 1.48, 0.1e2≈0.740.1 e^{2} \approx 0.74, and 0.70.7, so the optimum is about (0.51,0.25,0.24)(0.51, 0.25, 0.24). At β=0.1\beta = 0.1 the helpful answers take nearly all the probability, about (0.667,0.333,0.0001)(0.667, 0.333, 0.0001). At every β\beta the formal answer is exactly twice as likely as the casual one, as it was before training. Nothing in the reward expressed a preference between the styles, so the optimum inherits the reference policy's.

This is consistent with the persona view of Section 11.6, in which a pretrained model is a mixture over the many writers and characters its training text contains, and post-training reweights that mixture rather than writing behavior from nothing. The optimum does not test the view: the odds equation holds for any reference policy, and the view's distinctive claim, that the reference's probability is organized by characters, is one the mathematics neither needs nor checks (inference). Chapter 26 and Chapter 32 test the view against what fine-tuning does in practice.

The second consequence is that how firmly the prior holds depends on the anchor's weight (Section 12.3.3). When β\beta is large against the reward's range, no behavior's probability changes by more than a factor of e(rmax⁡−rmin⁡)/βe^{(r_{\max} - r_{\min})/\beta}: the optimum sharpens what the reference already does and cannot make a rare behavior common. When β\beta is small, Equation (12.7) says rarity offers little protection. DeepSeek's developers report training DeepSeek-R1-Zero with a KL coefficient of 0.001 over 10,400 steps, replacing the reference model with the latest policy every 400 steps (DeepSeek-AI et al., 2025). Read as the β\beta of the closed form, a reward gap of 1 then makes dominant any behavior whose reference probability exceeds e−1000e^{-1000} (inference). The reading is loose, since the coefficient weights an estimate of the divergence added directly to the loss, not a per-token penalty in the reward as in PPO, against standardized advantages, but it places such training far from the regime where the prior holds. Resetting the reference loosens the anchor further: if each phase reached its optimum, tilting π0\pi_0 by er/βe^{r/\beta} and then tilting the result again would be a single tilt by e2r/βe^{2r/\beta}. In that regime the closed form does not predict that training only sharpens.

One prediction holds at every β\beta, and Section 12.7.4 derives and tests it: at the optimum, the probability of solving a training problem in kk attempts never falls below the reference policy's, for any kk.

The third consequence is a limit. The posterior says which outputs the optimal policy produces, not which computation a network uses to produce them, and networks that agree on the training prompts can generalize differently elsewhere (Chapter 9). Whether training makes reward something the policy pursues, rather than a signal that strengthens whatever computation earned it, is a separate question, which Section 33.1 takes up.

Sources cited in Section 12.4 5
  1. Korbak et al. (2022) RL with KL penalties is better viewed as Bayesian inference
  2. Todorov (2009) Efficient computation of optimal actions
  3. Kappen et al. (2012) Optimal control as a graphical model inference problem
  4. Levine (2018) Reinforcement Learning and Control as Probabilistic Inference: Tutorial and Review
  5. DeepSeek-AI et al. (2025) DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning

12.5 Best-of-n: reweighting by sampling #

Training a policy is expensive, and a deployed system can be steered without it. Draw nn responses from the reference policy, score each with the reward, and return the best. This is best-of-n sampling, also called rejection sampling or reranking. It needs no gradient and no change to the model, only nn samples and nn scores per query. The question for this section is what distribution it samples from, and how far that distribution is from the reference.

12.5.1 Which distribution best-of-n samples #

Assume, as Beirami et al. (2025) do, finitely many responses with distinct rewards, and sort them by reward. Let F(y)F(y) be the reference probability of a reward at most r(y)r(y) and F−(y)F^-(y) the probability of a reward strictly below it. The best of nn independent draws is yy exactly when all nn draws have reward at most r(y)r(y) and not all of them have reward below it, so

πn(y)=F(y)n−F−(y)n,\pi_n(y) = F(y)^n - F^-(y)^n,

which is their form of the best-of-n distribution (Beirami et al., 2025). Write u=F(y)u = F(y) and δ=F(y)−F−(y)=π0(y)\delta = F(y) - F^-(y) = \pi_0(y). For small δ\delta, the difference of powers un−(u−δ)nu^n - (u - \delta)^n is close to its first-order term nun−1δn u^{n-1} \delta, so πn(y)≈n F(y)n−1 π0(y)\pi_n(y) \approx n\,F(y)^{n-1}\,\pi_0(y). The next term is smaller by a factor of about nδ/(2u)n\delta/(2u), so the approximation needs n π0(y)n\,\pi_0(y) to be small compared with F(y)F(y), not only π0(y)\pi_0(y) small. Within that range best-of-n, too, reweights the reference policy, by a factor nFn−1n F^{n-1} that grows with the response's rank among rewards. The exponential tilt of Equation (12.4) depends on the reward's size; best-of-n depends only on its rank, which makes it indifferent to how the reward is scaled.

12.5.2 The divergence of best-of-n #

For rewards that vary continuously, with no response carrying any probability on its own, the first-order form is exact, and the KL divergence has a closed form that became folklore.

Derivation The best-of-n KL for continuous rewards

Let the reward r(Y)r(Y) of a response YY drawn from π0\pi_0 be continuous, with distribution function FF, and let πn\pi_n reweight π0\pi_0 by the factor n F(r(Y))n−1n\,F(r(Y))^{n-1}.

  1. The KL divergence is the expected logarithm of the reweighting factor under πn\pi_n: KL⁡(πn ∥ π0)=Eπn[log⁡n+(n−1)log⁡F(r(Y))]\KL(\pi_n \,\Vert\, \pi_0) = \E_{\pi_n}\big[\log n + (n-1) \log F(r(Y))\big].
  2. F(r(Y))F(r(Y)) is the fraction of reference responses that score at or below YY. By the definition of FF, a fresh reference response falls among the lowest-scoring fraction uu of responses with probability exactly uu, so under π0\pi_0 the number F(r(Y))F(r(Y)) is uniform on [0,1][0, 1]. Under πn\pi_n, YY is the best of nn independent draws, so F(r(Y))F(r(Y)) is the largest of nn independent uniform numbers. Call it MM. It is below mm only when all nn numbers are, which has probability mnm^n, so its density is nmn−1n m^{n-1}.
  3. Integration by parts gives ∫01mn−1log⁡m dm=[mnnlog⁡m]01−∫01mn−1n dm=0−1n2\int_0^1 m^{n-1} \log m \, dm = \big[\tfrac{m^n}{n} \log m\big]_0^1 - \int_0^1 \tfrac{m^{n-1}}{n} \, dm = 0 - \tfrac{1}{n^2}, so E[log⁡M]=n⋅(−1n2)=−1n\E[\log M] = n \cdot (-\tfrac{1}{n^2}) = -\tfrac{1}{n}.
  4. Substituting, KL⁡(πn ∥ π0)=log⁡n−n−1n\KL(\pi_n \,\Vert\, \pi_0) = \log n - \frac{n-1}{n}.

A language model's responses are finitely many, however, and each carries some probability of its own. Beirami et al. (2025) show that for this case the folklore formula is not the KL divergence in general; it is an upper bound:

KL⁡(πn ∥ π0)  ≤  log⁡n−n−1n.\KL(\pi_n \,\Vert\, \pi_0) \;\le\; \log n - \frac{n-1}{n}.
(12.8)

The gap comes from the chance that the nn draws repeat a response. The formula is accurate when n2max⁡yπ0(y)n^2 \max_y \pi_0(y) is much smaller than one, so that even the likeliest response is rarely drawn twice. The gap can grow without bound when nn times the reference probability of the best response is large; for two equally likely responses, the true divergence never exceeds log⁡2\log 2 while the formula grows without limit (Beirami et al., 2025).

12.5.3 How close to the tilt #

The budget derivation of Section 12.3 gives one comparison at once: at any KL, the tilt of Equation (12.4) earns at least as much expected reward as best-of-n, because it earns the most of any policy within that budget. The question is how much is lost. Gui and colleagues answer it for win rate, the probability that a policy's response is preferred to a fresh sample from the reference. They place best-of-n and trained alignment policies in a common class, every reweighting of the reference by a non-decreasing function of the reward, and show that within this class best-of-n is essentially optimal for the trade-off between win rate and KL (Gui et al., 2024). They also train a model to imitate the best-of-n distribution, so that one sample costs what nn did (Gui et al., 2024). In the 2020 summarization study, the authors report, without showing the data, that best-of-n and PPO policies with the same average reward were of similar quality to human labelers, though the PPO policies were farther from the supervised model in KL (Stiennon et al., 2020).

reference π₀optimum π*best-of-n πn0.000.050.100.150.20probability30 responses by reward r, evenly spaced from 0 to 10.20.40.60.81.0expected reward048KL from π₀ (nats)π* as κ variesπ₀κ = 20 (β = 0.05): the optimum has KL 4.76 nats and expected reward 0.82.Best-of-324: KL 4.76 nats (the formula log n − (n−1)/n gives 4.78), expected reward 0.79.
reference π₀optimum π*best-of-n πn0.000.050.100.150.20probability30 responses by reward r, evenly spaced from 0 to 10.20.40.60.81.0expected reward0246810KL from π₀ (nats)π* as κ variesπ₀κ = 20 (β = 0.05): the optimum has KL 4.76 nats andexpected reward 0.82.Best-of-324: KL 4.76 nats (the formula log n − (n−1)/ngives 4.78), expected reward 0.79.
Figure 12.3 Best-of-n beside the optimum, for the model of Figure 12.2. Green dots are best-of-n πₙ, computed exactly on the thirty responses at the integer n whose KL is closest to the optimum's at the current κ; blue bars are the optimum π*, the violet outline the reference π₀. Best-of-n is more peaked and stops short of the top responses: it can return only what its n draws contain, so it concentrates on the responses a batch of n usually holds at its top, while the optimum's weight keeps growing to the top of the scale. In the second panel, green dots are best-of-n at n = 1, 2, 4, and so on to 2¹⁷, just below the optimum's frontier, which no policy can exceed. The readout compares best-of-n's exact KL with the formula log n − (n−1)/n.

Figure 12.3 shows the two side by side. At β=0.05\beta = 0.05 the optimum spends 4.76 nats and earns an expected reward of 0.82; best-of-324 spends the same divergence and earns 0.79, and the formula overstates its divergence slightly, at 4.78 nats. The shapes differ more than the numbers. Best-of-324 puts 22 percent of its probability on a single response below the top, and the best response appears in fewer than 1 percent of batches of 324 draws, while the optimum gives that response 8 percent. In this model the formula is close because the best responses are rare; the coin of Exercise 12.2 is the opposite case.

12.5.4 One axis of pressure, and its limits #

With its divergence in hand, best-of-n and reinforcement learning can be drawn on one axis, the KL from the reference policy, which is how the overoptimization measurements of Section 15.6, by OpenAI researchers on their own GPT-3-series models, are plotted (Gao et al., 2022). Those measurements use d=KL⁡d = \sqrt{\KL}, because KL is a quadratic measure of distance (Gao et al., 2022). A developer report had observed reward rising roughly linearly in KL⁡\sqrt{\KL} during RLHF, and explained that the KL of a slightly changed policy grows with the square of the change while reward grows linearly with it (Bai et al., 2022b). The closed form gives the same law: near the reference, the tilt's reward gain is about 2Var⁡π0(r) KL⁡\sqrt{2\Var_{\pi_0}(r)\,\KL}, with Var⁡π0(r)\Var_{\pi_0}(r) the variance of the reward under π0\pi_0 (Exercise 12.3).

The axis has limits. Those best-of-n curves used the folklore formula (Gao et al., 2022), which Beirami et al. (2025) show is an upper bound, so they are drawn at or to the right of their true positions. And the same study found that reinforcement learning consumes far more KL than best-of-n, and concluded that KL "should not be used to compare the amount of optimization between different optimization algorithms" (Gao et al., 2022). The axis orders the policies one method produces; it does not equate pressure across methods.

Sources cited in Section 12.5 5
  1. Beirami et al. (2025) Theoretical guarantees on the best-of-n alignment policy
  2. Gui et al. (2024) BoNBoN Alignment for Large Language Models and the Sweetness of Best-of-n Sampling
  3. Stiennon et al. (2020) Learning to summarize from human feedback
  4. Gao et al. (2022) Scaling Laws for Reward Model Overoptimization
  5. Bai et al. (2022b) Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback

12.6 Direct preference optimization #

The RLHF pipeline of Section 12.2 trains two networks and runs a sampling loop: a reward model fitted to comparisons, then a policy that generates responses throughout training so that PPO can score and update them. Both steps are expensive, and the second is delicate to tune. Direct preference optimization (DPO) removes the reward model and the sampling loop by running Equation (12.4) backward (Rafailov et al., 2023).

12.6.1 The idea: every policy implies a reward #

The closed form maps a reward to a policy. Solve it for the reward instead. Taking logarithms of Equation (12.4) and rearranging,

r(x,y)=βlog⁡π∗(y ∣ x)π0(y ∣ x)+βlog⁡Z(x).r(x, y) = \beta \log \frac{\pi^\ast(y \given x)}{\pi_0(y \given x)} + \beta \log Z(x).

Read from right to left, this says that any policy, compared with the reference, implies a reward for which it is the optimum: responses it makes more likely than the reference did are the ones that reward favors. The intractable Z(x)Z(x) is still there, but it depends only on the prompt. Preference data compare two responses to the same prompt, and the Bradley-Terry model of Section 12.2.1 (taught in Section 13.2) turns a comparison into a probability through the difference of the two rewards: the probability that ywy_w is preferred to yly_l is σ(r(x,yw)−r(x,yl))\sigma\big(r(x, y_w) - r(x, y_l)\big), with σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}) the logistic function. In a difference, the prompt's constant cancels.

Derivation From the closed form to the DPO loss
  1. Substitute the implied reward of a policy πθ\pi_\theta into the Bradley-Terry probability. The two βlog⁡Z(x)\beta \log Z(x) terms are equal, since both responses answer the prompt xx, and cancel: P(yw≻yl ∣ x)=σ(βlog⁡πθ(yw ∣ x)π0(yw ∣ x)−βlog⁡πθ(yl ∣ x)π0(yl ∣ x))\Prob(y_w \succ y_l \given x) = \sigma\Big(\beta \log \frac{\pi_\theta(y_w \given x)}{\pi_0(y_w \given x)} - \beta \log \frac{\pi_\theta(y_l \given x)}{\pi_0(y_l \given x)}\Big).
  2. Every quantity left can be computed: two log-probabilities under the policy being trained and two under the frozen reference.
  3. Fit πθ\pi_\theta by maximum likelihood on a dataset of comparisons (x,yw,yl)(x, y_w, y_l), which means minimizing the negative log-likelihood:
LDPO(θ)=−E(x, yw, yl)[log⁡σ(βlog⁡πθ(yw ∣ x)π0(yw ∣ x)−βlog⁡πθ(yl ∣ x)π0(yl ∣ x))].\mathcal{L}_{\mathrm{DPO}}(\theta) = -\E_{(x,\,y_w,\,y_l)}\Big[\log \sigma\Big(\beta \log \frac{\pi_\theta(y_w \given x)}{\pi_0(y_w \given x)} - \beta \log \frac{\pi_\theta(y_l \given x)}{\pi_0(y_l \given x)}\Big)\Big].
(12.9)
  1. For the gradient, write r^θ(y)=βlog⁡πθ(y ∣ x)π0(y ∣ x)\hat r_\theta(y) = \beta \log \frac{\pi_\theta(y \given x)}{\pi_0(y \given x)} for the implicit reward and h=r^θ(yw)−r^θ(yl)h = \hat r_\theta(y_w) - \hat r_\theta(y_l). The logistic function has two properties that settle the derivative: σ′(h)=σ(h)(1−σ(h))\sigma'(h) = \sigma(h)\big(1 - \sigma(h)\big), and 1−σ(h)=σ(−h)1 - \sigma(h) = \sigma(-h). So the derivative of −log⁡σ(h)-\log \sigma(h) with respect to hh is −σ′(h)/σ(h)=−(1−σ(h))=−σ(−h)-\sigma'(h)/\sigma(h) = -(1 - \sigma(h)) = -\sigma(-h). And ∇θh=β(∇θlog⁡πθ(yw ∣ x)−∇θlog⁡πθ(yl ∣ x))\nabla_\theta h = \beta\big(\nabla_\theta \log \pi_\theta(y_w \given x) - \nabla_\theta \log \pi_\theta(y_l \given x)\big), because π0\pi_0 does not depend on θ\theta. A gradient step on one pair therefore moves θ\theta along
β σ(r^θ(yl)−r^θ(yw)) (∇θlog⁡πθ(yw ∣ x)−∇θlog⁡πθ(yl ∣ x)).\beta\,\sigma\big(\hat r_\theta(y_l) - \hat r_\theta(y_w)\big)\,\big(\nabla_\theta \log \pi_\theta(y_w \given x) - \nabla_\theta \log \pi_\theta(y_l \given x)\big).

It raises the probability of the preferred response, lowers that of the other, and weights the pair by σ(r^θ(yl)−r^θ(yw))\sigma(\hat r_\theta(y_l) - \hat r_\theta(y_w)), which is near one when the implicit reward currently orders the pair the wrong way and near zero when it already orders it correctly with a wide margin.

This is the gradient the paper gives, and its authors report that without the weighting the model can degenerate. The paper's title, "Your Language Model is Secretly a Reward Model", states the idea: the policy's own log-probability ratio is the reward model, fitted to the comparisons directly. In its experiments, DPO exceeded PPO-based RLHF at controlling sentiment and matched or improved response quality in summarization and single-turn dialogue, without sampling from the model during fine-tuning; the summarization and dialogue comparisons were judged by GPT-4 (Rafailov et al., 2023). DPO was derived in the bandit view of Section 12.2. A later preprint derives it in the token-level view as a form of inverse Q-learning, a method that recovers a value function from behavior, and argues that DPO therefore performs some credit assignment across the tokens of a response (Rafailov et al., 2024a).

Table 12.2 Three routes to the reweighting of the reference policy
RLHF with PPO Best-of-n DPO
Reward model trained separately on comparisons needed at inference, or a program that checks answers none; the implicit reward βlog⁡(πθ/π0)\beta \log(\pi_\theta / \pi_0)
Sampling during training yes, from the current policy no training no; a fixed dataset of comparisons
Cost per query at inference one sample nn samples and nn scores one sample
What it aims at π∗\pi^\ast for the reward model, approximately πn\pi_n, nearly optimal for win rate against KL, not the tilt for rr π∗\pi^\ast for the reward that best fits the comparisons under Bradley-Terry

12.6.2 What goes wrong #

Removing the reward model does not remove what the reward model stood for. The implicit reward is still a learned proxy, fitted to finite data under an assumed model of how people choose, and each assumption has been shown to matter. One analysis treats RLHF and DPO as special cases of one preference objective. It finds that when one response is always preferred to another, the Bradley-Terry fit needs an infinite reward gap, so the optimum gives the losing response zero probability whatever β\beta is: in the authors' words, "the strength of the KL-regularisation becomes weaker and weaker the more deterministic the preferences" (Azar et al., 2024). With finite data this becomes overfitting, and their bounded alternative avoids it; Section 22.4 works through the derivation. And direct alignment methods overoptimize too: their quality deteriorates across a wide range of KL budgets, often before a single epoch of the dataset is complete (Rafailov et al., 2024b).

The model of the human inside the loss is itself a choice. A method presented at ICML 2024 replaces Bradley-Terry with a value function from prospect theory, a model of how people weigh gains against losses, and learns from single responses labeled desirable or undesirable (Ethayarajh et al., 2024). Section 22.4 and Chapter 13 examine such choices. These methods are now parts of larger recipes. An open post-training recipe, reported by its developer in a preprint and released with its data and code, combines supervised fine-tuning, DPO, and the reinforcement learning with verifiable rewards of the next section (Lambert et al., 2024).

Sources cited in Section 12.6 6
  1. Rafailov et al. (2023) Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  2. Rafailov et al. (2024a) From $r$ to $Q^*$: Your Language Model is Secretly a Q-Function
  3. Azar et al. (2024) A General Theoretical Paradigm to Understand Learning from Human Preferences
  4. Rafailov et al. (2024b) Scaling Laws for Reward Model Overoptimization in Direct Alignment Algorithms
  5. Ethayarajh et al. (2024) KTO: Model Alignment as Prospect Theoretic Optimization
  6. Lambert et al. (2024) Tulu 3: Pushing Frontiers in Open Language Model Post-Training

12.7 Verifiable rewards and reasoning models #

For some tasks no learned reward is needed. A mathematics problem with a known numerical answer, or a programming task with unit tests, can be graded by a program: compare the final answer, or run the tests. The developer report that named the approach calls it reinforcement learning with verifiable rewards (RLVR): the policy receives a reward only when its response is verifiably correct (Lambert et al., 2024). "Verifiable" here means checked by a program, not proved correct; whether the check is right is the question of Section 24.2. Loops of this kind trained DeepSeek-R1 (DeepSeek-AI et al., 2025) and, by its developers' account in a preprint, Kimi k1.5 (Kimi Team et al., 2025), reasoning models that write a long chain of reasoning before answering. This section teaches the loop end to end, because most of the evidence in Chapter 24 and Chapter 30 comes from it.

12.7.1 The loop #

The loop combines pieces already taught. Its distinctive move is the baseline: instead of training a value network, it compares each response with other responses to the same prompt.

Algorithm 12.1 One iteration of group-relative reinforcement learning with a verifier
  1. Draw a batch of prompts, each with a checkable answer or a set of tests.
  2. For each prompt, sample a group of kk responses from the current policy.
  3. Grade each response with a program: reward 1 if the answer is correct or the tests pass, 0 otherwise, sometimes with a small reward for the required format.
  4. Within each group, subtract the mean reward from each response's reward and divide by the group's standard deviation. The result is the response's advantage, given to every token of the response.
  5. Update the policy by a few minibatch steps on the clipped objective of Equation (12.2) with these advantages, minus β\beta times an estimate of the KL divergence from a reference policy.
  6. Repeat from step 1 with the updated policy, so that samples always come from the policy being trained.

Group Relative Policy Optimization (GRPO), the version of this loop that DeepSeek's reasoning models use, was introduced in a 2024 preprint by DeepSeek's developers as a variant of PPO that enhances mathematical reasoning while reducing PPO's memory use. It drops PPO's value model, a second network about the size of the policy, uses the average reward of the responses sampled for the same question as the baseline, and adds the KL divergence from the reference policy to the loss rather than to the reward (Shao et al., 2024a). In that paper the rewards still came from a learned reward model; rule-based rewards came with the reasoning models below.

The group mean is a baseline in the sense of Section 12.1.3 with one wrinkle: it includes the response's own reward. Write the mean as 1kri+1k∑j≠irj\frac{1}{k} r_i + \frac{1}{k}\sum_{j \ne i} r_j. The second part does not depend on response ii, since the samples are independent, and drops out in expectation like any baseline; the first part scales response ii's own term by 1−1/k1 - 1/k. The centered estimate is therefore unbiased for (k−1)/k(k-1)/k times the gradient: the right direction, slightly shortened. Dividing by the group's standard deviation is a further choice, which rescales each prompt's update by how much its group disagrees, so prompts count unequally. The sources describing GRPO do not say whether the standard deviation divides by kk or k−1k - 1; this book divides by kk.

Example 12.2 Advantages in a group of four

A prompt's four sampled responses are graded (1,0,0,1)(1, 0, 0, 1). The mean is 0.5, so the centered rewards are (+0.5,−0.5,−0.5,+0.5)(+0.5, -0.5, -0.5, +0.5); the standard deviation is 0.5, so the advantages are (+1,−1,−1,+1)(+1, -1, -1, +1). The two correct responses are made more probable and the two wrong ones less, by equal amounts. With grades (1,0,0,0)(1, 0, 0, 0), the mean is 0.25 and the standard deviation 0.25×0.75≈0.433\sqrt{0.25 \times 0.75} \approx 0.433, so the lone correct response gets advantage 0.75/0.433≈1.730.75 / 0.433 \approx 1.73 and each wrong one −0.25/0.433≈−0.58-0.25 / 0.433 \approx -0.58: a rare success is pushed hard. With grades (1,1,1,1)(1, 1, 1, 1), every centered reward is zero and so is every advantage, and the same holds for (0,0,0,0)(0, 0, 0, 0). The group teaches the policy nothing.

The last case is the important one. If a prompt is solved with probability pp by each sample, a group of kk independent samples is all right or all wrong with probability pk+(1−p)kp^k + (1 - p)^k, and such a group contributes nothing but the KL term. The training signal comes from problems the model solves sometimes.

group size k = 8other group sizescorrect responsesincorrect responsesresponses in groups with no signal0.00.20.40.60.81.0chance a group has signal0.00.20.40.60.81.0solve rate p of the promptk = 2k = 640%10%20%30%40%share of responses−202advantageWith p = 0.10 and k = 8, a group carries signal with probability 0.57; 43% of groups are all right orall wrong.With 1 of 8 correct, each correct response gets advantage 2.65 and each incorrect one −0.38.
group size k = 8other group sizescorrect responsesincorrect responsesresponses in groups with no signal0.00.20.40.60.81.0chance a group has signal0.00.20.40.60.81.0solve rate p of the promptk = 2k = 640%10%20%30%40%share of responses−202advantageWith p = 0.10 and k = 8, a group carries signal withprobability 0.57; 43% of groups are all right or allwrong.With 1 of 8 correct, each correct response getsadvantage 2.65 and each incorrect one −0.38.
Figure 12.4 When a group of graded responses carries signal. First panel: the probability that a group of k responses is neither all right nor all wrong, 1 − pᵏ − (1 − p)ᵏ, against the prompt's solve rate p, for the chosen k (solid) and for k = 2 and k = 64 (dashed, labeled on the curves). Every curve falls to zero at both ends, where groups are all wrong or all right; larger groups keep the signal over a wider range of p. Second panel: where the advantages of a group's responses fall, as the expected share of responses at each value; green stems are correct responses, red stems incorrect ones, and the gray stem at zero collects the responses in groups with no signal. Computed exactly from the binomial distribution; nothing is simulated.

Figure 12.4 makes the trade-off visible. At a solve rate of 0.1 and groups of eight, a group carries signal with probability 0.57; in the most likely mixed group, one correct response among eight, the correct response gets advantage 7≈2.65\sqrt{7} \approx 2.65 and each wrong one −0.38-0.38. Larger groups rescue hard prompts, at the price of more samples per prompt.

12.7.2 The systems #

The report on DeepSeek-R1, published in Nature and its developer's account of its own models, trained a first model, DeepSeek-R1-Zero, by reinforcement learning with GRPO alone, without supervised fine-tuning first. The developers report that reasoning abilities were incentivized without human-labeled reasoning trajectories, with behaviors such as self-reflection and verification emerging during training, and that R1-Zero's average pass@1 on the AIME 2024 mathematics competition, the fraction of problems a single sample solves, rose from 15.6 percent to 77.9 percent. Its rewards were rule-based checks of accuracy and format; the developers avoided neural reward models for reasoning tasks because they had observed them to be susceptible to reward hacking in large-scale reinforcement learning (DeepSeek-AI et al., 2025). The developers of Kimi k1.5 report, in a preprint, a framework without tree search, value functions, or rewards on each reasoning step (Kimi Team et al., 2025). The open recipe that named RLVR runs PPO on the objective of Equation (12.3) with the reward model replaced by a verification function (Lambert et al., 2024).

12.7.3 Rewarding the answer or the steps #

A verifier that checks only the final answer rewards outcomes; one that checks each step of the reasoning provides process supervision. The difference matters because a correct answer can follow from wrong reasoning. On grade-school word problems, a 2022 preprint by DeepMind researchers found that outcome-based supervision reached similar final-answer error with less labeling, but that correct reasoning steps required process-based supervision or a reward model that emulates it (Uesato et al., 2022). With reinforcement learning directly against final-answer correctness, at best 12.4 percent of correct answers rested on at least one wrong step, against 3.8 percent for the best process-based method (Uesato et al., 2022). On competition mathematics, in a 2023 study by OpenAI with reward models fine-tuned from its own GPT-4, the process-supervised reward model, choosing the best of 1,860 sampled solutions per problem, solved 78.2 percent of a representative subset of 500 MATH test problems, against 72.4 percent for the outcome-supervised one (Lightman et al., 2023). The authors caution that the two reward models' training sets are not directly comparable; in a smaller-scale comparison in which only the form of supervision differed, process supervision again came out ahead (Lightman et al., 2023). The authors released 800,000 step-level human labels (Lightman et al., 2023). Both comparisons are between reward models used for selection, not between training runs. The same axis returns for the monitorability of reasoning (Section 40.6) and for designs that limit what a training signal rewards (Chapter 28).

12.7.4 What the loop does to a policy #

The measurement that asks what this loop adds is pass@k: the probability that at least one of kk samples solves a problem, averaged over problems. Pass@1 is the ordinary success rate; pass@k at large kk measures coverage, which problems a model solves within a budget of many tries. If training only sharpens the policy toward solutions it already reaches, coverage with unlimited tries cannot grow, since a problem solved with any probability is solved eventually. At a finite kk it can: sharpening raises a rare solution's probability, and with it pass@k, so a rise at large kk does not by itself show that training added an ability. The closed form makes a sharper prediction for the problems the policy is trained on, at every β\beta.

Derivation At the optimum, pass@k cannot fall on a training prompt

Fix a training prompt, let the reward be 1 for a correct response and 0 otherwise, and let pp be the reference policy's solve rate, the total probability it gives to correct responses.

  1. By Equation (12.4), the optimum multiplies the probability of each correct response by e1/β/Ze^{1/\beta}/Z and of each incorrect one by 1/Z1/Z, with Z=p e1/β+1−pZ = p\,e^{1/\beta} + 1 - p. Its solve rate is therefore p∗=p e1/β/(p e1/β+1−p)p^\ast = p\,e^{1/\beta} \big/ \big(p\,e^{1/\beta} + 1 - p\big).
  2. Since e1/β>1e^{1/\beta} > 1, the denominator is less than e1/βe^{1/\beta}, so every correct response gains probability and p∗≥pp^\ast \ge p, with equality only when pp is 0 or 1.
  3. The kk samples are independent, so pass@k =1−(1−p∗)k= 1 - (1 - p^\ast)^k, which rises with p∗p^\ast. Hence the optimum's pass@k is at least the reference policy's at every kk.
  4. As β→0\beta \to 0, p∗→1p^\ast \to 1 for every p>0p > 0. The same holds with no penalty at all: every policy that maximizes expected reward solves every training problem the reference solves with any probability.

A run that resets its reference does not escape the result if each phase reaches its optimum, since a tilt of a tilt is again a tilt (Section 12.4.2). The measurements below should be read against it.

DeepSeek's developers had already observed, in their own model, that reinforcement learning improved the majority-vote accuracy of kk samples but not pass@k, which they read as "boosting the correct response from TopK rather than the enhancement of fundamental capabilities" (Shao et al., 2024a). A 2025 preprint by Yue and colleagues made the test systematic. Models trained with verifiable rewards outperformed their base models, the models training started from, at small kk, but base models consistently surpassed them as kk grew, across benchmarks and model families. Analyses of which problems each model solved, and of how likely the base model found the trained model's reasoning, indicated that the trained model's reasoning paths already existed in the base model's distribution (Yue et al., 2025).

The sharpest measurement is on the training problems themselves. The authors trained Qwen2.5-7B with GRPO on 2,000 mathematics problems, with the KL term removed. On those problems, pass@1 rose from 9.9 percent for the base model to 42.5 percent after 450 steps, while pass@256 fell from 67.2 to 64.3 percent (Yue et al., 2025). By the derivation above, no optimum does that on its own training prompts, with a penalty or without one. The crossover is therefore evidence about how far trained policies sit from the optimum they aim at, not about the optimum's prior (inference).

What does predict narrowing is the loop itself. A correct response gets a direct push only in the rounds in which it is sampled, and a problem the policy rarely solves yields groups that are all wrong, which carry no signal (Section 12.7.1). Meanwhile the network's parameters are shared across problems, so the updates that sharpen the policy where it often succeeds also move its distribution where it rarely does, which the optimum, computed prompt by prompt, leaves out. A run of a few hundred steps can therefore sharpen what it samples often and lose what it samples rarely, where the optimum would have kept both, so that the prior matters through what training samples rather than through the anchor (inference). Section 24.4 reports the measurements of this collapse, and two papers that report the reverse under other conditions, longer training from an already distilled model with reference resets in one and a pass@k that credits only reasoning another model judges correct in the other (Liu et al., 2025; Wen et al., 2026). The evidence does not yet decide what such training adds at frontier scale.

12.7.5 Why the grader matters for alignment #

In this loop the grader is the specification. Whatever a program rewards is what the policy is trained toward, and a flaw that one sampled response happens to find receives a large positive advantage, larger the rarer the success in its group, and spreads; Section 24.4 derives how fast. Chapter 24 treats graders as test suites, and Chapter 30 reports what the loop has produced in practice.

Sources cited in Section 12.7 9
  1. Lambert et al. (2024) Tulu 3: Pushing Frontiers in Open Language Model Post-Training
  2. DeepSeek-AI et al. (2025) DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning
  3. Kimi Team et al. (2025) Kimi k1.5: Scaling Reinforcement Learning with LLMs
  4. Shao et al. (2024a) DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models
  5. Uesato et al. (2022) Solving math word problems with process- and outcome-based feedback
  6. Lightman et al. (2023) Let's Verify Step by Step
  7. Yue et al. (2025) Does Reinforcement Learning Really Incentivize Reasoning Capacity in LLMs Beyond the Base Model?
  8. Liu et al. (2025) ProRL: Prolonged Reinforcement Learning Expands Reasoning Boundaries in Large Language Models
  9. Wen et al. (2026) Reinforcement Learning with Verifiable Rewards Implicitly Incentivizes Correct Reasoning in Base LLMs

12.8 What the anchor does not guarantee #

The KL penalty bounds how far the policy moves from the reference. It does not bound how much of the true objective is lost when the reward is wrong. A learned reward can be accurate where it was tested and wrong where the optimized policy goes. This section shows that gap in the closed form itself, states two results that bound it, and hands the general theory to Chapter 15.

12.8.1 The idea: the anchor charges for distance, not for direction #

Return to Figure 12.2 and suppose its reward rr was a proxy for an intended reward r∗r^\ast, the gold reward of Section 15.4. (The star on π∗\pi^\ast marks the optimum for the proxy rr, not for r∗r^\ast.) Let the proxy agree with r∗r^\ast where the reference policy puts most of its probability and overrate the rare responses at the top of its own scale, as a reward model fitted to the reference policy's samples might. Nothing in Equation (12.4) knows about r∗r^\ast: the optimum follows rr, and the penalty charges the same price per nat whether the distance leads toward responses that are better or toward responses that only score better.

reference π₀optimum π*proxy reward rtrue reward r*0.000.020.040.060.080.10probability01rewardresponses, in order of proxy reward r0.20.40.60.81.0expected reward048KL from π₀ (nats)proxy rtrue r*π₀κ = 20 (β = 0.05): KL 4.76 nats, expected proxy reward 0.82, expected true reward 0.54.The true reward peaks at 0.55 when the KL is 3.2 nats.
reference π₀optimum π*proxy reward rtrue reward r*0.000.020.040.060.080.10probability01responses, in order of proxy reward r0.20.40.60.81.0expected reward0246810KL from π₀ (nats)proxy rtrue r*π₀κ = 20 (β = 0.05): KL 4.76 nats, expected proxy reward0.82, expected true reward 0.54.The true reward peaks at 0.55 when the KL is 3.2 nats.
Figure 12.5 The same optimum, with the reward now read as a proxy. In the strip below the bars, the orange dots are the proxy reward r that the optimum follows and the dashed aqua line is the true reward r*, which equals r up to r = 0.5 and then bends down for the rare responses at the top of the proxy's scale. In the second panel, as κ grows the expected proxy reward (orange) keeps rising with KL, while the expected true reward (dashed aqua) rises, peaks, and falls. The proxy's error is a stated illustrative model; the optimum is computed exactly.

Figure 12.5 shows the result. As κ\kappa grows and β\beta falls, the expected proxy reward rises steadily toward 1. The expected true reward rises from the reference policy's 0.31, peaks at 0.55 when the divergence is 3.2 nats, and falls; at β=0.03\beta = 0.03 the optimum earns a proxy reward of 0.94 and a true reward of 0.46. This is the overoptimization curve of Section 15.6, produced from Equation (12.4) alone, with no training dynamics and no noise. The error sits where the reference policy is rare, which is where its samples gave the proxy no reason to be right and where the optimum goes when the anchor weakens.

12.8.2 What has been proved #

Two results bound the gap directly, each under its own assumptions.

When the true reward is linear in known features, the reward estimated from comparisons by maximum likelihood converges under the Bradley-Terry model and its extension to rankings, the Plackett-Luce model. But a policy trained against that estimate can fail, while a pessimistic estimate, which discounts responses the comparison data rarely cover, gives better policies under assumptions about how well the data cover the responses that matter (Zhu et al., 2023).

A low test error does not settle the matter either. Call a policy's regret the shortfall of its true return below the best achievable, normalized to lie between 0 and 1. A sufficiently low expected test error of a reward model guarantees low worst-case regret for the policy optimized against it. But for any fixed level of test error there are realistic data distributions with high regret, and policy regularization of the kind RLHF uses does not remove the problem (Fluri et al., 2025). The authors trace the mismatch to the distribution shift that optimization causes, the mechanism of Figure 12.5: test error is measured where the reference policy goes, and the optimized policy goes elsewhere.

Two questions remain for Chapter 15. Whether the penalty protects the true objective at all depends on the tail of the reward's error, how fast the probability of very large errors falls off, and on whether the error is independent of the true reward; Section 15.5 states the result and its conditions (Kwa et al., 2024). And whether KL is the right penalty is itself in question. The χ2\chi^2 divergence, ∑yπ(y)2/π0(y)−1\sum_y \pi(y)^2/\pi_0(y) - 1, charges far more than KL for probability moved onto responses the reference makes rare. Penalties built on it have been proposed for direct preference optimization, combined there with KL (Huang et al., 2025a), and, measured over the states and actions a policy visits, for reinforcement learning in general (Laidlaw et al., 2025); Section 15.4 teaches both.

12.8.3 Why anchor at all, and what else could be done #

The anchor still does useful work. A KL penalty toward the previous policy, the trust-region form of Section 12.1.4, makes approximate value iteration average its estimation errors instead of accumulating them, in an analysis that assumes each regularized greedy step is computed exactly, which the authors note does not hold when the policy is a neural network (Vieillard et al., 2020). In OpenAI's synthetic study of its own GPT-3-series models (Section 15.6), with another reward model's score as the gold reward, varying the KL penalty changed how early the gold reward converged but not the frontier of gold reward against KL, an effect "akin to early stopping" that the authors caution could be sensitive to hyperparameters (Gao et al., 2022). On that evidence the penalty chooses a point on the frontier the reward allows; it does not move the frontier (inference). An alternative states a limit as a constraint on a separate cost rather than a price on divergence, as constrained policy optimization does (Achiam et al., 2017); Chapter 28 develops it.

Whether KL toward the reference is the right regularizer, against the χ2\chi^2 alternatives, is a live dispute, and the evidence for the alternatives comes from proofs under stated assumptions and experiments at modest scale. As of October 2026, we found no head-to-head comparison at frontier scale with the true objective measured independently of the reward being optimized, the comparison that would settle it.

Key idea

The KL penalty fixes how far the policy may move from the reference, not which direction the reward's errors point; whether the true objective survives depends on where, and how heavily, the proxy is wrong.

Sources cited in Section 12.8 8
  1. Zhu et al. (2023) Principled Reinforcement Learning with Human Feedback from Pairwise or $K$-wise Comparisons
  2. Fluri et al. (2025) The Perils of Optimizing Learned Reward Functions: Low Training Error Does Not Guarantee Low Regret
  3. Kwa et al. (2024) Catastrophic Goodhart: regularizing RLHF with KL divergence does not mitigate heavy-tailed reward misspecification
  4. Huang et al. (2025a) Correcting the Mythos of KL-Regularization: Direct Alignment without Overoptimization via Chi-Squared Preference Optimization
  5. Laidlaw et al. (2025) Correlated Proxies: A New Definition and Improved Mitigation for Reward Hacking
  6. Vieillard et al. (2020) Leverage the Average: an Analysis of KL Regularization in Reinforcement Learning
  7. Gao et al. (2022) Scaling Laws for Reward Model Overoptimization
  8. Achiam et al. (2017) Constrained Policy Optimization

12.9 Exercises #

Exercise 12.1 The tilt by hand

Three responses have reference probabilities (0.7,0.2,0.1)(0.7, 0.2, 0.1) and rewards (0,1,2)(0, 1, 2). Compute π∗\pi^\ast, its expected reward, and its KL divergence from π0\pi_0 at β=1\beta = 1. Check the KL against Equation (12.6). Then describe the limits β→0\beta \to 0 and β→∞\beta \to \infty.

Solution

The weights π0(y)er(y)\pi_0(y) e^{r(y)} are 0.70.7, 0.2e≈0.54370.2e \approx 0.5437, and 0.1e2≈0.73890.1e^2 \approx 0.7389, so Z≈1.9826Z \approx 1.9826 and π∗≈(0.353,0.274,0.373)\pi^\ast \approx (0.353, 0.274, 0.373). The expected reward is 0.274+2×0.373≈1.0200.274 + 2 \times 0.373 \approx 1.020, up from 0.40.4 under π0\pi_0. The KL is ∑yπ∗(y)log⁡(π∗(y)/π0(y))≈0.353log⁡0.504+0.274log⁡1.371+0.373log⁡3.727≈−0.242+0.087+0.490=0.335\sum_y \pi^\ast(y) \log(\pi^\ast(y)/\pi_0(y)) \approx 0.353 \log 0.504 + 0.274 \log 1.371 + 0.373 \log 3.727 \approx -0.242 + 0.087 + 0.490 = 0.335 nats. From Equation (12.6) with κ=1\kappa = 1: 1.020−log⁡1.9826≈1.020−0.684=0.3351.020 - \log 1.9826 \approx 1.020 - 0.684 = 0.335, as before. As β→∞\beta \to \infty, π∗→π0\pi^\ast \to \pi_0, with expected reward 0.4 and KL 0. As β→0\beta \to 0, all probability moves to the third response, the expected reward tends to 2, and the KL tends to log⁡(1/0.1)≈2.303\log(1/0.1) \approx 2.303 nats, the price of certainty about a response the reference gave probability 0.1.

Exercise 12.2 Best-of-two on a coin

Two equally likely responses have rewards 0 and 1. Compute the exact best-of-two distribution and its KL divergence from the reference, and compare it with log⁡2−1/2\log 2 - 1/2. Explain the gap, and say what happens to both numbers as nn grows.

Solution

Best-of-two returns the reward-0 response only if both draws are that response, with probability 1/41/4, so π2=(1/4,3/4)\pi_2 = (1/4, 3/4). Its KL is 14log⁡1/41/2+34log⁡3/41/2≈−0.173+0.304=0.131\tfrac14 \log\tfrac{1/4}{1/2} + \tfrac34 \log\tfrac{3/4}{1/2} \approx -0.173 + 0.304 = 0.131 nats, below log⁡2−1/2≈0.193\log 2 - 1/2 \approx 0.193. The formula's derivation assumed that the maximum of the draws, mapped through the reward's distribution function, is distributed like the maximum of nn uniforms, which holds when no response carries probability on its own. Here each response carries half, the two draws repeat a response half the time, and the upper bound of Equation (12.8) is loose. For general nn, πn=(2−n,1−2−n)\pi_n = (2^{-n}, 1 - 2^{-n}), whose KL rises toward log⁡2≈0.693\log 2 \approx 0.693 (0.685 at n=10n = 10), while the formula grows without bound (1.403 at n=10n = 10, 3.615 at n=100n = 100), the example Beirami et al. (2025) use to show the gap is unbounded.

Exercise 12.3 Why reward grows like the square root of KL

Let the reward under π0\pi_0 have mean μ\mu and variance vv, and let κ=1/β\kappa = 1/\beta be small. Expand log⁡Z(κ)=log⁡Eπ0[eκr]\log Z(\kappa) = \log \E_{\pi_0}[e^{\kappa r}] to second order in κ\kappa, and use the derivation in Section 12.3.3 to show that the optimum's reward gain is approximately 2v KL⁡(π∗ ∥ π0)\sqrt{2v\,\KL(\pi^\ast \,\Vert\, \pi_0)}.

Solution

To second order, eκr≈1+κr+12κ2r2e^{\kappa r} \approx 1 + \kappa r + \tfrac12 \kappa^2 r^2, so Eπ0[eκr]≈1+κμ+12κ2(v+μ2)\E_{\pi_0}[e^{\kappa r}] \approx 1 + \kappa\mu + \tfrac12 \kappa^2(v + \mu^2). With log⁡(1+u)≈u−u2/2\log(1 + u) \approx u - u^2/2 and terms beyond κ2\kappa^2 dropped, log⁡Z≈κμ+12κ2v\log Z \approx \kappa\mu + \tfrac12 \kappa^2 v. Differentiating, Eπ∗[r]≈μ+κv\E_{\pi^\ast}[r] \approx \mu + \kappa v, so the gain is κv\kappa v. By Equation (12.6), KL⁡≈κ(μ+κv)−κμ−12κ2v=12κ2v\KL \approx \kappa(\mu + \kappa v) - \kappa\mu - \tfrac12\kappa^2 v = \tfrac12\kappa^2 v, so κ≈2KL⁡/v\kappa \approx \sqrt{2\KL/v} and the gain is κv≈2vKL⁡\kappa v \approx \sqrt{2v\KL}. Gain is linear in KL⁡\sqrt{\KL} near the reference, because divergence grows with the square of a small change and reward with the change itself; this is the reason given for the KL⁡\sqrt{\KL} axis of Section 15.6. In Figure 12.2 the reward's variance under π0\pi_0 is v≈0.0249v \approx 0.0249, and at β=1\beta = 1 the approximation gives a gain of 0.0249 at a KL of 0.0124, against exact values of 0.0253 and 0.0128.

Exercise 12.4 Group-relative advantages

A group of eight responses to one prompt has three correct answers. Compute the advantages, dividing by the standard deviation over the eight rewards. Then, for a prompt with solve rate p=0.05p = 0.05 and groups of eight, compute the probability that a group gives no training signal, and say what this implies for choosing training problems.

Solution

The mean is 3/8=0.3753/8 = 0.375 and the standard deviation 0.375×0.625≈0.484\sqrt{0.375 \times 0.625} \approx 0.484. Each correct response gets 0.625/0.484≈1.290.625 / 0.484 \approx 1.29 and each incorrect one −0.375/0.484≈−0.77-0.375 / 0.484 \approx -0.77; in closed form, 5/3\sqrt{5/3} and −3/5-\sqrt{3/5}. The advantages sum to zero, 3×1.29−5×0.77≈03 \times 1.29 - 5 \times 0.77 \approx 0, as centered values must. A group gives no signal when it is all right or all wrong, with probability 0.958+0.058≈0.6630.95^8 + 0.05^8 \approx 0.663: two thirds of the groups sampled for this prompt only cost compute. Groups of 64 would cut this to 0.9564≈0.0380.95^{64} \approx 0.038, at eight times the sampling. A training set is most efficient when concentrated on problems of intermediate difficulty for the current policy, a set that moves as the policy improves.

Sources cited in Section 12.9 1
  1. Beirami et al. (2025) Theoretical guarantees on the best-of-n alignment policy

Further reading #

References

  1. Achiam, J., Held, D., Tamar, A., and Abbeel, P. (2017). Constrained Policy Optimization. International Conference on Machine Learning. Cited in §12.8
  2. Azar, M. G., Rowland, M., Piot, B., Guo, D., Calandriello, D., Valko, M., and Munos, R. (2024). A General Theoretical Paradigm to Understand Learning from Human Preferences. Proceedings of The 27th International Conference on Artificial Intelligence and Statistics (PMLR 238). Cited in §12.6
  3. Bai, Y., Jones, A., Ndousse, K., Askell, A., Chen, A., DasSarma, N., … Kaplan, J. (2022b). Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback. arXiv. preprint Cited in §12.2 §12.5
  4. Beirami, A., Agarwal, A., Berant, J., D'Amour, A., Eisenstein, J., Nagpal, C., and Suresh, A. T. (2025). Theoretical guarantees on the best-of-n alignment policy. International Conference on Machine Learning. Cited in §12.5 §12.9
  5. Christiano, P., Leike, J., Brown, T. B., Martic, M., Legg, S., and Amodei, D. (2017). Deep reinforcement learning from human preferences. Advances in Neural Information Processing Systems. Cited in §12.2
  6. DeepSeek-AI, Guo, D., Yang, D., Zhang, H., Song, J., Wang, P., … Zhang, Z. (2025). DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. Nature. doi:10.1038/s41586-025-09422-z. Cited in §12.4 §12.7
  7. Ethayarajh, K., Xu, W., Muennighoff, N., Jurafsky, D., and Kiela, D. (2024). KTO: Model Alignment as Prospect Theoretic Optimization. International Conference on Machine Learning. Cited in §12.6
  8. Fluri, L., Lang, L., Abate, A., Forré, P., Krueger, D., and Skalse, J. (2025). The Perils of Optimizing Learned Reward Functions: Low Training Error Does Not Guarantee Low Regret. International Conference on Machine Learning. Cited in §12.8
  9. Gao, L., Schulman, J., and Hilton, J. (2022). Scaling Laws for Reward Model Overoptimization. International Conference on Machine Learning. Cited in §12.5 §12.8
  10. Gui, L., Gârbacea, C., and Veitch, V. (2024). BoNBoN Alignment for Large Language Models and the Sweetness of Best-of-n Sampling. Advances in Neural Information Processing Systems. doi:10.52202/079017-0094. Cited in §12.5
  11. Huang, A., Zhan, W., Xie, T., Lee, J. D., Sun, W., Krishnamurthy, A., and Foster, D. J. (2025a). Correcting the Mythos of KL-Regularization: Direct Alignment without Overoptimization via Chi-Squared Preference Optimization. International Conference on Learning Representations. Cited in §12.8
  12. Jaques, N., Gu, S., Bahdanau, D., Hernández-Lobato, J. M., Turner, R. E., and Eck, D. (2017). Sequence Tutor: Conservative Fine-Tuning of Sequence Generation Models with KL-control. International Conference on Machine Learning. Cited in §12.2
  13. Kappen, H. J., Gómez, V., and Opper, M. (2012). Optimal control as a graphical model inference problem. Machine Learning. Cited in §12.4
  14. Kimi Team, Du, A., Gao, B., Xing, B., Jiang, C., Chen, C., … Lin, Z. (2025). Kimi k1.5: Scaling Reinforcement Learning with LLMs. arXiv. preprint Cited in §12.7
  15. Korbak, T., Perez, E., and Buckley, C. (2022). RL with KL penalties is better viewed as Bayesian inference. Findings of the Association for Computational Linguistics: EMNLP 2022. doi:10.18653/v1/2022.findings-emnlp.77. Cited in §12.2 §12.4
  16. Kwa, T., Thomas, D., and Garriga-Alonso, A. (2024). Catastrophic Goodhart: regularizing RLHF with KL divergence does not mitigate heavy-tailed reward misspecification. Advances in Neural Information Processing Systems. doi:10.52202/079017-0466. Cited in §12.8
  17. Laidlaw, C., Singhal, S., and Dragan, A. (2025). Correlated Proxies: A New Definition and Improved Mitigation for Reward Hacking. International Conference on Learning Representations. Cited in §12.8
  18. Lambert, N., Morrison, J., Pyatkin, V., Huang, S., Ivison, H., Brahman, F., … Hajishirzi, H. (2024). Tulu 3: Pushing Frontiers in Open Language Model Post-Training. arXiv. preprint Cited in §12.6 §12.7
  19. Levine, S. (2018). Reinforcement Learning and Control as Probabilistic Inference: Tutorial and Review. arXiv. preprint Cited in §12.4
  20. Lightman, H., Kosaraju, V., Burda, Y., Edwards, H., Baker, B., Lee, T., … Cobbe, K. (2023). Let's Verify Step by Step. International Conference on Learning Representations. Cited in §12.7
  21. Liu, M., Diao, S., Lu, X., Hu, J., Dong, X., Choi, Y., Kautz, J., and Dong, Y. (2025). ProRL: Prolonged Reinforcement Learning Expands Reasoning Boundaries in Large Language Models. Advances in Neural Information Processing Systems 38. doi:10.52202/085713-0608. Cited in §12.7
  22. Ouyang, L., Wu, J., Jiang, X., Almeida, D., Wainwright, C. L., Mishkin, P., … Lowe, R. (2022). Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems. doi:10.52202/068431-2011. Cited in §12.2
  23. Rafailov, R., Sharma, A., Mitchell, E., Manning, C. D., Ermon, S., and Finn, C. (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. Advances in Neural Information Processing Systems. Cited in §12.6
  24. Rafailov, R., Hejna, J., Park, R., and Finn, C. (2024a). From to : Your Language Model is Secretly a Q-Function. arXiv. preprint Cited in §12.6
  25. Rafailov, R., Chittepu, Y., Park, R., Sikchi, H., Hejna, J., Knox, W., Finn, C., and Niekum, S. (2024b). Scaling Laws for Reward Model Overoptimization in Direct Alignment Algorithms. Advances in Neural Information Processing Systems. doi:10.52202/079017-4009. Cited in §12.6
  26. Schulman, J., Levine, S., Moritz, P., Jordan, M. I., and Abbeel, P. (2015b). Trust Region Policy Optimization. arXiv. preprint Cited in §12.1
  27. Schulman, J., Wolski, F., Dhariwal, P., Radford, A., and Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv. preprint Cited in §12.1
  28. Schultz, W., Dayan, P., and Montague, P. R. (1997). A Neural Substrate of Prediction and Reward. Science. Cited in §12.1
  29. Shao, Z., Wang, P., Zhu, Q., Xu, R., Song, J., Bi, X., … Guo, D. (2024a). DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models. arXiv. preprint Cited in §12.7
  30. Stiennon, N., Ouyang, L., Wu, J., Ziegler, D. M., Lowe, R., Voss, C., … Christiano, P. (2020). Learning to summarize from human feedback. Advances in Neural Information Processing Systems. Cited in §12.2 §12.5
  31. Sutton, R. S., McAllester, D., Singh, S., and Mansour, Y. (1999). Policy Gradient Methods for Reinforcement Learning with Function Approximation. Advances in Neural Information Processing Systems. Cited in §12.1
  32. Todorov, E. (2009). Efficient computation of optimal actions. Proceedings of the National Academy of Sciences. Cited in §12.4
  33. Uesato, J., Kushman, N., Kumar, R., Song, F., Siegel, N., Wang, L., … Higgins, I. (2022). Solving math word problems with process- and outcome-based feedback. arXiv. preprint Cited in §12.7
  34. Vieillard, N., Kozuno, T., Scherrer, B., Pietquin, O., Munos, R., and Geist, M. (2020). Leverage the Average: an Analysis of KL Regularization in Reinforcement Learning. Advances in Neural Information Processing Systems. Cited in §12.8
  35. Wen, X., Liu, Z., Zheng, S., Ye, S., Wu, Z., Wang, Y., … Yang, M. (2026). Reinforcement Learning with Verifiable Rewards Implicitly Incentivizes Correct Reasoning in Base LLMs. International Conference on Learning Representations. Cited in §12.7
  36. Williams, R. J. (1992). Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine Learning. Cited in §12.1
  37. Yue, Y., Chen, Z., Lu, R., Zhao, A., Wang, Z., Yue, Y., Song, S., and Huang, G. (2025). Does Reinforcement Learning Really Incentivize Reasoning Capacity in LLMs Beyond the Base Model? arXiv. preprint Cited in §12.7
  38. Zhu, B., Jiao, J., and Jordan, M. I. (2023). Principled Reinforcement Learning with Human Feedback from Pairwise or -wise Comparisons. International Conference on Machine Learning. Cited in §12.8
  39. Ziegler, D. M., Stiennon, N., Wu, J., Brown, T. B., Radford, A., Amodei, D., Christiano, P., and Irving, G. (2019). Fine-Tuning Language Models from Human Preferences. arXiv. preprint Cited in §12.2 §12.3
AI Alignment: From the Optimization Problem to the Institutions Around It · © 2026 Changkun Ou · CC BY-NC-SA 4.0
Bibliography · PV/UV /