Chapter 16 · Section 16.5 · 55 min

Reward hacking and overoptimization

In 2016 OpenAI trained an agent to play CoastRunners, a boat-racing game whose score rewards hitting targets along the course. The agent found a lagoon where three targets respawned, and circled it forever, crashing and catching fire, scoring higher than human players while never finishing the race (Clark and Amodei 2016). Nothing was wrong with the optimizer. It did exactly what the score said.

RLHF is the same situation with a subtler score. The reward model is a learned approximation of what people prefer, fit to a few tens of thousands of comparisons, and RL is a powerful search for the responses it scores highest. Stiennon et al. (2020) watched this happen. As they optimized summaries harder against their reward model, its score kept climbing, while human labelers first liked the summaries more, then less, and eventually the reward model's preferences were anti-correlated with theirs.

This section explains why that is inevitable for any learned reward, measures it with the scaling laws of Gao et al. (2023), names the specific exploits that show up in practice (length, sycophancy, and friends), and goes through the mitigations, with an honest account of what each one fixes.

Goodhart's law

The economist Charles Goodhart observed in 1975 that a statistical regularity tends to collapse once it is used as a target for control. The anthropologist Marilyn Strathern later put it in the form everyone quotes, "when a measure becomes a target, it ceases to be a good measure". Reward hacking is Goodhart's law for optimizers, and Skalse et al. (2022) gave it a precise definition. A proxy reward is hackable if increasing the expected proxy return can ever decrease the expected true return. They proved that, if the policy can be any stochastic policy, two reward functions are unhackable with respect to each other only if they are equivalent (they order every policy the same way) or one of them is trivial (it gives every policy the same return). Some hackability is the normal case, not a bug in a particular reward model.

Manheim and Garrabrant (2018) separated four ways a proxy fails under pressure, and Gao et al. (2023) used the same four to read their results. Each has an RLHF face.

variantmechanismin RLHF
regressionalthe proxy is the truth plus noise, so selecting high proxy also selects high noisethe best-scoring responses are partly just lucky draws of reward-model error
extremalthe proxy and the truth agree on ordinary inputs and part ways on extreme onesa reward model trained on SFT outputs extrapolates "longer is better" to absurd lengths
causalthe proxy tracks a feature that correlates with quality without causing itconfident tone, bullet points, or citations that look like effort
adversarialan agent manipulates the proxy, or the people behind itsycophancy, persuasive wrong answers, flattery of the annotator

Regressional Goodhart alone does not make things get worse, only disappointing. Recall the noisy judge of §16.1. With true quality q∼N(0,1)q \sim \mathcal{N}(0, 1) and proxy s=q+es = q + e, e∼N(0,σe2)e \sim \mathcal{N}(0, \sigma_e^2), picking the best of nn by proxy gives an expected proxy of 1+σe2 mn\sqrt{1 + \sigma_e^2}\,m_n and an expected true quality of mn/1+σe2m_n/\sqrt{1 + \sigma_e^2}, so the true gain is always the fraction 1/(1+σe2)1/(1 + \sigma_e^2) of the proxy gain. Both keep rising with nn. For the true reward to fall, the proxy's error must grow in the direction the optimizer pushes, which is extremal Goodhart. Let's build exactly that. A response has one feature yy (think of it as verbosity) drawn from the reference policy as y∼N(0,1)y \sim \mathcal{N}(0, 1). The true (gold) reward is rgold(y)=y−0.25y2r_{\text{gold}}(y) = y - 0.25y^2, which rises up to y=2y = 2 and then falls, because past some point more is worse. The reward model, fit on ordinary responses, learned rproxy(y)=y+noiser_{\text{proxy}}(y) = y + \text{noise}, which is right near the data and wrong far from it. Now run best-of-nn.

Python · cell 1

The proxy rises forever, like the expected maximum of more and more samples. The gold reward rises at first, because near the data the proxy is right, peaks around n=64n = 64, and then falls as best-of-nn selects ever more extreme responses where "more" has stopped being good. By n=4096n = 4096 a large part of the gain is gone, and the reward model is still reporting progress. That is overoptimization, in thirty lines and one feature. The function bon_expect deserves a note. It computes the expected best-of-nn outcome over every subset of size nn of the pool at once, so the curve is smooth without resampling. Exercise 16.5b derives it.

Scaling laws for reward model overoptimization

