Resources/Model training/Training methods

Method

Distillation

Distillation trains a small, cheap student model to behave like a large teacher model on your tasks, either by learning from the teacher's answers or from the teacher's judgement of its own.

Chapter 74 min read4 references

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.

1.00PDF0CSV0file0link0zipHard targetWhat training on the teacher's text sees: one right word, everything else zero.
.86PDF.07CSV.04file.02link.01zipTeacher, T = 1The teacher's real belief. The small numbers say which alternatives were plausible.
.43PDF.19CSV.16file.12link.10zipTeacher, T = 3Softened by temperature: the same ranking, but the runners-up are now big enough to learn from.
The next word after “Your invoice is attached as a…”. A hard target throws away everything except the winner. The teacher's full distribution also says that CSV was a near miss and zip was not, and a higher temperature makes those differences large enough to matter in training.

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.

Softmax with temperature, for the example above
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, softer

Two ways to distil a language model

With language models there are two practical routes, and they differ in whose answers the student learns from.

Way 1 · teacher writes answers
your prompt→teacher (large)→full answer text→student learns prompt → answer

Any model families. Only text crosses over. Trains exactly like supervised fine-tuning.

Way 2 · teacher grades the student's own answer
your prompt→student writes→teacher scores every token→student moves toward teacher

Same tokenizer required, so the teacher is usually a bigger model of the same family. Learns from its own mistakes.

Off-policy distillation passes finished text from teacher to student. On-policy distillation lets the student write, then shows it, token by token, what the teacher would have said instead.
AspectOff-policy (sequence-level)On-policy (token-level)
Who writes the answersThe teacher, once, before trainingThe student, fresh every step
What crosses overFinished textThe teacher's probabilities at every token of the student's answer
Teacher and studentAny families; only text is sharedSame vocabulary (tokenizer), so usually the same family
TrainingPlain supervised fine-tuning on prompt → teacher answerA divergence between student and teacher, token by token
Signal per promptOne answer to imitateA 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.

Is distillation worth it here?
  1. A large hosted model answers your support questions well but costs many times more per token than a small open model.
  2. 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.
  3. 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”.
  4. 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.

  1. 01Distilling the Knowledge in a Neural NetworkHinton, Vinyals & Dean, 2015 · arXiv · arxiv.orgThe paper that named distillation: soft targets, temperature and the T² factor.
  2. 02Sequence-Level Knowledge DistillationKim & Rush, 2016 · arXiv · arxiv.orgDistilling by training on the teacher's generated sequences, the basis of off-policy distillation.
  3. 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.
  4. 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.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.