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.
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
- Start with a small "student" model that already knows the basics, often after first copying the teacher's answers.
- The student writes answers to practice questions by itself.
- The big "teacher" model reads each answer and says, word by word, how likely it would have been to write that word.
- Words the teacher strongly disagrees with get pushed down; words it agrees with get pushed up.
- 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
- Draw a simple shape from memory after looking at a perfect example. Then draw it again while a friend says "good" or "not that way" at each line. Which drawing improves faster over three tries?
- In the demo further down, move Mode separation up and watch the two student fits split apart: the forward-KL student stretches to cover both teacher bumps, and the reverse-KL student picks one. Change Left-mode weight to see which bump the reverse-KL student chooses.
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
| Time | Chapter | What to look for |
|---|---|---|
| 0:00 | Why Distillation Matters | The motivation: small models are cheaper, faster and can run locally, but are hard to train to high quality directly. |
| 1:28 | Soft Targets and Dark Knowledge | Hinton-style distillation: matching the teacher's whole softened distribution, and why the small probabilities on wrong answers carry information. |
| 4:11 | From One Token to Many Tokens | Going 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:30 | Exposure Bias | Why training on teacher-written prefixes leaves the student unprepared for its own prefixes, and how errors compound over long outputs. |
| 12:11 | On-Policy Reinforcement Learning | RL trains on the student's own samples (fixing the mismatch), but a single reward per sequence is sparse feedback. |
| 14:08 | On-Policy Distillation | The combination: student-generated samples, graded densely by the teacher at every token. |
| 16:39 | Why the KL Direction Matters | Forward 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:04 | Applications and Empirical Results | The overview of where on-policy distillation has been reported to help. |
| 20:30 | Application 1: Reasoning | Distilling maths reasoning into a smaller model, compared with more supervised fine-tuning or RL, and the compute each needs. |
| 22:43 | Application 2: Personalization | Teaching a model new domain knowledge, then using distillation to restore behaviours (like instruction following) that the new training damaged. |
| 24:47 | Application 3: Data Reuse | Why training many times on the same prompts works better with distillation than with RL, which tends to memorise answers. |
| 25:52 | On-Policy Self-Distillation for Reasoning | Variants where the teacher is the model itself under different conditions. Watch for what gives the "teacher" copy its advantage. |
| 29:15 | On-Policy Self-Distillation for Continual Learning | Using a model (or an earlier copy of it) as its own teacher so that learning new things doesn't erase old skills. |
| 30:04 | Recap | The two-by-two picture: who generates the data (teacher or student) and how dense the feedback is. |
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 (word-level) distillation: on a fixed sequence (ground truth or teacher-generated), match the teacher's next-token distribution at every position.
- Sequence-level distillation (Kim and Rush, 2016): generate outputs with the teacher (they used beam search) and train the student on them with ordinary cross-entropy. This approximates matching the teacher's distribution over whole sequences, and their best student ran 10× faster than its teacher with little loss in quality.
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.
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.
- Reasoning. The post quotes the Qwen3 report: from the same off-policy-distilled starting point, RL reached 67.6% on AIME'24 using 17,920 GPU hours, while on-policy distillation reached 74.4% using 1,800 GPU hours. In its own replication (Qwen3-8B-Base student, starting from a 400k-prompt SFT checkpoint at 60%), on-policy distillation reached about 70% in roughly 150 steps, which the post estimates as 9–30× cheaper than continuing SFT to the same score.
- Personalisation. Mid-training Qwen3-8B on internal company documents raised an internal-knowledge score but lowered instruction following (IF-eval), and no data mix fully preserved it. Running on-policy distillation afterwards, with the original Qwen3-8B as teacher on general chat prompts, brought IF-eval from 79% back to 83% (the original was 85%) while keeping the new knowledge.
- Data reuse. Training repeatedly on a single maths prompt (20 steps of 256 rollouts) approximately matched the teacher's AIME'24 score. With RL, repeated epochs on the same prompt tend to memorise the final answer; the distillation target is a whole distribution, so it doesn't collapse the same way.
- Dense versus sparse. Distilling an RL-trained teacher back into its own base model recovered the teacher's performance in about 7–10× fewer gradient steps than the RL run took, which the post estimates as 50–100× less compute overall.
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
| Method | Who generates the training sequences | Feedback |
|---|---|---|
| Supervised fine-tuning / sequence-level KD | Teacher or dataset (off-policy) | Dense: every token |
| Token-level KD with soft targets | Teacher 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
| Topic | Course page |
|---|---|
| Teacher–student distillation in practice, and the privileged-teacher robotics version | Module 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 rewards | Module 07 · KL, Module 07 · RLVR |
| Policy gradients, PPO and GRPO | Video 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 LLMs | Module 11 · Raschka, Module 11 · RLHF book |
Why it matters for robotics
- It's DAgger, which came from robotics. The compounding-error argument and the "let the learner act, have the expert label its states" fix come from imitation learning for control (Ross et al., 2011). On-policy distillation brings the same idea back to language models. If you've trained a robot policy with DAgger, you already know the algorithm.
- Privileged teacher to deployable student. Legged-locomotion work trains a teacher in simulation with information real robots lack, then trains a sensor-only student (Module 04). Doing that student training on the student's own rollouts is on-policy distillation with a different reason for the teacher's advantage.
- On-robot models must be small. Distilling a large VLA or language planner into something that fits robot compute is the obvious use. Reverse-KL, mode-seeking behaviour is arguably what you want for control: commit to one good way of grasping rather than averaging two grasps into a bad one in between. That last point is an analogy; the language-model results above don't test it.
- Keep old skills while learning new ones. A robot fine-tuned on a new task often loses old ones. Distilling from the earlier checkpoint on old-task data, as in the personalisation result, is a candidate fix. Evidence in robotics specifically is thinner than in LLMs, so treat it as a promising technique rather than a solved problem.
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:
- On-Policy Distillation of Language Models: Learning from Self-Generated Mistakes (GKD) (Agarwal, Vieillard, Zhou, Stanczyk et al., 2023)
- On-Policy Distillation (Kevin Lu and others, Thinking Machines Lab, October 2025)
- MiniLLM: On-Policy Distillation of Large Language Models (Gu, Dong, Wei, Huang, 2023)
- Distilling the Knowledge in a Neural Network (Hinton, Vinyals, Dean, 2015)
- Sequence-Level Knowledge Distillation (Kim, Rush, 2016)
- Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks (Bengio, Vinyals, Jaitly, Shazeer, 2015)
- A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning (DAgger) (Ross, Gordon, Bagnell, 2011)
- Qwen3 Technical Report (Qwen Team, 2025), source of the RL vs on-policy distillation comparison quoted above