Chapter 9 · Distillation and On-Policy Distillation¶
9.1 What is the basic principle of knowledge distillation? ★★¶
One-sentence answer
Knowledge distillation trains a small student to imitate the full probability distribution output by a large teacher (soft labels), rather than learning only one-hot ground-truth labels; the small probabilities on wrong classes in the soft labels carry dark knowledge such as similarities between classes, and the temperature \(T\) smooths the distribution so that this information shows up in the loss. In LLMs it takes the form of matching the teacher's next-token distribution token by token, or of running SFT directly on text generated by the teacher.
I will address three aspects: why imitating soft labels is better than learning ground-truth labels, what the temperature does, and the two forms distillation takes in LLMs.
(1) Soft labels carry more information than one-hot labels, and that is why distillation works.
The goal of knowledge distillation (KD; Hinton et al. 2015) is to have a small student model imitate a large teacher model, so that the student gets close to the teacher's ability at a much lower cost. A ground-truth label is one-hot: it only tells the model "this image is a cat". The teacher's full distribution also tells the model "this image is a cat, it looks a bit like a dog, and it looks nothing like a car". These similarities between classes are called dark knowledge, and they hide in the small probabilities of the wrong classes. A soft label therefore carries far more information than a one-hot label, so the student learns more from the same data and generalizes better.
(2) The temperature \(T\) smooths the teacher's distribution so that the information in the small probabilities shows up in the loss.
A trained teacher's output is usually very sharp, e.g. 0.99 for the correct class and around 0.0001 for every other class. These small probabilities carry information, but they are so tiny that they contribute almost nothing to the loss. Dividing the logits by \(T > 1\) smooths the distribution: the largest probability is pushed down and the small ones are lifted to a non-negligible size, so information such as "which wrong class looks more like the right answer" actually shows up in the loss, and only then can the student learn it. During distillation the teacher and the student use the same \(T\); at inference the student returns to \(T = 1\). In addition, raising the temperature shrinks the gradient of the soft-label term roughly as \(1/T^2\), so the loss is multiplied by \(T^2\) to keep the relative weight of the two loss terms unchanged when \(T\) is adjusted.
(3) In LLMs, distillation comes in a token-level form and a sequence-level form, corresponding to white-box and black-box settings.
In an LLM, predicting the next token at each position is a classification problem over the vocabulary.
- Token-level distillation (white-box): At every position, the student's next-token distribution is trained to match the teacher's, which amounts to SFT with the teacher's soft labels in place of one-hot labels. It requires access to the teacher's full logits and usually requires the two models to share a tokenizer. Seen the other way round, ordinary SFT is the special case in which the teacher's distribution collapses to one-hot.
- Sequence-level distillation (black-box): The teacher first generates complete responses, and the student then learns these responses with ordinary cross-entropy (Kim & Rush 2016). It needs only the teacher's text output, so it works with closed-source models; today's most common practice, "generate data with a strong model and run SFT on it", is essentially sequence-level distillation.
In summary: the essence of distillation is using the teacher's full distribution instead of sparse labels as the supervision signal; the various distillation methods for LLMs differ mainly in how much information they can get from the teacher, and in whose generated sequences they learn on (see 9.3 and 9.4).
Going deeper: the distillation loss, where \(T^2\) comes from, and engineering issues of white-box distillation
(1) The classic distillation loss.
Here \(z_i\) is the teacher's logit for class \(i\), \(p^{(T)}\) the teacher's softmax distribution at temperature \(T\), \(q^{(T)}\) the student's distribution at the same temperature, \(q^{(1)}\) the student's distribution at \(T=1\), \(y\) the ground-truth label, \(\mathrm{CE}\) the cross-entropy, and \(\alpha\) balances the two loss terms.
(2) Why multiply by \(T^2\).
The gradient of the soft-label term with respect to the student's \(i\)-th logit is \((q_i - p_i)/T\), and at large \(T\) the difference \(q_i - p_i\) itself shrinks roughly as \(1/T\), so the gradient of this term shrinks as \(1/T^2\) overall. After multiplying by \(T^2\), changing \(T\) no longer changes the relative weight of the two loss terms. Hinton et al. also note that at very high \(T\), with zero-mean logits, this term is approximately equivalent to making the student's logits fit the teacher's logits directly.
(3) Comparing white-box and black-box distillation.
| White-box (logit) distillation | Black-box (text) distillation | |
|---|---|---|
| What we get from the teacher | Full logits at every position | Only generated text (e.g. through an API) |
| Training signal | Match the teacher's distribution at every token | SFT on the teacher's outputs |
| Information per token | A whole distribution: rich | One sampled token: sparse |
| Requirements | Open weights; identical or alignable tokenizers | Any teacher, including closed-source ones |
| Examples | Hinton KD, MiniLLM, GKD, small-model pretraining in Gemma 2 and Llama 3.2 | Synthetic instruction data, DeepSeek-R1-Distill |
(4) Two engineering obstacles to white-box distillation.
- Mismatched tokenizers: Logits are defined over the teacher's vocabulary; if the student's tokenizer differs, the same text is split into different token sequences, the two distributions cannot be aligned, and one needs a dedicated cross-tokenizer method or a fallback to black-box distillation. That is why white-box distillation is most common within a single model family.
- Logits too large to store offline: With a vocabulary of 150k, the full distribution for one token takes about 300 KB in bf16, whereas a token ID takes only a few bytes. In practice one therefore either runs the teacher online during training, or stores only the top-k most likely tokens and their probabilities at each position.
(5) Distillation is also used in pretraining.
Gemma 2's 2B and 9B models are pretrained by "predicting the teacher's next-token distribution" instead of ordinary next-token prediction (Gemma Team 2024); Llama 3.2's 1B and 3B models were first obtained by structured pruning of Llama 3.1 8B and then used logits from Llama 3.1 8B and 70B as token-level targets during pretraining to recover performance (Meta 2024). A soft label per token carries more information than a one-hot label, so a small model learns better from the same number of tokens.
Follow-up questions
Follow-up 1: What is the difference between word-level and sequence-level distillation?
The difference is whether the student learns the teacher's distribution at each position, or the complete sequences the teacher generates. Word-level KD follows the reference answers in the training data and matches the teacher's next-token distribution at each position; sequence-level KD first has the teacher generate complete outputs and then has the student learn these outputs with cross-entropy. The idea behind the latter is that what we really want to match is the teacher's distribution over the whole sequence space, but that distribution cannot be enumerated, so it is approximated by the teacher's high-probability outputs. Kim & Rush (2016) also found that teacher outputs are more uniform in style than human-written references, which makes them easier for a capacity-limited student to learn.
Follow-up 2: What if the teacher and the student use different tokenizers?
Either use a cross-tokenizer alignment method or fall back to black-box distillation. Different tokenizers split the same text differently, so the KL between distributions over two different vocabularies cannot be computed directly. The simplest option is to run SFT only on text generated by the teacher, which is what DeepSeek-R1-Distill does (R1's tokenizer differs from Qwen's and Llama's anyway).
Follow-up 3: Why do we say that SFT is a special case of distillation?
Because SFT is equivalent to token-level distillation with the teacher's distribution collapsed to one-hot. SFT only maximizes the probability of the token in the data, as if the teacher put all of its probability on that one token at every position; token-level distillation preserves the teacher's judgment about the other candidate tokens.
Common mistakes
- Do not say that the student also uses a high temperature at inference: The temperature is used only during distillation training; at inference the student returns to \(T = 1\).
- Do not say that SFT on teacher-generated data is not distillation: It is sequence-level distillation, only with a sparser signal than token-level distillation.
- Do not ignore the \(T^2\) factor: Without it, raising the temperature makes the gradient of the soft-label term shrink rapidly, and the weighting of the two loss terms becomes unbalanced.
9.2 How do forward KL and reverse KL differ, and which should be used for distillation? ★★¶
One-sentence answer
The forward KL \(\mathrm{KL}(p\,\|\,q_\theta)\) takes the expectation over the teacher's samples and forces the student to cover all of the teacher's modes (mode-covering), which is equivalent to cross-entropy on teacher data; the reverse KL \(\mathrm{KL}(q_\theta\,\|\,p)\) takes the expectation over the student's own samples and makes the student focus on the teacher's main modes (mode-seeking). When the student lacks capacity, generation tasks are usually better served by the reverse KL, because it puts more weight on the quality of each output; but it requires the student to sample for itself, i.e. on-policy training.
I will address three aspects: how the two KLs behave differently, why this difference matters for a small student, and how to choose between them for distillation.
(1) The two KLs differ in whose samples the expectation is taken over, so they penalize different kinds of errors.
Let \(p\) be the teacher's distribution and \(q_\theta\) the student's. The KL is asymmetric: which distribution comes first decides whose samples the expectation is taken over, and that in turn decides what the student learns to be.
- The forward KL is mode-covering: The expectation is over the teacher's samples. Whenever the teacher gives some output a reasonable probability but the student gives it nearly zero, the penalty becomes huge, so the student is forced to put probability everywhere the teacher does. Minimizing the forward KL is equivalent to maximizing the student's log-likelihood on the teacher's samples, which is exactly what SFT and standard KD do.
- The reverse KL is mode-seeking: The expectation is over the student's own samples. If the student generates an output the teacher considers nearly impossible, the penalty is huge; but if the student misses some of the teacher's modes, it never samples there and so is never penalized. The student therefore picks one or a few of the teacher's main modes and learns them well.
(2) The difference between the two KLs matters only when the student lacks capacity, and that is precisely the normal situation in distillation.
When the student has enough capacity, both KLs are minimized at \(q_\theta = p\), and there is no difference. But distillation assumes precisely that the student is smaller than the teacher and cannot represent the teacher's full distribution. A simple example: the teacher is a distribution with two peaks, while the student can represent only one. With the forward KL, the student covers both sides with one wide peak and ends up putting a lot of probability in the valley between them, where the teacher thinks nothing should be; with the reverse KL, the student picks one of the peaks and fits it tightly. In text generation, a student trained with the forward KL may sample content "between" the teacher's various behaviors, such as odd blends of several answer styles, or outputs that look plausible but are actually hallucinations; the reverse KL would rather say less but say it right, giving higher output quality at the cost of diversity.
(3) Generation tasks usually favor the reverse KL, but "which divergence to use" and "whose samples to train on" are two independent choices.
For generation tasks we usually care more about the quality of each output, which is why MiniLLM (Gu et al. 2023) and others argue for the reverse KL in LLM distillation. But the reverse KL has an implementation hurdle: the expectation is over the student's samples, so the student must generate its own data, and one cannot simply run cross-entropy on a fixed dataset as in SFT. Note that in token-level distillation, "which divergence to use at each position" and "where the prefixes come from" are in fact two independent choices (Agarwal et al. 2023): with full logits available, any divergence can be computed exactly on any prefix. GKD's experiments found that the data source has the more consistent effect, with on-policy or mixed data almost always better, while the best divergence varies by task. The reason the reverse KL and on-policy training always appear together is that, by the chain rule of the KL, the reverse KL over whole sequences is exactly the sum of the per-position token-level reverse KLs over prefixes sampled by the student itself.
In summary: the choice between the two KLs is essentially a trade-off between "covering all of the teacher's behavior" and "doing only what the teacher endorses"; for capacity-limited generative models the latter is usually more appropriate, and it naturally requires on-policy sampling.
Going deeper: definitions, the chain rule and a comparison table
(1) Definitions of the two KLs.
Here \(y\) can be a single token or a whole sequence. Since \(\mathrm{KL}(p\,\|\,q_\theta) = -\mathbb{E}_{y\sim p}[\log q_\theta(y)] - \mathcal{H}(p)\) and the teacher's entropy \(\mathcal{H}(p)\) does not depend on \(\theta\), minimizing the forward KL is the same as maximizing \(\mathbb{E}_{y\sim p}[\log q_\theta(y)]\), i.e. cross-entropy on the teacher's samples.
(2) The connection between the sequence-level reverse KL and on-policy training.
The left side is the reverse KL over whole responses \(y\); the right side sums, over prefixes \(y_{<t}\) sampled by the student, the reverse KL between the next-token distributions at each position. The value of the on-policy distillation loss (see 9.4) is therefore the sequence-level reverse KL itself. Likewise, the sequence-level forward KL equals the sum of token-level forward KLs over prefixes sampled by the teacher, which is exactly word-level KD on teacher data. This yields a symmetric picture: the forward KL goes with teacher prefixes (off-policy), and the reverse KL goes with student prefixes (on-policy).
(3) Comparing the two KLs.
| Forward KL | Reverse KL | |
|---|---|---|
| Expectation taken over | Teacher samples | Student samples |
| Behavior | Mode-covering (mean-seeking) | Mode-seeking (zero-forcing) |
| Heaviest penalty | The student missing something the teacher does | The student doing something the teacher would not |
| Result for a small student | Spreads probability; may generate low-quality "in-between" outputs | Concentrates on the main modes: precise but less diverse |
| Training data | Fixed teacher data (off-policy), plain cross-entropy | The student's own samples (on-policy), requires sampling |
| Typical methods | Hinton KD, SFT on teacher outputs | MiniLLM, on-policy distillation |
(4) Options in between.
GKD also uses the generalized JSD, which interpolates between the forward KL and the reverse KL through a single parameter. In addition, the KL penalty in RLHF, \(\mathrm{KL}(\pi_\theta\,\|\,\pi_{\text{ref}})\), is also a reverse KL.
Follow-up questions
Follow-up 1: Which KL does SFT minimize?
The forward KL. SFT maximizes the student's log-likelihood on the data (or on teacher-generated samples), which is equivalent to minimizing \(\mathrm{KL}(p_{\text{data}}\,\|\,q_\theta)\), because the entropy of the data distribution does not depend on the student's parameters.
Follow-up 2: Does switching to the reverse KL on fixed data fix exposure bias?
No. Exposure bias depends on where the prefixes come from, not on which divergence is used. As long as the prefixes come from fixed data, the states seen in training differ from the states the student reaches on its own at inference, and switching to the reverse KL does not solve that (see 9.3).
Follow-up 3: If the student has enough capacity, do the two KLs still differ?
Not at the optimum: both are minimized at \(q_\theta = p\). With finite data and finite training steps, however, their optimization paths still differ; the difference truly matters when the student cannot represent the teacher's full distribution.
Common mistakes
- Do not mix up the names "forward" and "reverse": Papers sometimes use the opposite convention, so the safest practice is to write out both arguments of the KL.
- Do not say that the reverse KL is always better than the forward KL: GKD found that the best divergence varies by task, and the reverse KL pays for its precision with lower diversity.
- Do not treat "reverse KL" and "on-policy" as the same thing: The former is a choice of divergence; the latter is a choice of data source.
9.3 What is wrong with off-policy distillation? ★★¶
One-sentence answer
Off-policy distillation trains the student on sequences written by the teacher or by humans, but at inference the student continues from prefixes it generated itself, so the two state distributions differ; this is exposure bias: the student has never seen the states that follow its own mistakes, so once it goes off track it tends to keep going wrong, and errors accumulate with sequence length. In addition, when the teacher is far stronger than the student, the student may learn only the surface form of the teacher's reasoning rather than the ability. The remedy is to let the student generate and have the teacher correct it, which is on-policy distillation.
I will address three aspects: what exposure bias is, why it causes errors to compound, and another problem caused by a capacity mismatch.
(1) The training states and inference states of off-policy distillation differ; this is exposure bias.
In SFT and off-policy distillation, the prefix at every position during training comes from data written by the teacher or by humans; this practice is called teacher forcing. At inference, however, the student continues from prefixes it generated itself. The prefix distribution seen in training differs from the prefix distribution actually encountered at inference; this is exposure bias: during training, the model is never "exposed" to its own mistakes.
(2) Because the training data contain no demonstrations of "what to do after a mistake", errors compound with sequence length.
The student cannot imitate the teacher perfectly, and sooner or later it writes a token at some position that the teacher would not write. From that moment on, it is in a state that never appeared in the training data; and since the teacher's data contain no such mistake, they naturally contain no demonstration of "how to recover after this kind of mistake", so the student is more likely to keep going wrong there, and one wrong step leads to the next. Imitation-learning theory makes this precise: imitating only on the expert's state distribution (behavior cloning) can make errors grow quadratically with sequence length in the worst case, whereas collecting expert labels on the states the learner itself visits makes errors grow only linearly with length (Ross & Bagnell 2010; Ross et al. 2010). For long CoTs that often run to thousands of tokens, this difference is huge.
(3) When the teacher is far stronger than the student, the student may learn only the surface form.
The teacher's reasoning may contain steps the student simply cannot perform, such as complex mental arithmetic done in one step. When the student is forced to imitate such trajectories, what it learns is often the surface form rather than the ability: the same confident tone and the same "let me verify this", while the actual verification is wrong. Gudibande et al. (2023) found that imitation models trained on ChatGPT outputs learned the style but did not catch up in factual accuracy, and human evaluators were easily misled by the style.
In summary: the fundamental problem of off-policy distillation is that the student learns the path the teacher walked, but at inference it walks its own path; the remedy is to let the student receive the teacher's guidance on the states it actually reaches (see 9.4).
Going deeper: the mismatch between training and inference, and the connection to imitation learning
(1) Comparing the training objective with the inference process.
The training objective of off-policy distillation is
while generation at inference proceeds as
Here \(\pi_T\) is the teacher, \(\pi_\theta\) the student, \(y\) a sequence generated by the teacher, and \(\hat y\) a sequence generated by the student itself. In training, the prefix \(y_{<t}\) in the conditioning comes from the teacher; at inference, the prefix \(\hat y_{<t}\) comes from the student itself.
(2) The magnitude of error accumulation.
Let \(\epsilon\) be the probability that the student makes a mistake at a given step on the expert's state distribution, and let \(L\) be the sequence length. In the worst case, the total error of behavior cloning is \(O(\epsilon L^2)\), because once a mistake is made, the student may be in unfamiliar states for all remaining steps; DAgger collects labels on the learner's own state distribution, and its total error is \(O(\epsilon L)\).
(3) Historical remedies.
| Method | What it does |
|---|---|
| Scheduled sampling (Bengio et al. 2015) | Gradually replaces reference tokens in the prefix with the model's own predictions during training |
| DAgger (Ross et al. 2010) | Lets the learner act, and has the expert label the states the learner actually reaches |
| On-policy distillation | The student generates, and the teacher gives the next-token distribution at every prefix of the student's output |
Follow-up questions
Follow-up 1: How is on-policy distillation related to DAgger?
On-policy distillation is the DAgger idea implemented for LLM distillation. DAgger lets the learner act and then has the expert label the states the learner actually reaches; on-policy distillation lets the student generate responses and then has the teacher give the next-token distribution at every prefix of the student's output. The key in both is that the supervision signal is collected on the learner's own state distribution.
Follow-up 2: Given these problems, why is off-policy distillation still often run first in practice?
Because it is cheap and simple, and it brings the student close to the teacher, providing a good starting point for subsequent on-policy training. If the student is too weak at first, its own outputs are completely off track, and the teacher's signals on those prefixes, though well defined, are not necessarily meaningful. The common pipeline is therefore off-policy distillation first, then on-policy distillation (see 9.4 and 9.6).
Follow-up 3: Does exposure bias affect short and long responses equally?
No; the longer the sequence, the larger the effect. Error accumulation grows superlinearly with length, and long CoTs often run to thousands of tokens, so the probability that the student drifts off the teacher's trajectory partway through is high. This is one reason on-policy methods bring clear gains in reasoning distillation.
Common mistakes
- Do not say that switching to the reverse KL fixes exposure bias: Exposure bias depends on where the prefixes come from and has nothing to do with the choice of divergence.
- Do not say that off-policy distillation is worthless: It is the cheapest form of distillation and the only one available with a black-box teacher, and it often serves as the cold start before on-policy training.
- Do not take a student that has learned the teacher's style for one that has learned the teacher's ability: Imitation of surface form easily fools human evaluation.
9.4 What is on-policy distillation, and why is it cheaper than RL? ★★¶
One-sentence answer
On-policy distillation (OPD) lets the student generate responses and has the teacher score every token in them, using the reverse KL between the student and the teacher at each position as the loss: like RL, it learns on the student's own states, and like SFT, it has a supervision signal at every token. It is cheaper than RL because the information each response provides goes from roughly one bit in RL to a target at every token, so far fewer samples and steps are needed, and teacher scoring is just one parallel forward pass.
I will address three aspects: how OPD works, why it is effective, and why it is cheaper than RL.
(1) OPD works like this: the student solves the problem itself, and the teacher grades it token by token.
In OPD, for a batch of prompts, the student first generates responses by itself; this step needs only prompts, with no reference answers and no reward. Then the student's whole response is fed into the teacher for one forward pass, giving the teacher's log-probability at every position; since the response has already been generated, all positions can be computed in parallel, like a single prefill. Next, the reverse KL between the student and the teacher is computed at each position; the simplest way uses only the sampled token and takes the difference between the student's and the teacher's log-probabilities for it. Finally, the student is updated to minimize this KL. In an RL framework, the negative of this difference can be used as each token's advantage: if the student wants this token more than the teacher does, it is pushed down; if the teacher endorses the token more than the student does, it is pushed up; when the two agree, almost nothing changes. Intuitively, the teacher is like a tutor grading homework step by step: the student solves the problem itself, and at each step the tutor marks "I would not write this" or "this step is fine".
(2) OPD gets both the dense signal of SFT and the on-policy property of RL.
- Dense like SFT: RL gives a whole response a reward of just "right" or "wrong", roughly \(O(1)\) bits of information per response, and the model has to infer from statistics over many samples which tokens caused success or failure; OPD has a target at every token, passing \(O(N)\) bits per response (\(N\) is the number of tokens) (Lu & Thinking Machines Lab 2025). This also takes care of credit assignment: if the student takes a wrong step at token 300, RL only knows that the final answer was wrong, and the correct earlier steps are punished along with it; OPD puts a large penalty right around token 300, and the earlier steps the teacher agrees with are barely affected.
- On-policy like RL: Training uses the states the student actually reaches, including its own mistakes. The teacher shows it how to continue from those mistaken states, so the student learns to recover and exposure bias disappears (see 9.3). Combined with the mode-seeking behavior of the reverse KL, the student moves toward the teacher within what it can actually do, rather than imitating trajectories it cannot execute.
(3) OPD is cheaper than RL for three main reasons.
- It needs far fewer samples and steps: Since every token is supervised, the signal is used far more efficiently than in RL. RL also needs a group of responses per question to compute advantages, and groups that are all right or all wrong are wasted (see Chapter 8); in OPD every sample provides a useful gradient.
- Teacher scoring is cheap: Scoring is just one parallel forward pass over an already generated sequence, much faster than autoregressive generation.
- No reward model or verifier is needed: All that is required is a teacher that performs well in the domain, so it also works on tasks with no reference answer.
In summary: OPD can be understood as RL in which the reward is known at every token: it keeps the benefits of on-policy training while replacing the sparse outcome reward with the teacher's per-token judgment, so it can transfer the teacher's abilities to the student at a cost far below that of RL.
Going deeper: the loss, representative work, concrete numbers and practical details
(1) The OPD loss and its single-sample estimate.
Here \(x\) is a question drawn from the prompt set \(\mathcal{D}\), \(y\) a response sampled by the student itself, \(\pi_\theta\) the student, \(\pi_T\) the teacher, \(\hat k_t\) the single-sample estimate of the per-token reverse KL using the sampled token, and \(A_t\) the per-token advantage used in an RL framework. The Thinking Machines implementation sets the discount factor to 0, so each token is responsible only for its own step's KL and not for its effect on later tokens; the exact sequence-level gradient also includes a part for "the current token affecting later states", so this gives up a little unbiasedness in exchange for much lower variance and a simple implementation. In practice one can reuse RL code with a KL penalty directly: swap the reference model for the teacher and drop the reward.
(2) Two representative works.
- MiniLLM (Gu et al. 2023): One of the first works to argue systematically for the reverse KL in LLM distillation; it optimizes the sequence-level reverse KL directly with policy gradient, uses single-step decomposition (computing the current step's term exactly over the vocabulary) to reduce variance, samples from a mixture of the teacher and the student to avoid learning degenerate outputs, and uses length normalization to avoid a bias toward overly short responses.
- GKD (Agarwal et al. 2023): Unifies distillation into a framework with two knobs: it uses a fraction \(\lambda\) of student-generated data (\(\lambda = 0\) is ordinary supervised KD and \(\lambda = 1\) is fully on-policy), and it can use the forward KL, the reverse KL or the generalized JSD. It does not differentiate through the sampling process, so it is simple to implement and stable to train.
(3) Concrete numbers.
| Experiment | Starting point | Method | Result |
|---|---|---|---|
| Thinking Machines (Lu & Thinking Machines Lab 2025) | Qwen3-8B-Base after off-policy SFT on 400k prompts, 60% on AIME'24 | Continued SFT | Extrapolation suggests about 2M prompts to reach 70% |
| Same | Same | OPD | Reaches 70% in about 150 steps, with roughly 9–30× less compute than continued SFT |
| Qwen3 technical report (Yang et al. 2025) | An off-policy-distilled 8B checkpoint, 55.0% on AIME'24 | RL | About 17,920 GPU hours, reaching 67.6% |
| Same | Same | OPD | About 1,800 GPU hours, reaching 74.4% |
The compute gap reported by Thinking Machines is a range because it depends on whether the cost of having the teacher generate the SFT data is counted.
(4) Practical details.
- Three ways to compute the per-token KL: Using only the sampled token is simplest and only requires the teacher to return log-probabilities for given text, but its variance is higher; computing it exactly over the whole vocabulary has the lowest variance but needs both models' full logits and the same tokenizer; computing it over only the teacher's top-k tokens is a compromise.
- Very few samples per prompt: Every token in OPD has its own target, so no group comparison is needed; Thinking Machines samples only 4 responses per prompt.
- Prompts can be reused repeatedly: Thinking Machines trained on a single prompt for 20 consecutive steps with 256 sampled responses per step, and the student roughly caught up with the teacher. Because the target is the teacher's distribution on each freshly generated student response rather than a fixed answer, reusing the same prompt does not turn into memorizing an answer the way SFT would.
- It can be combined with RL: When there is both a real reward and a decent teacher, the two can be used together as the training signal: the teacher provides dense guidance, while the reward keeps the student from being capped by the teacher.
Follow-up questions
Follow-up 1: Why does OPD use the reverse KL rather than the forward KL?
Because the sequence-level reverse KL is exactly the sum of per-token reverse KLs over the student's own prefixes, which matches on-policy sampling naturally. Moreover, the reverse KL is mode-seeking and penalizes the student for doing things the teacher would not do, which suits a capacity-limited student moving toward the teacher within its own abilities (see 9.2).
Follow-up 2: Why is a round of SFT usually run before OPD?
Because the student cannot start out too weak. If the student's outputs are completely off track, the teacher's per-token signals on those strange prefixes, though well defined, are not necessarily meaningful. Running off-policy SFT first to bring the student close to the teacher and then running OPD is more efficient; both Thinking Machines and Qwen3 do this.
Follow-up 3: Can OPD suffer from reward hacking the way RL does?
Not at the level of the objective, but it inherits the teacher's own flaws. The optimum of the reverse KL is exactly matching the teacher, so there is no gap between "lowering the KL" and "becoming more like the teacher", which is why Thinking Machines calls it "unhackable"; an RL reward, by contrast, is only a proxy for the real goal, and the gap between proxy and goal is exactly where hacking comes from. However, whatever the teacher prefers, the student will learn: MiniLLM observed that students learn degenerate outputs that the teacher also scores highly (such as repeated phrases).
Follow-up 4: What are OPD's limitations?
There are three main ones.
- It needs a white-box teacher: We need the teacher's log-probabilities for the tokens the student generates, so the teacher must either have open weights or offer an interface that scores arbitrary text.
- The ceiling is the teacher: OPD learns to "be like the teacher" and cannot surpass it; to go beyond the teacher, a real reward and RL are still needed.
- The engineering is more complex: It needs RL-style sampling infrastructure plus one teacher forward pass for every student token, and the larger the teacher, the more noticeable this cost.
Common mistakes
- Do not say that OPD needs reference answers or a reward: It needs only prompts and a teacher that can provide log-probabilities.
- Do not say that OPD can surpass the teacher: Its objective is to match the teacher, so the teacher is also its ceiling.
- Do not say that a black-box teacher is enough for OPD: With only the teacher's generated text, the per-token KL cannot be computed.
- Do not take OPD's low cost to mean "the teacher does no computation": The teacher still runs a forward pass over every student token; it is just that such a parallel forward pass is much cheaper than autoregressive generation.
9.5 How do SFT, RL and on-policy distillation compare? ★★¶
One-sentence answer
The three can be compared by who generates the data, whether the signal is dense, and what they require: SFT learns from fixed data produced by a teacher or by humans, with a dense signal but off-policy; RL learns from the student's own samples, on-policy but with a sparse signal, and its advantage is that it can surpass any existing model; OPD lets the student receive the teacher's per-token guidance on its own samples, combining the strengths of both, but its ceiling is the teacher. From a unified perspective, all three make the student approach some target distribution, and they differ in what the target is and which direction of KL is used.
I will address three aspects: the core differences among the three, a unified theoretical perspective, and the situations each suits.
(1) The core differences lie in who generates the data and how much signal each sample provides.
The three methods can be understood through the analogy of a student doing exercises (Lu & Thinking Machines Lab 2025):
- SFT is studying the teacher's worked solutions: Every step has a demonstration, so the signal is dense; but the demonstrations show the teacher's way of thinking, and once the student goes off track on its own, they never show how to recover.
- RL is the student solving problems alone and only being told whether the final answer is right: It learns entirely in its own states, but each problem gives only about one bit of feedback, so it takes a great many problems to slowly work out which step went wrong.
- On-policy distillation is the student solving problems alone while a teacher grades every step: It learns in its own states and gets feedback at every step.
(2) From a unified perspective, all three make the student approach some target distribution.
SFT approaches the data distribution with the forward KL, with samples taken from the data. RL with a KL penalty can be rewritten as approaching an "optimal distribution" with the reverse KL, where that distribution is the reference model reweighted exponentially by the reward (derivation in Chapter 7); this optimal distribution cannot be written down explicitly and can only be sensed indirectly through the reward, so the signal is sparse. OPD approaches the teacher directly with the reverse KL, as if the target distribution were given explicitly, so every token can be compared against it directly. Going one step further, minimizing the reverse KL to the teacher is equivalent to RL whose reward is "the teacher's log-probability of this sample", plus an entropy regularizer. The entropy term is crucial: maximizing the teacher's log-probability alone would make the student collapse onto the single output the teacher finds most likely; the entropy term keeps the student's own distribution from collapsing while it moves toward the teacher.
(3) The three suit different situations and are usually combined in practice: SFT for the cold start, RL to raise a frontier model's capabilities, then OPD to distill small models from the large one.
The three differ in cost, requirements and ceiling, so they play different roles.
- SFT suits cold starts and teaching formats and knowledge: It is the cheapest and simplest, good for cold starts and for teaching the model output formats and new knowledge, and it is the only option with a black-box teacher.
- RL suits pushing the frontier of capability: It is the most expensive, but it is the only method that needs no stronger teacher and can surpass every existing model.
- OPD suits transferring a strong model's abilities to a small one: When a strong teacher already exists, it is the most efficient way to transfer its abilities to the student.
In summary: the differences among the three come down to "who generates the data" and "who provides the signal": in SFT the teacher generates and the teacher demonstrates; in RL the student generates and the environment scores; in OPD the student generates and the teacher scores every token.
Comparing the three methods:
| SFT / off-policy distillation | RL (e.g. RLVR) | On-policy distillation | |
|---|---|---|---|
| Who generates the training sequences | The teacher or humans (a fixed dataset) | The student itself | The student itself |
| Training signal | A target at every position (the data token or the teacher's distribution) | One scalar reward per response | The teacher's log-probability at each of the student's tokens |
| Signal density | Dense | Sparse | Dense |
| On-policy? | No: exposure bias | Yes | Yes |
| What it needs | Teacher outputs or labeled data | A reward: a verifier or a reward model | A stronger white-box teacher |
| Cost | Cheapest per step, but strong results may need large amounts of teacher data | Highest: many rollouts per prompt and many training steps | Moderate: student rollouts plus one teacher forward pass |
| Ceiling | The quality of the teacher or the data | Can exceed any teacher; bounded by exploration | The teacher |
Going deeper: formulas for the unified view, and the difference in forgetting
(1) The objectives of the three methods.
Here \(p_{\text{data}}\) is the data distribution, \(\pi^*\) the optimal solution of the KL-regularized RL objective, \(\pi_{\text{ref}}\) the reference model, \(r(y)\) the reward, \(\beta\) the KL coefficient, and \(\pi_T\) the teacher.
(2) OPD is equivalent to RL with a special reward.
The expectation on the right is the expected return with the teacher's log-probability as the reward, and \(\mathcal{H}(\pi_\theta)\) is the student's entropy. Since \(\log\pi_T(y\mid x)\) decomposes into a sum of per-token terms, the reward of this RL problem is known at every token, which is exactly why OPD is cheap.
(3) On-policy training forgets less, so OPD can be used to restore abilities.
A series of studies found that, on the same new task, on-policy training forgets less than SFT. For example, RL's Razor (Shenfeld et al. 2025) found that the degree of forgetting can be predicted by the KL between the fine-tuned model and the original model measured on the new task's inputs, and that on-policy updates tend to settle near the solution closest to the original model. In the Thinking Machines experiment, after Qwen3-8B continued training on a company's internal documents, internal-knowledge QA rose from 18% to 43%, but IFEval (instruction following) fell from 85% to 45%; with 30% general chat data mixed in, the two numbers were 36% and 79%. Starting from that model and running OPD on general chat prompts with the original Qwen3-8B as the teacher, IFEval came back to 83%, and internal-knowledge QA actually rose to 41%. The full discussion of continual learning is in the Self-Improving & RSI direction.
Follow-up questions
Follow-up 1: If OPD is both cheap and effective, why do we still need RL?
Because OPD's ceiling is the teacher, whereas RL can surpass every existing model. When pushing the frontier of capability, no stronger teacher exists, and only a real reward can drive the exploration of new behaviors. A practical division of labor is that RL discovers new abilities and distillation spreads them cheaply. Thinking Machines also found that when a teacher trained with RL is distilled back into the original base model, OPD needs only about 1/7 to 1/10 of RL's gradient steps.
Follow-up 2: Why is SFT called off-policy, while OPD and RL are on-policy?
The difference lies in who generates the training sequences. SFT's sequences come from a fixed dataset that has nothing to do with what the student would currently generate; the sequences in RL and OPD are generated by the student's current policy, so the states seen in training are exactly the states the student will reach at inference.
Follow-up 3: After domain fine-tuning, general abilities dropped. How can distillation restore them, and why does it not overwrite the newly learned knowledge?
Use the model from before fine-tuning as the teacher and run OPD on general prompts. The teacher is simply the model's own earlier version, so no stronger external model is needed. Because OPD corrects only the student's own outputs, and only where they drift from the old model's behavior, and because general chat prompts do not touch the new domain knowledge, what gets corrected is "behavior", and "knowledge" is not overwritten.
Common mistakes
- Do not say that OPD can completely replace RL: Without a stronger teacher, only RL can keep pushing capability forward.
- Do not say that RL's signal is dense: A response usually gets a single scalar reward, the sparsest signal of the three.
- Do not say that SFT and OPD differ only in their data source: They also use different directions of the KL: SFT corresponds to the forward KL and OPD to the reverse KL.
9.6 How are reasoning models distilled? Should a small model be distilled or trained directly with RL? ★★¶
One-sentence answer
The most common form of reasoning distillation is to have a strong reasoning model generate large numbers of long-CoT trajectories and then run SFT on a small model, as in DeepSeek-R1-Distill; a better practice is staged: first learn the format of long CoT through off-policy distillation, then use on-policy distillation to correct the student's own mistakes, and finally run RL if needed. A small model should be distilled first rather than trained directly with RL, because it rarely samples correct answers to hard problems, so RL lacks a starting point for exploration; running RL after distillation usually brings further gains.
I will address three aspects: what DeepSeek-R1-Distill did and concluded, why small models should be distilled first, and the problems of SFT-only reasoning distillation together with a better pipeline.
(1) DeepSeek-R1-Distill shows that SFT alone on a strong model's reasoning trajectories outperforms large-scale RL run directly on a small model.
After DeepSeek-R1 was trained, DeepSeek used R1 to generate about 800k samples (about 600k rejection-sampled reasoning samples plus about 200k non-reasoning samples) and ran SFT directly on Qwen2.5 (1.5B to 32B) and Llama models, producing the DeepSeek-R1-Distill series. The whole process is SFT only, with no RL; and it used only the text R1 generated, not its logits, so it is essentially one large-scale sequence-level distillation. The most convincing evidence is a controlled comparison: large-scale R1-Zero-style RL directly on Qwen2.5-32B-Base reached 47.0% on AIME 2024, while SFT on R1's data alone reached 72.6%.
(2) Small models should be distilled first, and the key reason is exploration.
RL can only reinforce what the student itself samples (see Chapter 8). A small model is weak and rarely samples a correct answer on hard problems, so the reward is almost always 0 and the learning signal is extremely scarce; even when it does succeed, its search range stays close to the abilities it already has. Reasoning patterns that large models discover through large-scale RL, such as reflection, backtracking and case analysis, are hard for a small model to find through its own exploration. Distillation hands these patterns to the small model directly in the form of trajectories, which effectively skips the hardest exploration phase. This is consistent with Yue et al. (2025): RLVR struggles to expand the base model's reasoning boundary, whereas distillation from a stronger teacher can bring in genuinely new reasoning patterns. Of course, RL after distillation still helps, and the DeepSeek paper also notes that further RL on the distilled models brings additional gains.
(3) SFT-only reasoning distillation has clear flaws, so a staged pipeline is the better practice.
SFT-style reasoning distillation inherits the weaknesses of off-policy training (see 9.3): the student may learn only the surface form of reasoning, such as writing "wait" constantly, overthinking or getting stuck in repetition loops, without learning real verification ability; and it may generalize poorly to problems that differ from the training distribution. A better pipeline therefore has three stages:
- Off-policy distillation: First run SFT on the teacher's reasoning trajectories so that the student learns the basic format and approach of long CoT.
- On-policy distillation: Then have the teacher correct the student token by token on the student's own trajectories, fixing its own mistakes.
- RL: Finally, if needed, run RL on verifiable tasks to break through the teacher's ceiling or to improve further on specific tasks.
Qwen3's small models (the 0.6B to 14B dense models and the 30B-A3B MoE model) use exactly this "off-policy distillation → on-policy distillation" pipeline, with Qwen3-32B or Qwen3-235B-A22B as the teacher (Yang et al. 2025).
In summary: for small models, distillation "moves over" the reasoning patterns that strong models discovered, and RL polishes them further on that basis; the order cannot be reversed, because without a good starting point RL has nothing to explore from.
Going deeper: is a stronger teacher always better, and some concrete numbers
(1) A stronger teacher is not always better.
As early as classification tasks, Mirzadeh et al. (2019) found a capacity gap: when the teacher and the student differ too much, the student actually learns worse, because the teacher's distribution is too complex for the small model to fit; their remedy was to add an intermediate-size "teacher assistant", distilling from the large teacher to the assistant first and then from the assistant to the student. The same phenomenon appears in reasoning distillation: Li et al. (2025) found a "small model learnability gap", in which small models of 3B parameters or fewer do not improve reliably when trained on very long CoTs or on the strongest teachers' outputs, and instead learn better from shorter CoTs or from smaller teachers' outputs. Their Mix Distillation trains on a mix of long and short CoTs (or outputs from large and small teachers); for example, Qwen2.5-3B-Instruct gains more than 8 points on MATH and AMC compared with training on long CoTs alone.
(2) A small amount of high-quality data can also unlock reasoning.
For an already strong base model, a few hundred to a thousand carefully chosen, high-quality long-CoT examples can unlock decent reasoning ability, e.g. s1 (Muennighoff et al. 2025) and LIMO (Ye et al. 2025). This shows that the effect of reasoning distillation also depends on the abilities the base model already has.
(3) Comparing different training routes.
| Route | Example | Result |
|---|---|---|
| Large-scale RL directly on a small model | DeepSeek-R1-Zero-Qwen-32B | AIME 2024: 47.0% |
| SFT-only distillation of R1's trajectories | DeepSeek-R1-Distill-Qwen-32B | AIME 2024: 72.6% |
| RL after distillation | DeepScaleR-1.5B (Luo et al. 2025; built on DeepSeek-R1-Distill-Qwen-1.5B, with the context length extended step by step) | AIME 2024: 28.8% → 43.1% |
| RL or OPD after off-policy distillation | Qwen3's 8B experiment | AIME'24: RL 55.0% → 67.6%; OPD 55.0% → 74.4% |
Follow-up questions
Follow-up 1: Does a stronger teacher always give better distillation?
Not necessarily. If the teacher's reasoning contains many steps beyond the student's ability, the student can only imitate the surface form; and the longer the sequence, the worse the off-policy error accumulation. When choosing a teacher, one should therefore look not only at how strong it is but also at whether the student "can learn" its outputs, and if needed choose shorter reasoning trajectories or a mid-size teacher. On-policy distillation partly sidesteps this problem: the trajectories are generated by the student itself, so they are within its reach by construction, and the teacher only makes local corrections.
Follow-up 2: If you had to design a training pipeline to give a small model strong reasoning ability, how would you do it?
I would design it in the order "off-policy distillation → on-policy distillation → RL". First, choose a teacher whose outputs the student can learn, run SFT on its long-CoT trajectories, and take care to filter out wrong answers and repetition loops; next, run on-policy distillation with the teacher on the student's own trajectories; finally, run RL on verifiable tasks, with difficulty filtering and a length curriculum, to raise pass@1 further. After each stage, evaluate both pass@1 and pass@k at large \(k\) to confirm that the reasoning boundary has not shrunk.
Follow-up 3: Is DeepSeek-R1-Distill white-box or black-box distillation?
In form, it is black-box distillation. It ran SFT only on the text R1 generated and did not use logits; moreover, R1's tokenizer differs from Qwen's and Llama's anyway, so per-token distribution matching would not be directly possible.
Common mistakes
- Do not say that DeepSeek-R1-Distill used RL: It used SFT only; the paper merely notes that further RL on top of it brings gains.
- Do not say that a small model can learn a large model's reasoning patterns through RL alone: A small model's exploration ability is limited, and it can hardly discover these patterns on its own.
- Do not say that RL is unnecessary after distillation: Distillation is capped by the teacher, and RL can keep improving on top of it.
- Do not say that a stronger teacher is always better: Both the capacity gap and the learnability gap show that too large a gap between teacher and student is harmful.