A distilled student learns from a larger teacher, and the loss that compares them has two directions. Which one you pick decides what the student gets wrong. This article derives the difference, runs it on a toy you can read in one sitting, and then follows a failure that a recent paper traced to a single missing stop token.
Why train on the student's own samples
Hinton, Vinyals and Dean (2015) describe transferring what an ensemble knows into one smaller model that is easier to serve. Agarwal et al. describe the standard recipe as training the student on a fixed set of output sequences. At inference the student writes its own sequences, and they can differ from the ones it trained on.
On-policy distillation changes where the training text comes from. Agarwal et al. (ICLR 2024) train the student on sequences the student generates, with the teacher giving feedback on those sequences, and allow different divergences between the two models. Gu et al. (MiniLLM, ICLR 2024) use the reverse direction of the KL divergence and argue that it keeps the student from overestimating regions where the teacher puts little probability. We read both papers' abstracts on October 16, 2026, not their full texts.
Two directions of one number
KL divergence measures how far a model q is from a reference p. It is not symmetric. Write p for the teacher and q for the student, both over the same set of outputs.
- Forward KL, the classic distillation loss: KL(p ‖ q) = Σ p(y) log( p(y) / q(y) ). The sum is weighted by the teacher. Wherever the teacher puts probability, the student must too, or the term blows up.
- Reverse KL: KL(q ‖ p) = Σ q(y) log( q(y) / p(y) ). The sum is weighted by the student. The student pays only where it puts probability, so it can ignore a region the teacher likes and pay nothing.
Reverse KL is also what you can estimate from the student's own samples: draw y from q, and the average of log q(y) − log p(y) is the reverse KL. That is why it pairs with on-policy training. Forward KL needs samples from the teacher, or a sum over every possible output.
In the figure you can move the student's mean and width and read both KL values at once. Make a prediction first, then check which direction centers the student between the two peaks.
A teacher assigns probability to two clusters. Your student can make only one peak. Move its mean and width, predict which loss will span both clusters, then compare the best fits.
Synthetic distributions on the 40 integer points from 1 to 40; these are not measurements of a trained language model.
weights forward KL. weights reverse KL. Natural logarithms give loss in nats.
The student has q(x) = exp(−(x − μ)² / (2σ²)) / Z, where Z is the sum of these exponentials over all 40 points. moves its center; changes its spread. Here μ and σ are Gaussian parameters before truncation and normalization; they need not equal the final discrete mean and standard deviation.
The fixed teacher has equal Gaussian peaks at 12 and 29, each with width 2, normalized on the same 40 points.
Probability per point, linear scale: 0 to 0.125.
Integer point x (1 to 40).
Solid blue: teacher p. Dashed orange: student q. Teacher probabilities are fixed; moving μ or σ changes q. The vertical scale adapts to the higher peak.
Your student: μ = 20.5, σ = 9.75. Forward KL(p || q) = 0.751076 nats; reverse KL(q || p) = 2.05563 nats. At point 20: teacher p = 0.0000374535, student q = 0.0425728.
Choose a prediction before checking or comparing the fitted students.
Inspect all 40 probability values
| Point x | Teacher p(x) | Student q(x) |
|---|---|---|
| 1 | 2.69244e-8 | 0.00576918 |
| 2 | 3.7168e-7 | 0.00704556 |
| 3 | 0.00000399594 | 0.0085143 |
| 4 | 0.0000334576 | 0.0101815 |
| 5 | 0.000218171 | 0.0120479 |
| 6 | 0.00110796 | 0.0141071 |
| 7 | 0.00438208 | 0.0163455 |
| 8 | 0.0134977 | 0.0187408 |
| 9 | 0.0323794 | 0.0212623 |
| 10 | 0.0604927 | 0.0238706 |
| 11 | 0.0880163 | 0.0265185 |
| 12 | 0.0997356 | 0.0291518 |
| 13 | 0.0880163 | 0.0317113 |
| 14 | 0.0604927 | 0.0341345 |
| 15 | 0.0323794 | 0.0363584 |
| 16 | 0.0134977 | 0.0383219 |
| 17 | 0.00438208 | 0.0399688 |
| 18 | 0.00110799 | 0.0412502 |
| 19 | 0.000218542 | 0.0421273 |
| 20 | 0.0000374535 | 0.0425728 |
| 21 | 0.0000374535 | 0.0425728 |
| 22 | 0.000218542 | 0.0421273 |
| 23 | 0.00110799 | 0.0412502 |
| 24 | 0.00438208 | 0.0399688 |
| 25 | 0.0134977 | 0.0383219 |
| 26 | 0.0323794 | 0.0363584 |
| 27 | 0.0604927 | 0.0341345 |
| 28 | 0.0880163 | 0.0317113 |
| 29 | 0.0997356 | 0.0291518 |
| 30 | 0.0880163 | 0.0265185 |
| 31 | 0.0604927 | 0.0238706 |
| 32 | 0.0323794 | 0.0212623 |
| 33 | 0.0134977 | 0.0187408 |
| 34 | 0.00438208 | 0.0163455 |
| 35 | 0.00110796 | 0.0141071 |
| 36 | 0.000218171 | 0.0120479 |
| 37 | 0.0000334576 | 0.0101815 |
| 38 | 0.00000399594 | 0.0085143 |
| 39 | 3.7168e-7 | 0.00704556 |
| 40 | 2.69244e-8 | 0.00576918 |
These are discrete, normalized, one-peak students, not a claim about every distillation run. Best fits search μ from 1 to 40 and σ from 0.5 to 20, both in steps of 0.25. A tie within 1e−12 keeps the earlier grid point, so reverse KL selects the left peak. No optimizer or training runs in your browser.
Very narrow students can round tiny probabilities to zero in floating-point arithmetic. An infinite forward KL here marks that numerical loss of support; the ideal Gaussian has positive mass at every point. The separate stop-token example in the article is outside this view.
Ask who weights the sum: the teacher or the student.
Check the prediction
Forward KL covers, reverse KL commits
Forward KL is weighted by the teacher, so it punishes the student for any teacher mass it misses. A single wide peak that spans both of the teacher's peaks avoids that, at the price of mass in the valley between them. Reverse KL is weighted by the student, so a student that sits on one peak pays nothing for ignoring the other, and it does better than a wide peak that pays for the valley.
Run it
The toy has a teacher over the points 1 to 40 with two peaks, at 12 and 29, each carrying half the mass. The student is a single peak with a mean and a width, and the script searches a grid for the best fit under each direction. The second part is a single position in a response where the model can continue or stop, and it comes up below.
Save this as opd_demo.py:
import math
def softmax(z):
m = max(z)
e = [math.exp(v - m) for v in z]
return [v / sum(e) for v in e]
def kl(p, q): # KL(p || q) in nats
if any(a > 0 and b == 0 for a, b in zip(p, q)):
return math.inf # q rules out something p allows
return sum(a * math.log(a / b) for a, b in zip(p, q) if a > 0)
# Part 1. A one-peak student fits a two-peak teacher on points 1..40.
xs = range(1, 41)
teacher = [0.5 * math.exp(-(x - 12) ** 2 / 8) + 0.5 * math.exp(-(x - 29) ** 2 / 8) for x in xs]
teacher = [v / sum(teacher) for v in teacher]
def student(mu, sigma):
return softmax([-(x - mu) ** 2 / (2 * sigma ** 2) for x in xs])
def best_fit(direction):
best = (math.inf, 0, 0)
for mu in [i / 4 for i in range(4, 161)]:
for sigma in [i / 4 for i in range(2, 81)]:
q = student(mu, sigma)
v = kl(teacher, q) if direction == "forward" else kl(q, teacher)
if v < best[0] - 1e-12:
best = (v, mu, sigma)
return best
for name in ("forward", "reverse"):
v, mu, sigma = best_fit(name)
q = student(mu, sigma)
print(f"{name}: mean {mu}, width {sigma}, KL {v:.4f}, student mass at 20 = {q[19]:.4f}")
print(f"teacher mass at point 20 = {teacher[19]:.6f}")
# Part 2. One stopping state. Actions: continue, the student's own stop token, the teacher's stop token.
teacher_p = [0.80, 0.0005, 0.1995]
def step(logits, shared, lr=0.5):
q = softmax(logits)
groups = [[0], [1, 2]] if shared else [[0], [1], [2]]
t = [sum(teacher_p[i] for i in g) for g in groups]
s = [sum(q[i] for i in g) for g in groups]
adv = [math.log(a / b) for a, b in zip(t, s)] # log teacher - log student
grad = [0.0] * 3
for g, sg, ad in zip(groups, s, adv):
for j in range(3):
d = (q[j] / sg if j in g else 0.0) - q[j] # d log s / d logit_j
grad[j] += sg * ad * d
return [l + lr * x for l, x in zip(logits, grad)]
for shared in (False, True):
logits = [math.log(0.6), math.log(0.4 - 1e-6), math.log(1e-6)]
for _ in range(2000):
logits = step(logits, shared)
q = softmax(logits)
stop = q[1] + q[2]
label = "one shared stop action" if shared else "two separate stop tokens"
print(f"{label}: stop probability {stop:.6f}, expected length {1 / stop:.1f}")Run python3 opd_demo.py. The output was identical on Python 3.14.6 and 3.9.6:
forward: mean 20.5, width 9.75, KL 0.7511, student mass at 20 = 0.0426
reverse: mean 12.0, width 2.0, KL 0.6931, student mass at 20 = 0.0001
teacher mass at point 20 = 0.000037
two separate stop tokens: stop probability 0.000758, expected length 1318.6
one shared stop action: stop probability 0.200000, expected length 5.0The forward fit lands at mean 20.5, the teacher's own mean, with a wide peak. It puts 0.0426 of its probability on point 20, in the valley, where the teacher has 0.000037. The reverse fit lands on the peak at 12 with width 2, and its KL is 0.6931, approximately log 2: the student concentrates on one teacher peak, with very little probability near the other. The two Gaussian components overlap, so the fit does not cover exactly half the teacher or assign zero mass to the other peak. Neither student is the teacher, and neither direction is better in general. Forward KL gives a student that covers everything and is sometimes wrong in the gaps. Reverse KL gives a student that is sharp where it commits and silent elsewhere.

