Lecture 10: Regularization Tools and The Mechanics of SFT vs. RL

rlhfbook.com

Nathan Lambert

Course on RLHF and post-training. Chapter 15.

How much should we let the model change to earn more reward?

Recall Lecture 9: the x-axis was KL

Last lecture's over-optimization curves: the proxy reward keeps climbing while the gold reward peaks and falls. The x-axis -- KL distance from the initial policy -- is the quantity this lecture is about controlling. Gao et al., 2023.
Last lecture’s over-optimization curves: the proxy reward keeps climbing while the gold reward peaks and falls. The x-axis – KL distance from the initial policy – is the quantity this lecture is about controlling. Gao et al., 2023.

This lecture

Over-optimization is unavoidable – regularization is how we keep it under control.

The spine of this lecture: in RL post-training, nearly every objective points the KL in the same direction.

The plan
  1. The explicit KL penalty -- the workhorse, and how to measure it
  2. Implicit regularization -- why RL forgets less than SFT
  3. Other tools -- pretraining gradients, NLL terms, reward margins

What “off the rails” looks like

Without regularization, strong optimizers push language models into:

  • Fluent-looking reasoning with extremely incorrect answers
  • Repeated text and excessive special characters
  • Language switching mid-generation – recall Lecture 5: R1-Zero mixed languages while reasoning, and labs added language-consistency rewards to stop it

Regularization is the difference between healthy RL training and these failure modes.

Part 1: The explicit KL penalty

The workhorse: a KL penalty to the reference

r = r_\theta - \lambda_{\text{KL}} \, D_{\mathrm{KL}}\!\left( \pi_{\text{RL}}(y \mid x) \,\|\, \pi_{\text{ref}}(y \mid x) \right)
  • KL control predates LLMs: dialogue agents (Jaques et al., 2017), then fine-tuning pretrained models (Jaques et al., 2020). Lecture 3 covered the per-token mechanics (\tilde{r}_t = -\beta\,\text{KL}_t).
  • Note the direction: this penalty is a reverse KL – estimated by sampling from the policy and scoring against the reference. It punishes the policy for putting mass where the reference would not.
  • “KL distance” is the optimization distance spent (colloquially – KL is not a true metric). The x-axis of the over-optimization curves is this quantity.

Measuring KL in practice

Sampling from P turns the definition into an expectation:

D_{\mathrm{KL}}(P \,\|\, Q) = \mathbb{E}_{x \sim P}\left[ \log P(x) - \log Q(x) \right]
  • Practitioners watch the KL curve during training – a very large KL usually means a bug or a broken model.
  • Lower-variance estimators (k_1, k_2, k_3) came up in Q&A 2 (Schulman, 2020).
# sample from the policy
tokens = model.generate(inputs)

# score sampled tokens under both models
logprobs     = log_softmax(model.forward(tokens).logits)
ref_logprobs = log_softmax(ref_model.forward(tokens).logits)

# log-probs of the tokens actually generated
token_lp     = gather(logprobs, tokens)
ref_token_lp = gather(ref_logprobs, tokens)

# sequence-level difference approximates KL
kl_approx = token_lp.sum(-1) - ref_token_lp.sum(-1)

Part 2: Implicit regularization

Even with no penalty: “SFT memorizes, RL generalizes”

Controlled study: post-train on one task, evaluate under a rule shift (Chu et al., 2025).

  • GeneralPoints: reach 24 from four cards; shift the face-card rule (train: J/Q/K = 10; test: 11/12/13).
  • V-IRL: visual navigation; shift from absolute (north/east) to relative (left/right) directions.

On V-IRL, RL improves out-of-distribution accuracy 80.8% → 91.8%. SFT collapses it 80.8% → 1.3% – destroying spatial reasoning the base model already had.

RL-based post-training carries implicit regularization from its on-policy structure alone.

SFT and RL are the two directions of KL

Recall the frame from Lecture 7 (on-policy distillation):

Forward KL – supervised fine-tuning:

D_{\mathrm{KL}}(\pi_\star \,\|\, \pi_\theta) = \mathbb{E}_{y \sim \pi_\star}\!\left[\log \tfrac{\pi_\star(y)}{\pi_\theta(y)}\right]

Samples come from the target (a fixed dataset). Mass-covering: wherever the target has mass and \pi_\theta \to 0, the loss blows up – the model must spread to cover everything.

Reverse KL – reinforcement learning:

D_{\mathrm{KL}}(\pi_\theta \,\|\, \pi_\star) = \mathbb{E}_{y \sim \pi_\theta}\!\left[\log \tfrac{\pi_\theta(y)}{\pi_\star(y)}\right]

Samples come from the policy itself. Mode-seeking: only penalized where it places mass, so it concentrates on high-reward modes.

Chapter 12 promised the why reverse KL is better in chapter 15 – here it is.

SFT is forward KL

