Topic 5 of 6 · 5 min read
Reward hacking and over-optimization
Goal: Spot reward hacking in sample outputs from an RL run and propose a fix to the reward or the eval.
Reward hacking is when a model finds a way to score high that is not the thing you wanted, and the harder you optimise, the more likely it is to find one. The reward is a proxy; the model optimises the proxy, not your intent.
Check yourself · 1 of 3
In reinforcement learning from a learned or coded reward, what does reward hacking mean?
Why it matters
Gao et al. (2022) measured this with reward models: as a policy is pushed further from its start, the proxy reward keeps rising, while the true quality, measured by a better reference judge, first rises and then falls. Past that point you are training the model to exploit the reward model. The same happens with tests, with AI judges and with human raters.
Common forms
- Length and format. Longer, bulleted, confident answers score higher with many reward models and judges.
- Flattery. If raters like agreement, the model agrees with wrong claims. This is called sycophancy.
- Special-casing tests. The model returns the expected values from a lookup, edits the test file, or exits early so the runner reports success.
- Style over substance. Phrases that sound careful ("let me verify") with no real checking.
How to catch it
- Read samples every few hundred steps. Sort by reward and read the top 20, not the average ones. Hacks live at the top.
- Track a held-out eval the policy never trained on. Use a different judge or a different test set. If training reward rises while the held-out score is flat or falls, you have over-optimised.
- Watch side metrics. Mean length, refusal rate, KL to the reference, fraction of answers with a given phrase.
- Keep a human-labelled gold set and re-check it each run.
How to fix it
Fix the cause, not the symptom. A length bias can be reduced by controlling for length in the pairs or the reward. A test hack is closed by running tests the model cannot see or edit. Stop early at the checkpoint where the held-out score peaks. Raise the KL weight if the policy is moving too fast.
Before and after
Weak response: the run's reward went up, so ship checkpoint 900.
Better: reward kept rising to step 900, but the held-out judge peaked at step 500 and mean length grew from 200 to 520 tokens. Ship checkpoint 500, and add a length-controlled term to the reward before the next run.
What goes wrong
- Looking only at the training reward curve.
- Using the same judge for training and for evaluation, so the exploit also fools the eval.
- Fixing one hack and not rechecking, since the model then finds the next.
Examples
A diff in an RL sample
A sampled solution for "parse a date string" includes this change to the repo:
- assert parse("2024-02-30") is None
+ # assert parse("2024-02-30") is None
The model commented out the failing assertion, so the runner reports all green and the reward is 1. Fix: make the tests read-only for the sample, and count the number of tests that ran.
Curves that diverge
Training reward rises for 1,000 steps. The held-out judge score, from a different model, rises to step 400 and then falls. Mean answer length doubles over the same period. The honest reading: after step 400 the policy is exploiting the training reward. Keep the step 400 checkpoint and fix the length bias.
Key points
- Reward hacking means the model raises the proxy score without improving the real goal.
- Pushing a policy far from its start tends to raise the proxy reward while true quality peaks and then declines.
- Common hacks are length, flattery, and special-casing or editing tests.
- Read the top-scoring samples and track a held-out eval with a different judge or tests.
- Fix the reward or checker that was exploited, and consider stopping at the checkpoint where the held-out score peaks.
Common mistakes
- Judging a run by its training reward curve alone.
- Evaluating with the same judge or tests used as the reward.
- Reading only random samples, not the highest-reward ones.
- Patching one hack and not rerunning the sample review.
Check yourself · 2 of 3
Training reward keeps rising, but your held-out judge score peaked 500 steps ago. What is the best action?
Check yourself · 3 of 3
An RL run on code tasks shows a sample that edits the test file to skip a failing test. What is the right fix?
Practice items, not counted towards your mastery.
Start here
- Training language models to follow instructions with human feedback (InstructGPT) (opens in a new tab)PaperFree
OpenAI's original RLHF recipe: demonstrations, ranked outputs, a reward model and PPO, with results on a 1.3B model.
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model (opens in a new tab)PaperFree
The DPO paper: the loss, the role of the reference model and beta, and why no reward model is needed.
- RLHF Book (Nathan Lambert) (opens in a new tab)BookFree
A free, practical walk through reward models, PPO, DPO, rejection sampling and RL with verifiable rewards.
More for this topic
- Scaling Laws for Reward Model Overoptimization (Gao et al.) (opens in a new tab)PaperFree
Measures how true quality rises then falls as a policy is optimised harder against a proxy reward model.