graph TD
A[Student writes a response] --> B[Teacher scores each token the student chose]
B --> C[Advantage: log teacher minus log student]
C --> D[Raise tokens the teacher likes more than the student does]
D --> A
E[Fixed dataset or teacher text] --> F[Forward KL: teacher-weighted]
F --> G[Student covers the teacher, gaps included]
The per-token version and its blind spot
In the on-policy setting each token the student writes gets an advantage: the log of the teacher's probability for that token minus the log of the student's. A token the teacher likes more than the student does is pushed up, and a token the teacher likes less is pushed down. Yang et al. (arXiv 2609.20511, September 17, 2026) use this sampled-token form, with the advantage held fixed during the update and no sum over later tokens. Averaged over the student's own samples, it estimates the reverse KL at each position. The paper's appendix notes that this local update leaves out a term that the reverse KL over whole responses would include.
The blind spot is in the phrase "the token the student chose." The teacher scores only that token. If the student chose a token the teacher almost never uses, the teacher's score is very low, and the student is pushed away from it, even if the teacher uses a different token to mean the same thing.
Stop tokens are that case. The paper's setup has a Qwen3-1.7B base model as the student and a Qwen3-4B post-trained model as the teacher. The base model declares <|endoftext|> as its stop token. The post-trained model also recognizes <|im_end|>, and that is the one it prefers. The student's probability on the teacher's preferred token is about 10⁻¹¹ near the end of a response, so it is almost never sampled and gets almost no direct feedback. What the student does sample is its own stop token, which the teacher scores low, so every time the student tries to stop it is pushed down. The paper reports the student's probability on its native stop token falling from about 0.8 early in training to near zero, while response length and the share of responses cut off at the length limit both rise.
The paper checks the obvious repair first: register both tokens as stop tokens when decoding. That follows nearly the same length and cut-off trajectory as no repair. The repair that works treats the model's stop tokens as one action whose probability is their sum, and scores that action. The same effect appears in Llama 3.2 and Gemma 3. On Gemma 3 the student and teacher declare the same stop set and still prefer different tokens within it.
What the toy shows, and what it does not
Part 2 of the script is one position in a response with three actions: continue, the student's stop token, and the teacher's stop token. The teacher continues 80% of the time and stops 20% of the time, almost always with its own token. The student starts with 0.4 on its own stop token and 10⁻⁶ on the teacher's. After 2,000 expected-gradient updates (the script sums over the three actions, so nothing is sampled), the student that scores the two stop tokens separately stops with probability 0.00076, which is an expected length of 1,319 tokens. That is slow learning, not a fixed value: the student starts with only 10⁻⁶ on the teacher's stop token. The student that scores them as one action stops with probability 0.2 and an expected length of 5.
Two cautions. First, this is an invented single-position model of the mechanism the paper describes, with numbers chosen to show it. It does not reproduce the paper's experiment, and its lengths say nothing about the paper's measured lengths. We did not run the paper's code: it needs several GPUs, and the repository carries no license. Second, the paper itself finds that the fix is not the whole story. In its longer runs a late rise in length remains after the stop tokens are matched, so the authors conclude that termination mismatch is an important source of length growth but not the only one.
Two more papers, briefly
Two further September 2026 papers study on-policy distillation. One (arXiv 2609.32722) reports that held-out accuracy rises roughly linearly with the square root of the student's reverse KL from where it started, within a range it calls a useful-transfer regime, and that in every weak-to-strong pair it saw the student's best score exceeded its teacher's. The other (arXiv 2609.35259) varies the rollout policy and the KL direction across Llama 3 and Qwen2.5 models and finds that the rollout policy "does not necessarily play a central role," with forward KL robust to it and reverse KL more sensitive. We read only their abstracts, so we report their claims and leave their evidence unchecked.
What to take from it
Reverse KL commits to a region and forward KL covers a region, and a student with less capacity than its teacher has to choose. Reading a distillation run means asking what the loss scores: the full distribution or only the token that was sampled. If the teacher and the student have different stop tokens, check the length curve and the stop probability before you trust the loss.
For a related exercise in checking what a signal rewards, see how to build an RL environment with a verifier in Python.
Once you can read what a post-training loss scores, run one end to end on a single small GPU.

