- Key idea
- Forward and reverse KL, total variation, Jensen–Shannon, Hellinger, χ², the f-divergence family, and Pinsker's inequality
- Real world
- Two maps of the same city can be compared in many ways: the largest single disagreement, the average disagreement, or how lost you'd get using one when the other is correct. Each answers a different question, and they rank maps differently.
- In an LLM
- A small student model learns from a large teacher. Training on the teacher's samples minimises forward KL and makes the student spread its bets. Training on the student's own samples, graded by the teacher, minimises reverse KL and makes it commit. Same teacher, different students.
Why more than one
KL divergence measures the extra surprise from predicting with when reality follows . It's not symmetric, and it can be infinite. Other measures fix those properties, and some show up directly in LLM methods:
| Divergence | Range | Symmetric? | Where you meet it |
|---|---|---|---|
| Forward KL | 0 to ∞ | no | Maximum likelihood, SFT, cross-entropy training |
| Reverse KL | 0 to ∞ | no | RLHF's KL penalty, on-policy distillation, variational inference |
| Total variation (TV) | 0 to 1 | yes | Speculative decoding acceptance rate, theory bounds |
| Jensen–Shannon (JS) | 0 to log 2 | yes | GANs; generalised JSD in GKD |
| Hellinger | 0 to 1 | yes | Statistical theory; robust to tiny probabilities |
| χ² | 0 to ∞ | no | Variance of importance weights |
Forward versus reverse KL
The two directions of KL weight mistakes differently (KL divergence has the interactive version):
- Forward, , averages over what does. If does something and gives it almost no probability, the penalty is huge. Minimising it makes cover everything does, even at the cost of putting probability on things never does. Called mass-covering or mean-seeking.
- Reverse, , averages over what does. is only penalised for going where doesn't. Minimising it makes pick one thing does and do it well, ignoring the rest. Called mode-seeking.
You don't know whether it'll be hot or cold. A forward-KL packer brings clothes for both and some in-between layers nobody needs. A reverse-KL packer bets on one climate and packs perfectly for it, and has nothing if they're wrong.
Supervised distillation trains the student on text the teacher wrote: cross-entropy on teacher samples, which is forward KL. Students spread out, and can produce odd mixtures of the teacher's styles. On-policy distillation (MiniLLM, GKD) lets the student write and the teacher grade each token, which is reverse KL. Students commit to the teacher's main modes and stay on their own distribution, which helps on long generations.
Bounded divergences
KL can be infinite: if gives zero probability to something does, . That makes it brittle when probabilities are tiny. Bounded alternatives:
- Total variation: half the summed absolute difference in probabilities. The largest amount by which and can disagree on the probability of any event. In speculative decoding, the draft acceptance rate is exactly .
- Jensen–Shannon: the average KL from each to their 50/50 mixture. Always finite, symmetric, and at most .
Pinsker's inequality connects them: . A small KL guarantees a small TV. That's how papers turn "the policy stayed within KL budget ε" into "no event's probability changed by more than ."
Try it
A forecaster who says "0% chance of snow" and is then wrong once has, by log-loss, an infinitely bad record, a forward-KL penalty. Judged by how far their percentages were off on average (a TV-like measure), one miss costs a bounded amount. The scoring rule decides whether forecasters can ever afford to say "never".
Language models never assign a token exactly zero probability: softmax can't. That's partly why forward-KL training is stable at all. But truncated sampling (top-p, top-k) does create exact zeros, so a trainer that computes KL to a truncated sampler's distribution can hit infinities. Clipping log-ratios or masking such tokens is the practical fix.
Where this shows up
- Distillation: forward KL (SFT on teacher data), reverse KL (on-policy), and mixtures: distillation.
- RLHF: the KL penalty is reverse KL from the reference, which is why the optimum is a tilted distribution.
- Speculative decoding speed is : rejection sampling.
- Importance-sampling variance is a χ² divergence: importance sampling in depth.
f-divergences
For a convex with :
| Divergence | |
|---|---|
| total variation | |
| squared Hellinger |
The widget's Hellinger row uses .
Jensen–Shannon and GKD
GKD uses a generalised JSD with mixture , which interpolates between forward KL () and reverse KL (), up to scaling.
Pinsker
and the same holds with the KL reversed.
Distillation objectives
With teacher and student :
Papers
- f-GAN: Training Generative Neural Samplers using Variational Divergence Minimization (Nowozin et al., 2016): the f-divergence family in ML
- MiniLLM: On-Policy Distillation of Large Language Models (Gu et al., 2023): reverse KL for distillation
- On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes (Agarwal et al., 2023): GKD, generalised JSD
- Fast Inference from Transformers via Speculative Decoding (Leviathan et al., 2022): acceptance rate and total variation