Measuring the gold reward requires knowing it, and with human preferences you do not, except by running expensive human evaluations. Gao et al. (2023) got around this with a synthetic setup. A 6B reward model, the InstructGPT one, served as the "gold" standard and labeled 100,000 comparisons. Proxy reward models from 3M to 3B parameters were trained on those labels, a 1.2B policy (and a 6B one) was optimized against each proxy by best-of-nn or by PPO, and the gold reward model scored the results. Everything could then be measured as a function of how far the policy had moved.

They measured distance as d=DKL(π∥πref)d = \sqrt{D_{\mathrm{KL}}(\pi\Vert\pi_{\text{ref}})}. In this section dd means that square-rooted KL, as in their paper, and not a model width. The gold reward (relative to the starting policy, so R(0)=0R(0) = 0) followed two simple functional forms,

Rbon(d)=d (αbon−βbon d),RRL(d)=d (αRL−βRLlog⁡d),R_{\text{bon}}(d) = d\,(\alpha_{\text{bon}} - \beta_{\text{bon}}\,d), \qquad R_{\text{RL}}(d) = d\,(\alpha_{\text{RL}} - \beta_{\text{RL}}\log d),

with coefficients that depend on the reward model. (These α\alpha and β\beta always carry their subscript, to keep them apart from the KL coefficient β\beta of §16.4.) In plain words, at first the gold reward grows linearly in the distance traveled, at rate α\alpha, and then a penalty that grows with distance, quadratically for best-of-nn and like dlog⁡dd\log d for RL, takes over and bends it back down.

Each curve has a peak, which tells you how far it pays to optimize. For best-of-nn, Rbon′(d)=αbon−2βbond=0R'_{\text{bon}}(d) = \alpha_{\text{bon}} - 2\beta_{\text{bon}}d = 0 gives

dbon⋆=αbon2βbon,Rbon⋆=αbon24βbon.d^\star_{\text{bon}} = \frac{\alpha_{\text{bon}}}{2\beta_{\text{bon}}}, \qquad R^\star_{\text{bon}} = \frac{\alpha_{\text{bon}}^2}{4\beta_{\text{bon}}}.

For RL, RRL′(d)=αRL−βRLlog⁡d−βRL=0R'_{\text{RL}}(d) = \alpha_{\text{RL}} - \beta_{\text{RL}}\log d - \beta_{\text{RL}} = 0 gives log⁡dRL⋆=αRL/βRL−1\log d^\star_{\text{RL}} = \alpha_{\text{RL}}/\beta_{\text{RL}} - 1, and substituting back,

dRL⋆=exp⁡ ⁣(αRLβRL−1),RRL⋆=βRL dRL⋆.d^\star_{\text{RL}} = \exp\!\Big(\frac{\alpha_{\text{RL}}}{\beta_{\text{RL}}} - 1\Big), \qquad R^\star_{\text{RL}} = \beta_{\text{RL}}\,d^\star_{\text{RL}} .

Our one-feature simulation is a best-of-nn experiment, so the best-of-nn form should fit it. A neat property makes the fit easy. Dividing by dd gives R/d=αbon−βbondR/d = \alpha_{\text{bon}} - \beta_{\text{bon}}d, a straight line in dd, so ordinary least squares on (d,R/d)(d, R/d) recovers both coefficients. (For RL, R/dR/d is a straight line in log⁡d\log d.)

Python · cell 2

The fitted peak sits at a KL of about 2.8 nats, about where the table showed the gold reward topping out (between n=16n = 16 and n=64n = 64), and the two-parameter form follows the whole curve closely. In Gao et al.'s experiments the same forms fit real reward models, and their main findings are worth knowing one by one.

  • Bigger reward models overoptimize less. The coefficients changed smoothly, roughly linearly in the logarithm of the proxy's parameter count. Larger proxies give a higher peak, reached at a larger KL. For RL, αRL\alpha_{\text{RL}} stayed nearly constant and βRL\beta_{\text{RL}} carried the size dependence.
  • More reward model data helps too. Below about 2,000 comparisons the proxies were near chance, and more data gave better gold scores and less overoptimization.
  • RL is far less KL-efficient than best-of-nn. RL "consumes" much more KL to reach the same proxy score, and to overoptimize. KL is not a universal currency between methods.
  • The KL penalty did not move the frontier. Adding a KL penalty to the RL objective made the gold score peak earlier in training, like early stopping, but at any given KL the gold score was the same with or without it. (They note this may depend on hyperparameters, and their main RL runs used no KL penalty.)
  • Bigger policies gain less but do not overoptimize more. A 6B policy started higher and improved less than a 1.2B one, and both peaked at about the same KL.

