TL;DR
Computing the exact Kullback–Leibler (KL) divergence between language models is mathematically intractable, forcing practitioners to rely on noisy, high-variance Monte Carlo estimators that can destabilize training. This paper introduces a Rao–Blackwellized estimator that analytically integrates out token-level sampling noise, provably reducing variance and ensuring non-negative KL estimates with zero computational overhead.
What Problem Does This Paper Address?
In modern language modeling, the KL divergence is everywhere. It is the core regularization metric in Reinforcement Learning from Human Feedback (RLHF) used to stop a model from drifting too far from its safe reference policy, and it is widely used in knowledge distillation and interpretability research.
However, because the set of all possible text strings is countably infinite, computing the exact KL divergence between two arbitrary language models is impossible in finite time (and mathematically undecidable). Instead, researchers use standard Monte Carlo (MC) sampling. The problem? MC estimation suffers from notoriously high variance. Even worse, it can produce negative KL estimates—a mathematical impossibility for the true metric—which severely destabilizes RLHF training loops. Existing fixes, like Schulman’s popular control variate method, often introduce massive variance spikes if they aren't perfectly calibrated.
Methods
The authors turn to a classic statistical technique: Rao–Blackwellization.
Instead of generating a full text string and evaluating its probability post-hoc (the standard Monte Carlo approach), the proposed Rao–Blackwellized (RB) estimator calculates the exact expected KL divergence at each token position across the entire vocabulary distribution, conditioned on the previously sampled prefix.
Essentially, instead of letting a random sample choose a single token at step $n$, the method looks at the model's complete probability distribution over the vocabulary for that step and calculates the step-wise KL analytically. They extend this mathematical framework to derive an RB estimator for the gradient of the KL divergence, supporting both on-policy and off-policy RLHF training.
Crucially, because a standard model forward pass already computes the full vocabulary distribution at each step, implementing this exact expectation adds zero additional computational overhead.
Datasets
The authors evaluated their estimators on two primary setups:
- IMDB Movie Reviews Dataset: Used for a sentiment-controlled generation task. A base GPT-2 model was fine-tuned using Direct Preference Optimization (DPO) and RLHF to steer it toward generating positive movie reviews.
- UltraFeedback Dataset: Used to scale up the evaluation to larger models, measuring the KL divergence between Zephyr-7B-Beta and its reference base model, Mistral-7B-v0.1.
Key Insights and Ideas
- Analytical beats Sampling: Sampling a specific token introduces unnecessary noise when the model already gives you the exact probability distribution over the entire vocabulary at each step. Capitalizing on this internal distribution eliminates token-level sampling noise entirely.
- Guaranteed Non-negativity: Because the RB estimator sums true local KL divergences (which are mathematically non-negative), the final estimate is guaranteed to never drop below zero, removing a major source of RLHF training instability.
- The Flaw in Fixed Control Variates: The paper demonstrates that Schulman’s control variate method with a fixed calibration ($\alpha = 1$) can lead to unbounded variance for neutral or adversarial prompts, making it highly unstable across different prompts.
Key Results
The Rao–Blackwellized estimator consistently outperformed all traditional methods in stability and variance reduction.
Variance Reduction
As shown in the experimental data, the RB estimator achieves the lowest empirical standard deviation across all sample sizes ($M=1, 5, 10$) without introducing any bias.
When analyzing the standard deviations across all prompts in the IMDB dataset, the RB estimator consistently demonstrated a tighter, more stable distribution with far fewer extreme outliers than alternative methods.
RLHF Training Stability
- Incorporating the RB gradient estimator into the RLHF training loop reduced the variance of the gradient norm by 24.6%.
- Models optimized with the RB gradient estimator were significantly more stable across different runs and landed on the optimal Pareto frontier (balancing high reward vs. low KL drift) 78% of the time compared to those trained via standard Monte Carlo.
Limitations and Future Work
The primary limitation acknowledged by the authors is computational scale. Evaluating the variance of these estimators and running multiple training seeds required training 36 separate models for their statistical significance tests. Due to these resource constraints, their RLHF training experiments were limited to smaller architectures (GPT-2 and Zephyr-7B).
The authors note that future work should focus on deploying the Rao–Blackwellized estimator within larger state-of-the-art LLM alignment pipelines and exploring its compatibility with a broader range of RL-based optimization algorithms.
Summary updated