\begin{aligned} D_{\mathrm{KL}}(\pi_\star \,\|\, \pi_\theta) &= \mathbb{E}_{(x,y) \sim \mathcal{D}} \left[ \log \pi_\star(y \mid x) - \log \pi_\theta(y \mid x) \right] && \text{definition; samples are the data} \end{aligned}
\begin{aligned} &= \underbrace{\mathbb{E}_{(x,y) \sim \mathcal{D}}\left[ \log \pi_\star(y \mid x) \right]}_{-H(\pi_\star),\ \text{constant in } \theta} \; - \; \mathbb{E}_{(x,y) \sim \mathcal{D}}\left[ \log \pi_\theta(y \mid x) \right] && \text{split the expectation} \end{aligned}
\begin{aligned} &= -H(\pi_\star) + \mathcal{L}_{\text{SFT}}(\theta) \;\propto\; \boxed{\ \mathcal{L}_{\text{SFT}}(\theta)\ } && \text{the NLL term is the SFT loss} \end{aligned}

Same gradients, same minimum: minimizing the SFT loss is minimizing forward KL to the data distribution.

RL is reverse KL

Start from the KL-regularized objective (the one our RL trainers optimize):

\max_\pi\; \mathcal{J}_{\text{RL}}(\theta) = \mathbb{E}_{x \sim \mathcal{D},\, y \sim \pi(\cdot \mid x)}\left[ r(x, y) \right] - \beta\, D_{\mathrm{KL}}\!\left(\pi(\cdot \mid x) \,\|\, \pi_{\text{ref}}(\cdot \mid x)\right)

Dividing by -\beta and normalizing the reward-tilted reference with Z(x) turns the objective into a single KL – minimized exactly when \pi equals the tilted distribution. Lecture 6 walked this same path to the optimal policy (the starting point of DPO):

\pi_\star(y \mid x) = \frac{1}{Z(x)}\, \pi_{\text{ref}}(y \mid x)\, \exp\!\left(\tfrac{1}{\beta}\, r(x,y)\right)

RL is reverse KL

Now expand the reverse KL to \pi_\star, substituting \log \pi_\star = \log \pi_{\text{ref}} - \log Z(x) + \tfrac{1}{\beta} r(x,y):

\begin{aligned} D_{\mathrm{KL}}(\pi_\theta \,\|\, \pi_\star) &= \mathbb{E}_{x \sim \mathcal{D},\, y \sim \pi_\theta}\left[ \log \pi_\theta(y \mid x) - \log \pi_\star(y \mid x) \right] && \text{definition; samples from } \pi_\theta \\ &= \mathbb{E}_{x \sim \mathcal{D},\, y \sim \pi_\theta}\left[ \log \pi_\theta - \log \pi_{\text{ref}} + \log Z(x) - \tfrac{1}{\beta}\, r(x,y) \right] && \text{substitute } \log \pi_\star \\ &= -\tfrac{1}{\beta}\,\mathbb{E}\left[r(x,y)\right] + D_{\mathrm{KL}}\!\left(\pi_\theta \,\|\, \pi_{\text{ref}}\right) + \underbrace{\log Z(x)}_{\text{constant}} && \text{regroup the terms} \\ &\propto -\tfrac{1}{\beta}\, \mathcal{J}_{\text{RL}}(\theta) && \text{drop the constant} \end{aligned}
\boxed{\ \max_\theta\, \mathcal{J}_{\text{RL}}(\theta) \iff \min_\theta\, D_{\mathrm{KL}}(\pi_\theta \,\|\, \pi_\star)\ }

SFT minimizes forward KL to the data; RL minimizes reverse KL to the reward-tilted reference.

Which direction should forget less?

The naive read: forward KL is mass-covering, so SFT should preserve every mode – while mode-seeking RL should collapse onto one and forget the rest.

Sequential fine-tuning experiments say otherwise.

Which direction should forget less?

The opposite holds. That intuition assumes a unimodal policy – LLMs are multimodal.

Forward KL (SFT) stretches the policy to cover the target, dragging probability mass off the "old" mode. Reverse KL (RL) shifts a new mode toward the target and leaves the old one alone. Chen et al., 2025 (with permission).
Forward KL (SFT) stretches the policy to cover the target, dragging probability mass off the “old” mode. Reverse KL (RL) shifts a new mode toward the target and leaves the old one alone. Chen et al., 2025 (with permission).

RL’s razor

“Among the many high-reward solutions for a new task, on-policy methods such as RL are inherently biased toward solutions that remain closer to the original policy in KL divergence.” (Shenfeld et al., 2026)

  • Forgetting tracks KL drift: \text{Forgetting} \approx f\!\left(\mathbb{E}_{x \sim \tau}\!\left[D_{\mathrm{KL}}\!\left(\pi_0 \,\|\, \pi\right)\right]\right) with R^2 = 0.96 – measured on the new task’s data. A cheap forgetting predictor.
  • The ablation: on-policy data fully accounts for the difference – negative gradients have no discernible effect.
