Overview

15 Regularization

The chapter explains that regularization is essential in RLHF because powerful post-training updates can push a model too far from its strong reference model and cause over-optimization. When this happens, the model may start producing degraded or nonsensical outputs such as repeated text, strange characters, or broken reasoning. Regularization is therefore used to keep optimization controlled while still allowing the model to improve from human feedback and other reward signals.

The central technique is KL-based control, where the reward objective is reduced by a penalty for drifting from a reference policy. In practice, this penalty is usually computed between the current RL policy and a fixed reference model, often using a reverse KL form that strongly discourages assigning probability to outputs the reference model considers unlikely. The chapter also shows how the computation is approximated efficiently with log probabilities, and notes that although many regularization tricks appear in specific systems, KL regularization remains the core stabilizing tool in most RLHF implementations.

The chapter also argues that RL has an implicit regularizing effect beyond any explicit penalty. Empirical results suggest that RL generalizes better than SFT and forgets less because on-policy updates stay close to the model’s own distribution, while SFT trains from a fixed external dataset that can pull the model away from prior knowledge. This difference is tied to forward versus reverse KL behavior: SFT tends to spread probability broadly and can overwrite earlier capabilities, whereas RL updates are more local and preserve existing structure. The chapter closes by surveying other stabilizers such as pretraining-gradient replay, NLL terms added to DPO, and margin-based losses for reward modeling.

Forgetting dynamics for forward KL (SFT) versus reverse KL (RL). The “old” mode represents prior knowledge, the “new” mode represents the target task. Forward KL stretches the policy to cover the target and pulls mass away from the old mode (top right), while reverse KL shifts the new mode toward the target without disturbing the old mode (bottom right). From Chen et al. 2025, with permission of the author.
figure
Bias toward KL-minimal solutions reduces forgetting. (Left) Among policies that solve the new task, RL converges to those closest in KL to the base model. (Right) This KL bias yields higher prior-task retention at matched new-task performance compared to SFT. From Shenfeld, Pari, and Agrawal 2026. License CC-BY.
figure

Summary

  • Regularization in RLHF prevents the optimizers introduced in Chapter 6 from pushing the model too far from its starting point, avoiding degenerate outputs like repeated text, language switching, or nonsensical reasoning.
  • The primary regularization tool is a KL divergence penalty between the current policy and a reference model, applied to generated tokens during training. The reverse KL direction used in most RLHF implementations strongly penalizes the new model for placing probability mass where the reference model assigns low probability.
  • Other regularization approaches include mixing in pretraining gradients or a negative log-likelihood (NLL) term on winning completions to preserve general language modeling quality, and margin losses for reward model training (as in Llama 2) or reward-weighted DPO variants that integrate reward scores into the preference optimization update.
  • RL-based post-training also provides implicit regularization: RL generalizes where SFT memorizes (due to reverse vs. forward KL dynamics), and on-policy sampling inherently biases RL toward solutions that stay close to the base model, reducing forgetting of prior knowledge.

FAQ

What is the main purpose of regularization in RLHF?Regularization helps keep the policy from drifting too far from a strong reference model during optimization. In RLHF, this prevents over-optimization, which can cause the model to produce nonsensical or low-quality outputs even if the reward increases.
What does over-optimization mean in the context of RLHF?Over-optimization happens when the model learns too aggressively from the reward signal and moves too far from the reference model. This can hurt out-of-distribution behavior and lead to strange outputs such as repeated text, wrong reasoning, special-character spam, or language switching.
Why is KL divergence used as a regularizer in RLHF?KL divergence is widely used because it measures how much the current policy has diverged from the reference policy. By penalizing large KL values, training stays closer to the original model’s behavior while still allowing improvement on the reward objective.
What is the standard RLHF objective with KL regularization?The usual form is to maximize reward while subtracting a KL penalty: \(r = r_\theta - \lambda_{\text{KL}} \mathcal{D}_{\text{KL}}(\pi_{\text{RL}}(y \mid x) \| \pi_{\text{ref}}(y \mid x))\). This encourages high reward but constrains the policy to remain near the reference model.
What is the difference between forward KL and reverse KL in this chapter?Forward KL is \(\text{KL}(\pi_\star \| \pi_\theta)\), where the target distribution is sampled first, and it tends to be mode-covering. Reverse KL is \(\text{KL}(\pi_\theta \| \pi_\star)\), where the model samples from itself, and it tends to be mode-seeking.
Why does RL generalize better than SFT according to this chapter?RL typically uses on-policy sampling and behaves like reverse KL, which keeps updates local to where the model already places probability mass. SFT behaves more like forward KL, which can spread probability more broadly and disrupt prior knowledge, leading to more memorization and worse out-of-distribution generalization.
Why can SFT cause forgetting while RL preserves prior knowledge better?SFT trains on a fixed external dataset and pulls the model toward those examples even if they are far from the current policy, which can overwrite older capabilities. RL trains on the model’s own generations, so updates are constrained to regions the model already visits, which helps preserve previous knowledge.
What is meant by “RL’s Razor”?“RL’s Razor” is the idea that among many high-reward solutions, on-policy RL tends to favor policies that stay closer to the original model in KL divergence. This KL bias helps reduce forgetting and improves retention of earlier skills.
What is pretraining-gradient regularization?It is an added term in the RLHF objective that rewards the model for maintaining likelihood on pretraining-style text. This helps preserve general language modeling ability and reduce regressions on broad text tasks.
What is margin-based regularization in reward-model training?Margin-based regularization adds a margin term to the preference loss so the model not only ranks preferred outputs above rejected ones, but does so by a desired gap. This is used in approaches like Llama 2’s margin loss and related reward-aware preference methods.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Reinforcement Learning from Human Feedback ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Reinforcement Learning from Human Feedback ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Reinforcement Learning from Human Feedback ebook for free