KL Regularization in RLHF
Definition
KL regularization in RLHF is a penalty on the KL divergence between the policy being trained and a frozen reference policy (usually the SFT model), added to the reward. It is a leash that keeps the policy from drifting into regions where the learned reward model is unreliable — the mechanism that prevents reward hacking / over-optimization and preserves fluency over the whole training run. It is distinct from PPO’s implicit trust-region KL.
Key math
The per-token reward combines a terminal RM score with a dense KL penalty at every position:
so the total objective PPO maximizes is
is the reward-vs-fidelity dial: too small → the policy chases the RM into its blind spots (high score, degenerate/dishonest text); too large → the policy is leashed so tightly it barely improves. Often adapted to a target KL (a few nats/response), exactly like PPO-Penalty’s adaptive- controller — but against a frozen anchor rather than . This reference-KL objective is also what DPO solves in closed form.
Why it matters
The reward model is a learned, imperfect proxy for human preference, and its errors are largest exactly where the SFT model rarely ventures — so an unconstrained optimizer marches straight into those blind spots. The term makes that drift costly, trading a little reward to stay in-distribution where is trustworthy. Tuning is the central knob of the RLHF pipeline. Two KLs, don’t conflate: the reference KL bounds total drift (long horizon, fixed anchor); the trust-region KL to bounds step size (short horizon, moving anchor, enforced by clip).
Taught in
- 04-ppo — the RM-score-minus-KL reward, the two-KL distinction, and why the reference KL is load-bearing against reward hacking.
See also
- reward-model — the imperfect proxy the KL guards against
- rlhf — the pipeline this regularizer lives in
- ppo — the optimizer applying it
- trust-region — the other (implicit) KL in RLHF-PPO
- rl-for-llms