AI & prompting

What Is Model Distillation? Teacher, Student and Soft Targets

Model distillation trains a small "student" model to imitate a large "teacher" model, using the teacher's outputs as training targets instead of only the original labels. The student ends up much cheaper to run while keeping much of the teacher's accuracy, which is how many small, fast models are made.

Where the idea comes from

The technique was named in a 2015 paper by Geoffrey Hinton, Oriol Vinyals and Jeff Dean, Distilling the Knowledge in a Neural Network. Their starting point: training and deployment have different needs. Training can afford a huge model or an ensemble of many models and lots of compute; serving millions of users needs something small and fast. The paper compares this to insects, whose larval form is built for feeding and adult form for travel and reproduction, and proposes training a cumbersome model first and then transferring its knowledge into a small one. They call that transfer step distillation, and credit earlier work by Rich Caruana and colleagues on compressing an ensemble into a single model.

How distillation works: soft targets

A normal classifier is trained on hard labels: this image is a BMW, full stop. But a trained model's output says more than its top answer. The paper's example: an image of a BMW may have only a very small chance of being mistaken for a garbage truck, but that mistake is still many times more likely than mistaking it for a carrot. Those small probabilities encode how the model sees the world: cars resemble trucks more than vegetables.

Distillation trains the student on the teacher's full probability distribution, which the paper calls soft targets. The problem is that a confident teacher puts almost all probability on one class, so the useful small numbers are nearly zero. The fix is temperature. The paper's softmax with temperature T is:

q_i = exp(z_i / T) / Σ_j exp(z_j / T)

where z are the model's raw scores (logits). T = 1 is the normal softmax; a higher T "produces a softer probability distribution over classes", in the paper's words. Here is what that does to three illustrative logits, 9, 4 and -2, for BMW, garbage truck and carrot, computed in Python:

TemperatureBMWGarbage truckCarrot
T = 10.99330.00670.0000166
T = 20.92070.07560.0038
T = 50.67630.24880.0749
T = 200.42450.33060.2449
import math
def softmax(z, T):
    e = [math.exp(x / T) for x in z]
    s = sum(e)
    return [x / s for x in e]

for T in (1, 2, 5, 20):
    print(T, [round(p, 4) for p in softmax([9.0, 4.0, -2.0], T)])

At T = 1 the truck-versus-carrot information is buried in tiny numbers. At T = 5 it's clearly visible: the truck is about 3 times more likely than the carrot. The paper uses the same high temperature for the teacher and the student during training; once trained, the student uses a temperature of 1.

In practice the student is trained on two objectives at once: match the teacher's soft targets, and get the true hard labels right. The paper recommends multiplying the soft-target part by T² so that its contribution stays balanced when you change the temperature.

What the original paper measured

MNIST digits. A large, heavily regularised network made 67 test errors. A smaller network (two hidden layers of 800 units) trained normally made 146 errors. The same small network trained to match the large one's soft targets at a temperature of 20 made 74 errors, nearly closing the gap. In a striking variant, a student trained on data with every example of the digit 3 removed still got 98.6% of the test 3s right after a bias adjustment, having learned what a 3 is purely from the teacher's soft targets on other digits.

Speech recognition. On a production acoustic model, the paper reports:

SystemTest frame accuracyWord error rate
Baseline single model58.9%10.9%
Ensemble of 10 models61.1%10.7%
Distilled single model60.8%10.7%

One distilled model matched the word error rate of the 10-model ensemble, so serving needs one model instead of ten.

Distillation in language models

The idea transferred directly to large language models, in two main forms.

Classic distillation on the teacher's probabilities. DistilBERT (Sanh et al., 2019) applied it during pre-training of a smaller BERT. The paper reports a model 40% smaller than BERT that keeps 97% of its language-understanding performance and runs 60% faster.

Distillation on the teacher's generated text. With modern LLMs, the student often never sees the teacher's probabilities. Instead, the teacher generates answers, and the student is fine-tuned on them as ordinary training data. DeepSeek-R1 is a well-documented example. Its paper says the reasoning patterns of large models can be used to improve smaller models' reasoning, and the model card lists six distilled models, fine-tuned from open-source bases using samples generated by DeepSeek-R1:

Distilled modelBase model it was trained from
DeepSeek-R1-Distill-Qwen-1.5BQwen2.5-Math-1.5B
DeepSeek-R1-Distill-Qwen-7BQwen2.5-Math-7B
DeepSeek-R1-Distill-Llama-8BLlama-3.1-8B
DeepSeek-R1-Distill-Qwen-14BQwen2.5-14B
DeepSeek-R1-Distill-Qwen-32BQwen2.5-32B
DeepSeek-R1-Distill-Llama-70BLlama-3.3-70B-Instruct

For the Qwen-based models, the card says they were fine-tuned with 800,000 samples curated with DeepSeek-R1. Note what that means: a "Distill-Qwen-7B" model is a Qwen model taught to reason like R1, not a shrunken R1. Its architecture and size come from the base model. If you're running models locally, that matters when you compare them; see what 7B means in an LLM and what is a reasoning model.

Distillation vs quantization vs fine-tuning

DistillationQuantizationFine-tuning
What changesA new, smaller model is trainedSame model, weights stored in fewer bitsSame model, weights adjusted for a task
Training targetsThe teacher's outputsNone (no training, or light calibration)Your labelled examples
Main goalSmaller, faster model with similar behaviourLess memory, faster inferenceBetter behaviour on a specific task

They combine well. A distilled model can be quantized to run on a laptop (what is LLM quantization), and fine-tuned cheaply with adapters (LoRA fine-tuning explained).

Limits of distillation

  • The student is capped by the teacher. It learns to imitate, so it inherits the teacher's mistakes and biases along with its skills.
  • Headline numbers don't transfer. DistilBERT's 97% is one model on one benchmark suite. How much a student loses depends on the size gap, the task and the training data, so check results on your own tasks.
  • Coverage depends on the prompts. When distilling from generated text, the student learns what the training prompts covered. Gaps in those prompts become gaps in the student.
  • Licences and terms. Read the teacher model's licence or the provider's terms of use before training on its outputs.

Frequently asked questions

Is a distilled model as good as the original?
Usually not quite, but it can come close at a fraction of the size. DistilBERT reports keeping 97% of BERT's language-understanding performance while being 40% smaller and 60% faster. How much is lost depends on the task, the size gap and the training data, so evaluate the student on your own use case.
What is the difference between distillation and quantization?
Distillation trains a new, smaller model with fewer parameters. Quantization keeps the same model and stores its existing weights in fewer bits, for example 4 instead of 16. They solve the same problem, a model too big to run cheaply, and are often combined: a distilled model can be quantized afterwards.
Is distillation the same as fine-tuning?
Distillation is a kind of training, and in the LLM world it often looks like fine-tuning: a smaller model is fine-tuned on outputs generated by a bigger one. The difference is the source of the training targets. In ordinary fine-tuning they come from human-labelled data; in distillation they come from the teacher model.
Why use a high temperature during distillation?
At the normal temperature of 1, a confident teacher puts nearly all probability on one answer, so the small probabilities that show which wrong answers are similar to the right one are close to zero. Raising the temperature spreads the distribution out so the student can learn from those relationships. Hinton et al. use the same high temperature for teacher and student during training, and the student uses a temperature of 1 afterwards.

Sources