What it is
A large model is often good enough for a task but too slow or expensive to run at scale. Distillation transfers what it does on your task into a much smaller model. The large one is the teacher, the small one the student, and the student is trained on the teacher's output instead of, or as well as, human-written answers.
The idea predates language models. Hinton, Vinyals and Dean's 2015 paper “Distilling the Knowledge in a Neural Network” showed that a small network learns far more from a large model's full output probabilities, which they called soft targets, than from the correct labels alone.
Why a teacher's probabilities teach more
A correct label says only which answer was right. A teacher's probabilities also say how wrong each wrong answer was. Hinton's example: an image of a BMW may have only a tiny chance of being mistaken for a garbage truck, but that is still many times more likely than mistaking it for a carrot. That pattern of near-misses describes how the teacher sees the problem, and a student that learns it generalises better from fewer examples.
For a language model the same holds at every token. Continuing “Your invoice is attached as a…”, a teacher might give PDF 86%, CSV 7%, file 4%. Training on the teacher's text keeps only “PDF”. Training on its distribution also teaches that CSV was a reasonable alternative and that most other words were not.
Temperature controls how much of that detail survives. The probabilities come from a softmax over the model's raw scores (logits); dividing the logits by a temperature T above 1 flattens the distribution, keeping the ranking but making the small probabilities large enough to influence training. Hinton et al. used the same high temperature for teacher and student, and multiplied the soft-target loss by T² because its gradients shrink by 1/T² as T rises.
p_i = exp(z_i / T) / Σ_j exp(z_j / T) # z = the model's raw scores (logits)
T = 1 PDF 0.86 CSV 0.07 file 0.04 link 0.02 zip 0.01
T = 3 PDF 0.43 CSV 0.19 file 0.16 link 0.12 zip 0.10 # same order, softerTwo ways to distil a language model
With language models there are two practical routes, and they differ in whose answers the student learns from.
Any model families. Only text crosses over. Trains exactly like supervised fine-tuning.
Same tokenizer required, so the teacher is usually a bigger model of the same family. Learns from its own mistakes.
| Aspect | Off-policy (sequence-level) | On-policy (token-level) |
|---|---|---|
| Who writes the answers | The teacher, once, before training | The student, fresh every step |
| What crosses over | Finished text | The teacher's probabilities at every token of the student's answer |
| Teacher and student | Any families; only text is shared | Same vocabulary (tokenizer), so usually the same family |
| Training | Plain supervised fine-tuning on prompt → teacher answer | A divergence between student and teacher, token by token |
| Signal per prompt | One answer to imitate | A correction at every token the student wrote |
Off-policy distillation is how DeepSeek built its small R1 models: about 800,000 samples generated with DeepSeek-R1 were used to fine-tune Qwen and Llama models with supervised training alone, no RL. Their distilled 32B model clearly outperformed the same base model trained with large-scale RL directly. When a strong teacher exists, copying it is often a better use of compute than having a small model discover everything by trial and error.
When to use it
- You want a cheaper, faster model that answers like a larger one on your topic.
- You have plenty of questions but few well-written answers: the teacher supplies the answers.
- A large model already does the job well, but its cost or latency is too high at scale.
And when not to: if no model, however large, answers your questions well, because they depend on your product or internal knowledge, distillation has nothing to transfer. Train on your own replies first.
- A large hosted model answers your support questions well but costs many times more per token than a small open model.
- Step 1: evaluate the teacher against the student on held-out questions. If the teacher wins clearly, there is something to distil; if they mostly tie, there isn't.
- Step 2: distil, then evaluate the distilled student against the plain student. The useful result is “close to the teacher” at the student's price, not “better than the teacher”.
- Step 3: if the answers are right but don't sound like your team, run supervised training on your own replies, continuing from the distilled model.
Common mistakes
- Distilling from a teacher you haven't evaluated on your questions. Its mistakes are learned too.
- Expecting the student to beat the teacher.
- Expecting your house style. Both routes teach the teacher's style; your replies are at most examples for the teacher.
- Distilling when teacher and student already answer about equally well; there is little to transfer.
- Using a few dozen prompts on the off-policy route. That much teacher text rarely changes a model's habits.
References and further reading
External sources open in a new tab.
- 01Distilling the Knowledge in a Neural NetworkHinton, Vinyals & Dean, 2015 · arXiv · arxiv.orgThe paper that named distillation: soft targets, temperature and the T² factor.
- 02Sequence-Level Knowledge DistillationKim & Rush, 2016 · arXiv · arxiv.orgDistilling by training on the teacher's generated sequences, the basis of off-policy distillation.
- 03DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement LearningDeepSeek-AI, 2025 · arXiv · arxiv.orgSmall models distilled from R1 with supervised training alone, compared with RL on the same bases.
- 04Does Reinforcement Learning Really Incentivize Reasoning Capacity in LLMs Beyond the Base Model?Yue et al., 2025 · arXiv · arxiv.orgFinds that distillation, unlike RL, can bring genuinely new reasoning patterns into a model.