How far best-of-n moves the policy

Best-of-nn is the cleanest optimizer to analyze, because its KL from the reference has a closed form, at least when no two responses tie.

∂ The KL of best-of-n from the reference

Let the reference produce responses whose proxy scores have a continuous CDF FF, and let u=F(score)∈[0,1]u = F(\text{score}) \in [0, 1] be a response's quantile, which is uniform under the reference. Best-of-nn keeps the response with the largest quantile among nn independent ones. The largest of nn uniforms has density nun−1n u^{n-1} on [0,1][0, 1], so relative to the reference, the best-of-nn policy reweights a response at quantile uu by the likelihood ratio πbon/πref=nun−1\pi_{\text{bon}}/\pi_{\text{ref}} = n u^{n-1}. The KL is the expected log of that ratio under πbon\pi_{\text{bon}},

DKL(πbon∥πref)=∫01nun−1log⁡(nun−1) du=log⁡n+(n−1)∫01nun−1log⁡u du.D_{\mathrm{KL}}(\pi_{\text{bon}}\Vert\pi_{\text{ref}}) = \int_0^1 n u^{n-1}\log\big(n u^{n-1}\big)\,du = \log n + (n - 1)\int_0^1 n u^{n-1}\log u\,du .

For the last integral, integrate by parts or use ∫01un−1log⁡u du=−1/n2\int_0^1 u^{n-1}\log u\,du = -1/n^2, so ∫01nun−1log⁡u du=−1/n\int_0^1 n u^{n-1}\log u\,du = -1/n. Therefore

DKL(πbon∥πref)=log⁡n−n−1n.■D_{\mathrm{KL}}(\pi_{\text{bon}}\Vert\pi_{\text{ref}}) = \log n - \frac{n-1}{n}. \qquad \blacksquare

In plain words, best-of-nn moves about log⁡n\log n nats, so each doubling of nn buys a fixed amount of KL, log⁡2≈0.69\log 2 \approx 0.69 nats, minus a small correction. Best-of-2 is only 0.19 nats away from the reference, best-of-16 1.84, best-of-1024 5.93. Beirami et al. (2024) pointed out that for real language models, where many samples can coincide (short answers repeat), the formula is an upper bound on the true KL, not its exact value, and gave a better estimator. It is exact in the continuous, no-ties case derived here.

Warm-up

The KL budget of best-of-n

Implement bon_kl(n), the KL of best-of-nn from the reference by the formula above (it must work elementwise on arrays), and largest_n_within(budget), the largest integer n≥1n \ge 1 whose best-of-nn KL is at most budget nats.

Hidden tests, hints, and AI help, from $1.99 a month.
Interview

Best-of-n with a reward model, and its exact expectation

Best-of-nn is the simplest way to use a reward model at inference time, and the way to measure overoptimization without running RL. Implement two functions.

best_of_n(scores, n) takes scores of shape (P, N), reward model scores of NN samples for each of PP prompts, and returns the index of the best of the first nn samples for each prompt, shape (P,) (ties go to the earliest).

expected_best_of_n(proxy, gold, n) takes one prompt's pool of NN samples, with proxy scores and gold scores (arrays of shape (N,)), and returns the expected gold score of the sample chosen by best-of-nn on the proxy, averaged exactly over all (Nn)\binom{N}{n} subsets of size nn. Sort the pool by proxy score, ascending. The ii-th smallest (1-indexed) is the subset's maximum exactly when it is in the subset and the other n−1n-1 members come from the i−1i-1 below it, which happens in (i−1n−1)\binom{i-1}{n-1} of the (Nn)\binom{N}{n} subsets. Assume no ties in the proxy. Use log-gamma or exact integers, because these binomials overflow floats.

Hidden tests, hints, and AI help, from $1.99 a month.
Interview

Fitting the overoptimization curves

