Divergences beyond KL

KL is one of many ways to measure how different two distributions are. Forward or reverse KL, total variation, Jensen–Shannon, χ²: which one a method minimises decides how its model behaves.

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 QQ when reality follows PP. It's not symmetric, and it can be infinite. Other measures fix those properties, and some show up directly in LLM methods:

DivergenceRangeSymmetric?Where you meet it
Forward KL KL(P∥Q)\mathrm{KL}(P \Vert Q)0 to ∞noMaximum likelihood, SFT, cross-entropy training
Reverse KL KL(Q∥P)\mathrm{KL}(Q \Vert P)0 to ∞noRLHF's KL penalty, on-policy distillation, variational inference
Total variation (TV)0 to 1yesSpeculative decoding acceptance rate, theory bounds
Jensen–Shannon (JS)0 to log 2yesGANs; generalised JSD in GKD
Hellinger0 to 1yesStatistical theory; robust to tiny probabilities
χ²0 to ∞noVariance of importance weights

Forward versus reverse KL

The two directions of KL weight mistakes differently (KL divergence has the interactive version):

  • Forward, KL(P∥Q)\mathrm{KL}(P \| Q), averages over what PP does. If PP does something and QQ gives it almost no probability, the penalty is huge. Minimising it makes QQ cover everything PP does, even at the cost of putting probability on things PP never does. Called mass-covering or mean-seeking.
  • Reverse, KL(Q∥P)\mathrm{KL}(Q \| P), averages over what QQ does. QQ is only penalised for going where PP doesn't. Minimising it makes QQ pick one thing PP does and do it well, ignoring the rest. Called mode-seeking.
example · packing for a trip

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.

example · two ways to distil

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 QQ gives zero probability to something PP does, KL(P∥Q)=∞\mathrm{KL}(P \| Q) = \infty. That makes it brittle when probabilities are tiny. Bounded alternatives:

  • Total variation: half the summed absolute difference in probabilities. The largest amount by which PP and QQ can disagree on the probability of any event. In speculative decoding, the draft acceptance rate is exactly 1−TV1 - \mathrm{TV}.
  • Jensen–Shannon: the average KL from each to their 50/50 mixture. Always finite, symmetric, and at most log⁡2\log 2.

Pinsker's inequality connects them: TV≤KL/2\mathrm{TV} \le \sqrt{\mathrm{KL}/2}. 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 ε/2\sqrt{\varepsilon/2}."

Try it

teacher Pstudent Q
Five ways to measure the gap (bar length: value ÷ the measure’s maximum)
forward KL(P‖Q) unbounded; bar drawn up to 30.079
reverse KL(Q‖P) unbounded; bar drawn up to 30.079
Jensen–Shannon at most log 2 = 0.690.020
total variation at most 10.185
squared Hellinger at most 10.020
Pinsker’s inequality ties them together: total variation ≤ √(KL/2), here 0.185 ≤ 0.199. Now push the student’s P(Lyon) towards 0 and watch the chart: the dot is where you are, and the left end is P(Lyon) = 1e-8.
A teacher P and a student Q over the next word after “The capital of France is”. Move the student away, or make it nearly rule out “Lyon”.
example · a weather forecast that rules things out

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".

example · why models avoid exact zeros

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

going deeper

f-divergences

For a convex ff with f(1)=0f(1) = 0:

Df(P ∥ Q)=∑xQ(x) f(P(x)Q(x))D_f(P \,\|\, Q) = \sum_x Q(x)\, f\Big(\frac{P(x)}{Q(x)}\Big)
f(t)f(t)Divergence
tlog⁡tt \log tKL(P∥Q)\mathrm{KL}(P \Vert Q)
−log⁡t-\log tKL(Q∥P)\mathrm{KL}(Q \Vert P)
12∣t−1∣\tfrac12 \lvert t - 1 \rverttotal variation
(t−1)2(t - 1)^2χ2(P∥Q)\chi^2(P \Vert Q)
(t−1)2(\sqrt t - 1)^22×2 \times squared Hellinger

The widget's Hellinger row uses H2=1−∑xP(x)Q(x)H^2 = 1 - \sum_x \sqrt{P(x) Q(x)}.

Jensen–Shannon and GKD

JS(P,Q)=12KL(P ∥ M)+12KL(Q ∥ M),M=12(P+Q)\mathrm{JS}(P, Q) = \tfrac12 \mathrm{KL}(P \,\|\, M) + \tfrac12 \mathrm{KL}(Q \,\|\, M), \qquad M = \tfrac12 (P + Q)

GKD uses a generalised JSD with mixture M=βP+(1−β)QM = \beta P + (1 - \beta) Q, which interpolates between forward KL (β→0\beta \to 0) and reverse KL (β→1\beta \to 1), up to scaling.

Pinsker

TV(P,Q)=12∑x∣P(x)−Q(x)∣ ≤ 12KL(P ∥ Q)\mathrm{TV}(P, Q) = \tfrac12 \sum_x \lvert P(x) - Q(x) \rvert \ \le\ \sqrt{\tfrac12 \mathrm{KL}(P \,\|\, Q)}

and the same holds with the KL reversed.

Distillation objectives

With teacher pTp_T and student qθq_\theta:

SFT on teacher samples: min⁡θ Ey∼pT[−log⁡qθ(y)] ⇔ min⁡θKL(pT ∥ qθ)on-policy: min⁡θKL(qθ ∥ pT)\text{SFT on teacher samples: } \min_\theta\ \mathbb{E}_{y \sim p_T}\big[-\log q_\theta(y)\big] \ \Leftrightarrow\ \min_\theta \mathrm{KL}(p_T \,\|\, q_\theta) \qquad \text{on-policy: } \min_\theta \mathrm{KL}(q_\theta \,\|\, p_T)

Papers

Related

  • tilting - Reweight a distribution by exp(reward / β) and renormalise. That one operation is the exact solution of KL-regularised RLHF, the starting point of DPO, a Bayesian posterior, and the yardstick for best-of-n.
  • rejection-sampling - Sample from a distribution you can evaluate but not easily draw from, by proposing from an easier one and sometimes saying no. The same idea makes LLM inference 2–3× faster without changing a single output probability.
  • importance-weights - Reweighting samples from one distribution to learn about another. Why it works, how to tell when it's failing (effective sample size), and the fixes LLM training uses for long answers.