LLM + RoboticsModule 12 · Video 05

On-policy distillation: small models learning from their own mistakes

Ordinary distillation trains a small model on text the big model wrote. Then, at test time, the small model has to continue from its own text, which it never practised on. On-policy distillation fixes this mismatch. The student writes, the teacher grades every token of what the student wrote, and the student learns from that dense feedback. This guide follows the video's path from soft targets to exposure bias, reinforcement learning, the KL-direction question and the applications.

Video length30:34
Published15 July 2026
LevelIntermediate: softmax, cross-entropy and the idea of a policy gradient
Builds onModule 04 · Distillation, Module 07 · The KL leash, Module 02 · RL ladder

Video by Jia-Bin Huang · Watch on YouTube

Start here (no maths needed)

A small AI can learn by copying a big AI's answers. But copying perfect answers doesn't teach it what to do after it makes a mistake. In on-policy distillation the small AI writes its own answer, and the big AI marks every word: good, okay or wrong turn. The small AI learns from its own attempts, with detailed marks.

Think of it like this

Learning to ride a bike by watching videos of a champion only shows you a perfect ride. The first time you wobble, you've never seen a wobble before, so you fall. A good coach does something different: you ride, and they jog alongside saying "lean left now", "too fast here", "good". You practise on your wobbles, with tips at every moment. A coach who only says "you fell" at the end is like reinforcement learning: honest, but not much help in knowing what went wrong.

How it works

  1. Start with a small "student" model that already knows the basics, often after first copying the teacher's answers.
  2. The student writes answers to practice questions by itself.
  3. The big "teacher" model reads each answer and says, word by word, how likely it would have been to write that word.
  4. Words the teacher strongly disagrees with get pushed down; words it agrees with get pushed up.
  5. Repeat. The student gets better at exactly the situations it actually gets itself into.

Why robots care

Robots make small mistakes all the time: a gripper slips, a wheel skids. A robot that only ever copied perfect demonstrations doesn't know how to recover, so one small error grows into a big one. Robotics researchers met this problem first, and the fix (let the learner act, and have an expert say what it should have done) is the same idea as on-policy distillation.

Try it

Words to know

Teacher and student
The big model that knows the task, and the small model learning from it.
Soft targets
The teacher's full set of probabilities for every possible next word, not just its top pick.
On-policy
Learning from data the learner itself produced, rather than data someone else produced.
Exposure bias
The gap between training on perfect text and having to continue your own imperfect text at test time.
KL divergence
A measure of how different two probability distributions are. It isn't symmetric, so the order matters.

Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.

1. Watch

Chapter guide

TimeChapterWhat to look for
0:00Why Distillation MattersThe motivation: small models are cheaper, faster and can run locally, but are hard to train to high quality directly.
1:28Soft Targets and Dark KnowledgeHinton-style distillation: matching the teacher's whole softened distribution, and why the small probabilities on wrong answers carry information.
4:11From One Token to Many TokensGoing from one prediction to sequences: token-level distillation (match the teacher at every position) versus sequence-level distillation (train on the teacher's generated outputs).
9:30Exposure BiasWhy training on teacher-written prefixes leaves the student unprepared for its own prefixes, and how errors compound over long outputs.
12:11On-Policy Reinforcement LearningRL trains on the student's own samples (fixing the mismatch), but a single reward per sequence is sparse feedback.
14:08On-Policy DistillationThe combination: student-generated samples, graded densely by the teacher at every token.
16:39Why the KL Direction MattersForward KL (mode-covering) versus reverse KL (mode-seeking), and why the reverse direction suits a small student imitating a big teacher. The demo below shows this.
19:04Applications and Empirical ResultsThe overview of where on-policy distillation has been reported to help.
20:30Application 1: ReasoningDistilling maths reasoning into a smaller model, compared with more supervised fine-tuning or RL, and the compute each needs.
22:43Application 2: PersonalizationTeaching a model new domain knowledge, then using distillation to restore behaviours (like instruction following) that the new training damaged.
24:47Application 3: Data ReuseWhy training many times on the same prompts works better with distillation than with RL, which tends to memorise answers.
25:52On-Policy Self-Distillation for ReasoningVariants where the teacher is the model itself under different conditions. Watch for what gives the "teacher" copy its advantage.
29:15On-Policy Self-Distillation for Continual LearningUsing a model (or an earlier copy of it) as its own teacher so that learning new things doesn't erase old skills.
30:04RecapThe two-by-two picture: who generates the data (teacher or student) and how dense the feedback is.

The video's description doesn't list references. The sources below are the original papers behind each chapter's topic. The three application titles match the sections of Thinking Machines Lab's "On-Policy Distillation" post, which makes it the natural companion reading.

2. The ideas, explained

Soft targets and dark knowledge

Hinton, Vinyals and Dean (2015) trained a small model to match a large model's (or an ensemble's) output probabilities instead of only the hard labels. The teacher's logits z are softened with a temperature T so that small probabilities become visible, and the student is trained on a mix of the soft-target loss and the usual hard-label loss:

