A KL penalty is a term in an RL objective that charges the policy for moving away from a fixed reference policy, measured by Kullback-Leibler divergence. In RLHF the reference policy is usually the supervised fine-tuned model, and the penalty stops the policy from drifting into degenerate text that only a reward model could love.
The objective
Here is the policy being trained, is the frozen reference policy, is the reward and sets the strength of the penalty. In practice the KL is estimated per sample as , summed over tokens, and is either folded into the reward or added to the loss.
What the penalty does
This objective has a closed-form maximiser:
where normalises the distribution. The optimal policy reweights the reference rather than replacing it: responses the reference considers impossible stay impossible, and acts as a temperature on the reward. DPO is derived from exactly this formula.
Worked example
Two responses each have reference probability 0.5; one has reward 1, the other 0. With , the optimal policy puts on the better response. With it puts only there. As the policy greedily picks the highest reward; as it stays equal to the reference.
Choosing beta
- Too small: the policy finds reward-model blind spots, the signature of reward overoptimisation.
- Too large: almost nothing is learned.
- Adaptive schemes, as in Ziegler et al. (2019), tune to hit a target KL per batch. Reporting KL alongside reward makes runs comparable.
Why it matters
KL from the reference is the most useful single dial for how much a model has changed during RL. Gao et al. (2022) plotted true quality against and found it peaks and then declines, so KL budget is effectively a safety margin against reward hacking. It also preserves capabilities and calibration learned in pretraining that a narrow reward would otherwise erode.
Related terms
- RLHF (reinforcement learning from human feedback)
- DPO (Direct Preference Optimization)
- Reward overoptimization
- Reward hacking
- PPO (Proximal Policy Optimization)
- Best-of-n sampling