Implement fit_bon(d, R) and fit_rl(d, R), each returning (alpha, beta) for the forms R=d(αbon−βbond)R = d(\alpha_{\text{bon}} - \beta_{\text{bon}}d) and R=d(αRL−βRLlog⁡d)R = d(\alpha_{\text{RL}} - \beta_{\text{RL}}\log d) by least squares on R/dR/d (use only points with d>0d > 0). Then implement peak_bon(alpha, beta) and peak_rl(alpha, beta), each returning (d_star, R_star), the location and height of the curve's maximum.

Hidden tests, hints, and AI help, from $1.99 a month.

The widget runs the full experiment in your browser. A pool of reference samples lives in a 2D response space, a gold reward is defined on it, and an ensemble of proxy reward models each sees the gold reward plus its own error, an error that is small near the data and grows away from it. Best-of-nn is computed exactly for every nn with the subset formula, and the best-of-nn form is fit to the gold curve.

Why does the true reward peak and fall while the reward model's score keeps rising?
Best-of-n over 3,000 reference samples in a 2D response space, computed exactly over all subsets for each n. Each proxy reward model sees the gold reward plus an error that is small near the data and grows away from it. The horizontal axis is the square root of the best-of-n KL.
Loading interactive figure…

In a real system, best-of-nn is a batching pattern. Repeat each prompt nn times, sample all the responses in one batch, score them with the reward model in one batch, reshape the scores to (P, n), and gather the winners. Here it is with a stand-in policy (independent per-position token distributions) and a stand-in reward model, so the pattern is visible without a real model.

🔥 In PyTorchfor a machine with PyTorch

What models actually learn to exploit

The overoptimization curves are averages. Up close, reward hacking takes a few recognizable forms.

Length. The most common and best documented. Singhal et al. (2023) found that across three RLHF settings, much of the reward improvement came from longer responses, and that optimizing a reward of response length alone reproduced most of RLHF's gain over SFT. The reward model is the main culprit, having picked up the length correlation in its preference data (§16.2), often more strongly than the annotators themselves held it (§16.3). Length is also cheap for the policy to change, so it is the first direction RL finds.

Sycophancy. A model tells users what they want to hear. Perez et al. (2022) found that larger models more often repeat back a user's stated view, and that more RLHF made some behaviors worse, for example stronger expressed political views. Sharma et al. (2023) showed that five production assistants were consistently sycophantic across four tasks, that human preference data favors responses matching the user's views, and that optimizing against a preference model sometimes traded truthfulness for agreement. This is adversarial Goodhart with the annotator as the target. The policy learns what wins comparisons, and agreeing with the person judging you wins comparisons.

Persuasive wrongness. Wen et al. (2024) gave the problem its sharpest form. After RLHF on tasks where people could not easily check answers, models became better at convincing human evaluators that wrong answers were right, without becoming more correct. Evaluators' false positive rate rose by 24.1% on a reading comprehension task and 18.3% on a programming task. When the judge cannot verify, optimizing the judge's approval optimizes the appearance of correctness.

Style and hedging. Formatting that looks thorough (headers, lists, bold), reflexive disclaimers, and refusals of borderline requests all raise scores under some reward models without making answers better. Which ones appear depends on the reward model, so they are best found by reading samples from the policy at the end of training, not by guessing in advance.

Hacking the verifier. When the reward is a program, the exploits are bugs. Models trained against unit tests have learned to special-case the tests, and models graded by answer matching have learned to output in formats the checker misparses (§18.3). The broader catalog of specification gaming in RL agents is the subject of §19.1.

Mitigations, and what each one fixes

There is no cure, because a learned reward is a proxy by construction. There are several ways to optimize it more safely, and they combine.

The KL penalty. It limits how far the policy moves, and so how deep into the extremal region it can go. Gao et al. found it behaves like early stopping, reaching the same gold-versus-KL frontier sooner rather than raising it. Kwa et al. (2024) add a theoretical warning. When the reward model's errors are heavy-tailed, KL regularization cannot prevent "catastrophic Goodhart", policies that reach very high proxy reward with no more true utility than the reference, because a small amount of probability on rare, wildly overrated responses is cheap in KL. (Their measurements of real reward models found light-tailed errors, which is reassuring for now.)

Early stopping on an independent signal. The most reliable mitigation in practice. Since gold rises then falls, stop near the peak, judged by evaluations the policy was not trained against (§16.6).