p_T(i) = exp(z_i / T) / Σ_j exp(z_j / T)          (teacher, softened)
L = α · T² · KL(p_T^teacher ‖ p_T^student)  +  (1 − α) · CE(y, p_1^student)

The T² factor keeps the soft-target gradients on a similar scale as T changes. The information in the wrong-answer probabilities (an image of a 2 that looks a bit like a 3 and a bit like a 7) is often called dark knowledge. It tells the student how the teacher generalises, which hard labels can't.

From one token to many: token-level and sequence-level distillation

For a language model, the "label" is a whole sequence. Two classic options:

token-level:     L = Σ_t KL( p_teacher(· | y_<t, x) ‖ q_θ(· | y_<t, x) ),   y fixed
sequence-level:  L = − Σ_t log q_θ(ŷ_t | ŷ_<t, x),   ŷ ~ teacher

Supervised fine-tuning on outputs written by a stronger model (as with many open reasoning datasets) is sequence-level distillation. Both forms are off-policy: the prefixes y<t come from the data or the teacher, never from the student.

Exposure bias

At training time the student always conditions on a "good" prefix. At inference it conditions on its own, possibly flawed, prefix. One early slip puts it in a state it never trained on, where it is more likely to slip again. Bengio et al. (2015) proposed scheduled sampling, gradually feeding the model its own predictions during training. The same problem was formalised years earlier in imitation learning by Ross, Gordon and Bagnell (2011): a policy trained only on expert states can see its errors grow quadratically with the horizon T, and their algorithm DAgger fixes this by running the learner's policy, asking the expert to label the states the learner actually visits, and training on the growing dataset. On-policy distillation is DAgger for language models, with the teacher's full distribution as the label.

behaviour cloning:   error can grow like  O(ε · T²)
DAgger (on-policy):  error grows like     O(ε · T)       (Ross et al., 2011)

On-policy reinforcement learning

RL also trains on the student's own samples, so it doesn't suffer exposure bias. The catch is feedback density: a verifier says "correct" or "wrong" once per sequence, so a 2,000-token solution gets one number, with no indication of which step went wrong. Thinking Machines' post puts it as RL teaching O(1) bits per episode, against O(N) bits for distillation, where N is the number of tokens. The policy-gradient machinery (REINFORCE, baselines, PPO, GRPO) is covered in Video 06 and 30u30 Day 29.

On-policy distillation

Agarwal et al. (Google DeepMind, 2023) introduced Generalized Knowledge Distillation (GKD; the arXiv title is "On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes"). The student is trained on its own sampled outputs, with the teacher's token-level distribution as the target, and the divergence can be chosen freely:

GKD:  L(θ) = (1 − λ) · E_{(x,y) ~ data}[ D(p_T ‖ q_θ)(y | x) ]
           +      λ  · E_{x ~ X, y ~ q_θ(·|x)}[ D(p_T ‖ q_θ)(y | x) ]

D(p_T ‖ q_θ)(y|x) = (1/|y|) Σ_t D( p_T(· | y_<t, x) ‖ q_θ(· | y_<t, x) )
D ∈ { forward KL, reverse KL, generalised JSD(β) }

λ is the fraction of student-generated data; λ = 1 is fully on-policy. Gradients aren't taken through the sampling step, which keeps training stable and cheap. The paper reports gains on summarisation, translation and arithmetic reasoning, and shows the same loss can be added to RL fine-tuning. MiniLLM (Gu, Dong, Wei and Huang, 2023) reached a related recipe from the reverse-KL side, deriving an on-policy policy-gradient optimisation of sequence-level reverse KL.

Thinking Machines Lab's post (Kevin Lu and colleagues, October 2025) uses the simplest version: per-token reverse KL on student samples, implemented as RL with the reward set to the negative KL and a discount of zero:

sample y ~ π_θ(· | x)                                   (student rollout)
advantage_t = −( log π_θ(y_t | y_<t, x) − log π_teacher(y_t | y_<t, x) )
update π_θ with the usual importance-sampled policy-gradient loss

Only one teacher forward pass per rollout is needed, rollouts can be partial, and no reward model is required. The post describes it as a small change to an RL loop with a KL penalty: swap the reference model for the teacher.

Why the KL direction matters

forward KL   KL(p ‖ q) = E_{y~p}[ log p(y) − log q(y) ]   samples from the teacher
reverse KL   KL(q ‖ p) = E_{y~q}[ log q(y) − log p(y) ]   samples from the student

Forward KL punishes the student heavily wherever the teacher has mass and the student doesn't, so the student spreads out to cover everything the teacher might do: mode-covering. A small student that can't represent all the teacher's modes ends up putting mass in the gaps between them, which for text means bland or incoherent mixtures. Reverse KL punishes the student wherever it has mass and the teacher doesn't, so it concentrates on what it can do well: mode-seeking. That suits a low-capacity student, and the expectation is over the student's own samples, which is what makes it naturally on-policy. The trade-off is lower diversity; GKD's generalised JSD(β) interpolates between the two. Thinking Machines adds that per-token reverse KL is hard to "hack", since low KL to the teacher means behaviour the teacher itself finds likely.

Interactive: forward vs reverse KL on a two-bump teacher

