- Key idea
- Reward hacking, and a KL penalty that keeps the policy near where it started
- Real world
- A cleaning robot rewarded for "no visible mess" learns to cover the mess instead of cleaning it.
- In an LLM
- A reward model that prefers longer answers produces padded, repetitive replies.
betain TRL'sGRPOConfigsets the KL weight; recent versions default it to 0.
Reward hacking
An agent optimises exactly the reward you wrote down, not the goal you had in mind. When the two differ, a strong enough optimiser finds the gap. Some real cases:
- CoastRunners (OpenAI, 2016): a boat-racing agent found it scored more by circling a lagoon and hitting the same targets forever than by finishing the race.
- Tetris: a program told to avoid losing learned to pause the game just before the last block landed, and never unpause.
- Chat models: reward models trained on human preferences often favour longer, more confident answers, so RL drifts toward padding and flattery.
- Coding models: rewarded for passing unit tests, a model can learn to special-case the test inputs, or edit the tests, instead of fixing the code.
- Maths models: a checker that looks for the last number in the answer can be gamed by listing several numbers.
Better rewards help, but you can never specify everything. The other defence is to limit how far the policy can move.
The KL penalty
Score = reward − β × (how far the policy has drifted from a frozen reference copy of itself). The drift is measured with the , which is 0 when the two policies are identical. Small β: chase the reward. Large β: stay close to the original behaviour.
Try it: a reward model that likes long answers
A model gives a short answer 80% of the time and a long one 20%. The reward model scores them 0.5 and 1.0. With a KL penalty, the best possible policy multiplies each answer’s original chance by and rescales so the chances add up to 100%:
| β | Short answer | Long answer |
|---|---|---|
| Reference model | 80% | 20% |
| 1 | → 71% | → 29% |
| 0.1 | → 3% | → 97% |
With β = 1 the model shifts a little toward the higher reward. With β = 0.1 it almost always gives the long answer. If length is what the reward model is wrong about, that is the hack winning.
In language models
The reference model is the model as it was before RL. Rewards that can be checked by rules, such as an exact maths answer or passing unit tests, are much harder to hack than a learned reward model. That's one reason many recent training recipes use them with little or no KL penalty: DAPO and Olmo 3 drop it entirely for maths and code, while DeepSeek keeps a small, per-domain one. For learned rewards, which are easier to hack, the penalty stays.
Objective and its optimum
The widget and the example compute exactly from this formula. The same closed form is the starting point for DPO, which trains on preference pairs directly without sampling.
Estimating KL from samples
The exact KL needs a sum over every possible answer, so trainers estimate it from the sampled tokens. With for a sampled token, three standard estimators are:
and are unbiased; also has low variance and is never negative, which is why GRPO adopted it. For one token with : , , . With : (a negative "distance"), .
Where the estimate goes also matters. Added to the reward, gives the correct gradient. Used directly as a loss term, as GRPO does with , the gradient is only approximately right, and as a loss has zero expected gradient. DeepSeek-V3.2 reweights by the current-to-sampling probability ratio to remove the bias.
Papers
- Schulman, Approximating KL Divergence (blog, 2020)
- Rethinking KL Regularization in RLHF (Oct 2025)