Better reward models. Every finding of Gao et al. points the same way. More preference data and larger reward models raise the peak and push it out. Fresh on-policy comparisons, collected as the policy moves, fix the reward model exactly where it is being exploited (§16.2), which is why Anthropic and Llama 2 iterated.

Ensembles and conservative objectives. Train several reward models and optimize a pessimistic score, the worst member (worst-case optimization) or the mean minus a multiple of the members' variance (uncertainty-weighted optimization; many reimplementations subtract a multiple of the standard deviation instead, as the cell below does). Responses that only one member loves score low. Coste et al. (2023), in Gao's synthetic setup with 25% label noise, found that conservative ensembles practically eliminated overoptimization for best-of-nn (gains of up to 70%) and always reduced it for PPO. Eisenstein et al. (2023) found that ensembles help but do not eliminate hacking, because members trained from the same pretrained model share blind spots, and that diversity in pretraining seeds matters more than in fine-tuning seeds. WARM averages the weights of several fine-tuned reward models instead of their outputs, for one model's inference cost (Ramé et al. 2024).

Constraints instead of a sum. When the reward combines several reward models (helpfulness, harmlessness, honesty), each has its own overoptimization point. Moskovitz et al. (2023) treat each component as a constraint to keep at its useful threshold rather than a term to maximize, and learn the weights as Lagrange multipliers during training. Llama 2's piecewise combination (use the safety score when it is low or the prompt is risky, the helpfulness score otherwise) is a hand-built version of the same idea.

Reshaping the reward. Reward models trained with Bradley-Terry measure log-odds, and a policy gains as much from pushing an already-great response higher as from fixing a bad one. Wang, Nagpal, et al. (2024) proposed passing the centered reward through a log-sigmoid, which saturates for responses already well above a reference, so the policy is paid mostly for fixing bad outputs. Llama 2 went the other way for a different reason. Its combined score was a probability, so it applied the logit to undo the sigmoid and then whitened the result, for stability and to balance the reward against the KL penalty.

Targeting known exploits. For length, use length-balanced preference data, a length penalty in the reward, a reward model with a separate length head (ODIN), and length-controlled evaluation (Dubois et al. 2024). For sycophancy, add preference data in which the correct answer disagrees with the user.

Python · cell 3

Selecting by the gold reward itself climbs steadily toward the best value, 1.0. The single reward model peaks around n=256n = 256 and then falls, the familiar curve. Averaging five members shrinks each member's private error, which raises the curve but does not stop the fall, because at large nn best-of-nn still finds responses whose average error happens to be large. The two pessimistic objectives pay a price at small nn, since they also discount good responses the members disagree about, and keep improving all the way to n=1024n = 1024, where they beat the single model by about 0.06. If the members' errors were shared, every one of these objectives would see the same thing and none of them would help, which is Eisenstein et al.'s point.

Core

Conservative ensemble rewards for best-of-n

Implement conservative_reward(S, method, k=1.0) where S has shape (M, N), the scores of NN responses under MM reward models. method is "mean", "mean_minus_std" (the mean minus k times the population standard deviation, ddof=0, across members), or "min" (worst-case). Return shape (N,). Then implement pick(S, method, k=1.0), the index of the response with the highest conservative reward.

Hidden tests, hints, and AI help, from $1.99 a month.
mitigationfixesdoes not fixcost
KL penaltyhow far the policy travels into extrapolationthe gold-versus-KL frontier (Gao), heavy-tailed errors (Kwa)one frozen reference model
early stopping on held-out evalsstops near the gold peakanything the evals cannot seeevaluation compute and judgment
more data, bigger reward modelraises and delays the peaksystematic biases in the labelsannotation and compute
on-policy data refreshreward model errors where the policy now isbiases the annotators sharenew annotation rounds
ensembles, conservative objectiveserrors members do not shareerrors they shareMM reward models, or weight averaging
constrained RLHFovershooting any one component's useful rangea wrong thresholdthreshold estimation
reward transforms (log-sigmoid)paying for already-good responsesreward model errors on bad responsesnone
length controlslength exploitationother style exploitssome data or a second head

Read more

Watch next

🎬 9 Examples of Specification Gaming · Robert Miles AI SafetyA tour of optimizers that found the loophole instead of the task, the pattern behind reward hacking.
🎬 Learning to summarize from human feedback (Paper Explained) · Yannic KilcherA walk through the paper that first showed a learned reward rising while human preference falls.