The teacher (filled) is a mix of two bell curves of width 1. The student can only be a single bell curve. Dashed: the student that minimises forward KL(teacher ‖ student). Solid: the student that minimises reverse KL(student ‖ teacher), found by a grid search over mean and width.

Forward-KL fit (mean, width)
–
Reverse-KL fit (mean, width)
–
Teacher density at forward fit's peak
–
Teacher density at reverse fit's peak
–

Try this: at the defaults (separation 6, left weight 0.6) the forward-KL student has mean −0.6 and width about 3.1, so its peak sits in the valley between the bumps, where the teacher has only about 6% of its peak density. The reverse-KL student locks onto the heavier left bump (mean −3.0, width 1.0), where the teacher is at full density. Drop separation to 2 and the two fits agree (mean −0.2, width 1.4), because the teacher is effectively one bump. "Teacher density" is relative to the teacher's highest point. The forward fit is exact (it matches the teacher's mean and variance); the reverse fit is a grid search, so values are to 0.1 in mean and 0.05 in width.

Applications and empirical results

All numbers in this section are as reported by Thinking Machines Lab's post, which in turn draws on the Qwen3 technical report for one comparison. They are the authors' measurements in specific setups, not general laws.

A practical caveat from the same post: on-policy distillation works best when the student already puts some probability on what the teacher would do, which is why the experiments start from an SFT or mid-trained checkpoint. Reverse KL can only sharpen within the student's existing support; SFT (forward KL) is what adds new support.

On-policy self-distillation

The last two chapters cover self-distillation, where the teacher is the same model (or a copy of it) rather than a bigger one. The video's description doesn't name the specific papers, so this guide stays general. The common idea is that some version of the model has an advantage the student version lacks: an earlier checkpoint that still has a skill, or the same weights given extra context the student won't have at test time. The student is trained on its own samples to match that teacher token by token. Thinking Machines' personalisation result is one concrete case for continual learning: the earlier Qwen3-8B acted as teacher to restore what fine-tuning had erased, and the post suggests alternating "learn new data" and "distil old behaviour back" phases. It also reports that plain SFT on a model's own samples still degraded instruction following in its tests, which it takes as evidence that the on-policy, teacher-graded signal is what matters, not just training on self-generated text.

The two-by-two

MethodWho generates the training sequencesFeedback
Supervised fine-tuning / sequence-level KDTeacher or dataset (off-policy)Dense: every token
Token-level KD with soft targetsTeacher or dataset (off-policy)Dense: full distribution per token
RL with a verifier (PPO, GRPO)Student (on-policy)Sparse: one reward per sequence
On-policy distillation (GKD, MiniLLM, Thinking Machines)Student (on-policy)Dense: teacher grades every token

3. Where the course goes deeper

TopicCourse page
Teacher–student distillation in practice, and the privileged-teacher robotics versionModule 04 · Distillation deep dive
Multi-teacher on-policy distillation in a frontier model (Kimi K3)Module 05 · Serving
SFT, preference tuning, the KL leash and RL with verifiable rewardsModule 07 · KL, Module 07 · RLVR
Policy gradients, PPO and GRPOVideo 06 · GRPO, 30u30 Day 29 · PPO, Module 02 · RL ladder
DPO and preference methods (the KL-regularised view)Module 08 · Stage 05
Book-length treatment of post-training and RL for LLMsModule 11 · Raschka, Module 11 · RLHF book

Why it matters for robotics

Self-check

Why does a temperature T > 1 help in Hinton-style distillation, and why multiply the loss by T²?

Softening raises the small probabilities so the student can learn the teacher's relative preferences among wrong answers. Softening also shrinks the gradients by about 1/T², so the T² factor keeps the soft-target term's scale roughly constant as T changes.

Sequence-level distillation trains on teacher outputs. Why is it still affected by exposure bias?

The student only ever conditions on teacher-written prefixes. At test time it conditions on its own, and an early deviation puts it in states it never trained on. The data is off-policy.

RL is on-policy too. What does on-policy distillation give you that RL with a correctness reward doesn't?

Dense feedback. A verifier gives one number per sequence; the teacher gives a score at every token, so the student learns which step went wrong. Thinking Machines frames this as O(N) bits per episode against O(1).

A teacher has two equally likely, well-separated modes. Describe the best single-Gaussian student under forward KL and under reverse KL.

Forward KL: mean between the modes, width large enough to cover both, so it puts a lot of mass where the teacher has almost none. Reverse KL: it sits on one mode with roughly that mode's width, ignoring the other.

In Thinking Machines' implementation, what is the per-token advantage, and what extra model does it need?

The negative per-token reverse KL estimate: −(log π_student(y_t) − log π_teacher(y_t)) on the student's sampled token. It needs only the teacher's log-probabilities on the student's samples (one forward pass); no reward model.

Why does on-policy distillation usually start from an SFT checkpoint rather than a raw base model?

Reverse KL on student samples can only sharpen behaviour the student already produces with some probability. If the student never samples the teacher's kind of output, there's nothing to reinforce. SFT (forward KL) first adds that support.

References

The video's description lists no references. Primary sources for this guide: