What is knowledge distillation?
Knowledge distillation trains a small model, the student, to copy the outputs of a larger trained model, the teacher. Instead of learning only from hard labels, the student learns from the teacher's full probability distribution over classes or tokens. Those probabilities show which wrong answers are close to right, and the student picks up that structure with far fewer parameters.
Distillation is how many compact models are built for serving. DistilBERT is a distilled BERT, Gemma 2's 2B and 9B models were trained on a larger teacher's distributions, and many small open chat and reasoning models are fine-tuned on text written by a bigger model. A smaller student reads fewer bytes per generated token, so it answers faster and costs less to run, and it fits on phones and laptops where the teacher cannot.
Key ideas
- A student model learns to match a larger teacher's output probabilities instead of only the hard labels.
- The teacher's small probabilities on wrong classes encode which classes are similar, information a one-hot label throws away.
- Dividing logits by a temperature T above 1 softens both distributions so those small probabilities affect training.
- The loss mixes α·T²·KL to the teacher with (1 − α) cross-entropy on the true label; T² keeps the soft gradients from shrinking as T grows.
- Soft targets act as a regularizer, so a student trained on them overfits less when labelled data is scarce.
- For LLMs, distillation ranges from matching the teacher's per-token logits to fine-tuning on text the teacher generated.
Common questions
How is knowledge distillation different from quantization and pruning?
Quantization stores the same weights in fewer bits, and pruning removes weights or whole heads from the trained model. Both keep the original architecture. Distillation trains a separate, smaller architecture from scratch or from a smaller checkpoint, using the teacher as the source of targets. The three are often combined, for example a distilled student that is then quantized to 4 bits.
Can a student model be better than its teacher?
Sometimes. When the student has the same size as the teacher, as in born-again networks, it often scores slightly higher, because the soft targets act as a strong regularizer. A much smaller student usually stays below the teacher but well above the same small model trained on labels alone.
Does the student need the same architecture or tokenizer as the teacher?
The architecture can differ freely, since only the outputs are matched. Logit distillation does need the same output space: for LLMs that means a shared vocabulary, so each of the teacher's token probabilities has a matching student token. Sequence-level distillation only needs text, so it works across tokenizers and model families.
Is it allowed to train a model on another model's outputs?
It depends on the teacher's license or terms of service. Several commercial API providers forbid using their outputs to build competing models, while many open-weight licenses permit distillation, sometimes with naming or attribution conditions. Check the specific license before using a model's outputs as training data.
Related explainers
- Softmax, Logits & Temperature — Turning raw scores into probabilities
- KL Divergence — Measuring how different two distributions are
- Loss Functions — How networks measure their mistakes
- BERT & Masked Language Modeling — Mask a word, predict it from both sides — how BERT learns deep bidirectional representations
- Quantization — Shrinking model weights to 8 and 4 bits
- Sampling: Temperature, Top-k & Top-p — How a language model picks its next token
References
- Hinton, Vinyals & Dean (2015), "Distilling the Knowledge in a Neural Network"
- Kim & Rush (2016), "Sequence-Level Knowledge Distillation"
- Sanh et al. (2019), "DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter"
- Gemma Team (2024), "Gemma 2: Improving Open Language Models at a Practical Size"
- DeepSeek-AI (2025), "DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning"
Last updated