Among policies that solve the new task, RL converges to those closest in KL to the base model -- yielding higher prior-task retention at matched new-task performance. Shenfeld et al., 2026 (CC-BY).
Among policies that solve the new task, RL converges to those closest in KL to the base model – yielding higher prior-task retention at matched new-task performance. Shenfeld et al., 2026 (CC-BY).

Part 3: Other regularization tools

Other regularization in the wild

  • Pretraining gradients (InstructGPT): add \gamma\, \mathbb{E}_{x \sim \mathcal{D}_{\text{pretrain}}}\left[\log \pi_{\text{RL}}(x)\right] to the objective, “to fix the performance regressions on public NLP datasets” (Ouyang et al., 2022).
  • NLL alongside DPO: \mathcal{L}_{\text{DPO+NLL}} = \mathcal{L}_{\text{DPO}} + \alpha\, \mathcal{L}_{\text{NLL}} keeps the chosen text high-likelihood in absolute terms, not just relatively better (Pang et al., 2024).
  • Margin loss for reward models (Llama 2): -\log \sigma\!\left(r_{\theta}(y_c) - r_{\theta}(y_r) - m(y_c, y_r)\right), where the margin m comes from annotator rating deltas – the Likert scales from Lecture 8 (Touvron et al., 2023).

Most of these are scaffolding: added to stabilize one setup, simplified away in the next model generation.

Recap: keeping the policy close

Every RL-side objective in this lecture points the KL the same way: sampled from the model, scored against a target.

Three kinds of control
  1. Explicit -- the reverse-KL penalty to the reference (the workhorse)
  2. Implicit -- on-policy sampling alone biases RL toward KL-minimal solutions
  3. Auxiliary -- pretraining gradients, NLL terms, reward margins

Takeaways

  • The KL penalty is the explicit control: a reverse KL, estimated on the policy’s own samples. Watch the KL curve during training.
  • Even with no penalty, on-policy RL is implicitly regularized – SFT memorizes, RL generalizes.
  • Forgetting tracks KL drift (RL’s razor), and on-policy data – not negative gradients – is why RL forgets less.
  • Most other regularizers are scaffolding: they stabilize one setup and disappear in the next generation.

Where to go deeper

Regularization is where RLHF practice earns its stability – these are the references people reach for when debugging real runs.

Go deeper

The course so far

  1. Prerequisites review
  2. Overview (ch. 1-3)
  3. IFT, Reward Models & Rejection Sampling (ch. 4, 5, 9)
  4. RL: Motivation & Math (ch. 6)
  5. RL: Implementation & Practice (ch. 6)
  6. The Rise of Reasoning Models (ch. 7)
  7. Direct Preference Optimization (ch. 8)
  8. Synthetic Data & Modern Post-training (ch. 12)
  9. Preferences & Preference Data (ch. 10-11)
  10. Over-Optimization & RLHF’s Bad Reputation (ch. 14, app. B)
  11. Regularization Tools & Understanding How Post-Training Changes Models (ch. 15)today
  12. Evaluation (ch. 16)next (tentative)

Thank you

Questions / discussion

Contact: [email protected]

Newsletter: interconnects.ai

rlhfbook.com

References (1/2)

Chen, H., Razin, N., Narasimhan, K., and Chen, D.. “Retaining by Doing: The Role of On-Policy Data in Mitigating Forgetting.” 2025. [link]
Chu, T., Zhai, Y., Yang, J., Tong, S., Xie, S., et al.. “Sft memorizes, rl generalizes: A comparative study of foundation model post-training.” International Conference on Machine Learning (ICML), 2025.
Gao, L., Schulman, J., and Hilton, J.. “Scaling laws for reward model overoptimization.” International Conference on Machine Learning, 2023.
Jaques, N., Gu, S., Bahdanau, D., Hern\''andez-Lobato, J., Turner, R., et al.. “Sequence tutor: Conservative fine-tuning of sequence generation models with kl-control.” International Conference on Machine Learning, 2017.
Jaques, N., Shen, J., Ghandeharioun, A., Ferguson, C., Lapedriza, A., et al.. “Human-centric dialog training via offline reinforcement learning.” Conference on Empirical Methods in Natural Language Processing (EMNLP), 2020.
Ouyang, L., Wu, J., Jiang, X., Almeida, D., Wainwright, C., et al.. “Training language models to follow instructions with human feedback.” Advances in Neural Information Processing Systems, 2022.
Pang, R., Yuan, W., Cho, K., He, H., Sukhbaatar, S., et al.. “Iterative reasoning preference optimization.” Advances in Neural Information Processing Systems (NeurIPS), 2024.
Schulman, J.. “Approximating KL Divergence.” 2020.

References (2/2)

Shenfeld, I., Pari, J., and Agrawal, P.. “RL's Razor: Why Online Reinforcement Learning Forgets Less.” The Fourteenth International Conference on Learning Representations, 2026. [link]
Touvron, H., Martin, L., Stone, K., Albert, P., Almahairi, A., et al.. “Llama 2: Open foundation and fine-tuned chat models.” arXiv preprint arXiv:2307.09288, 2023.