The KL penalty in RLHF constrains the trained policy from drifting too far from the reference (SFT) model.
In the RLHF objective:
Why it's essential — without KL penalty:
- The model finds "adversarial" outputs that score high on the reward model but are actually bad
- Reward hacking: the model exploits imperfections in the learned reward model
- Examples: generating very long responses (length bias), using sycophantic language, repeating phrases the reward model likes
- The outputs become degenerate — high reward, low quality
What KL penalty does:
- Keeps close to in distribution space
- Acts as a regularizer: "be better, but don't change too much"
- controls the tradeoff: higher = more conservative, lower = more optimization
- In practice, is often adapted during training
Connection to KL Divergence:
- Measures how many "bits" of difference between the two policies
- Penalizes deviations proportional to how unlikely the output would be under the reference
See also: RLHF Pipeline, KL Divergence, Proximal Policy Optimization (PPO)