Skip to main content
Knowledge Distillation

Knowledge Distillation

The Teacher-Student Framework

Knowledge distillation is based on a surprisingly human analogy: a master chef (the teacher) has spent years developing intuition about flavor combinations, but they can train an apprentice (the student) far faster than the apprentice could learn from raw ingredients alone. The apprentice does not need to replicate every experience the master had — they just need to absorb the master’s refined judgment. In ML terms: a large, expensive model has learned a rich understanding of the data, and we can transfer that understanding to a smaller, deployable model more efficiently than training the small model from scratch on raw labels. The key insight from Hinton’s original 2015 paper: when a teacher classifies a cat image, its “soft” output might say “90% cat, 8% dog, 2% tiger.” Those secondary probabilities (the “dark knowledge”) carry information that hard labels (“cat”) miss entirely. They tell the student that cats and dogs are more similar than cats and cars — relationships that would take the student many more examples to discover on its own.
Distillation is not just for model compression. It is also used to: (1) transfer knowledge from an ensemble to a single model, (2) train models on private data by distilling from a model trained with access, and (3) improve training stability by providing smoother gradient signals than hard labels.

Core Distillation Methods

Soft Target Distillation


Feature-Based Distillation

Soft-target distillation only uses the final output layer. But the teacher’s intermediate representations also carry valuable information — the way the teacher structures its internal representations (which features activate together, which spatial regions get attention) is knowledge the student can absorb. Feature-based distillation forces the student’s hidden layers to mimic the teacher’s, providing a much richer training signal. Think of it this way: soft-target distillation is like learning from a teacher’s final answers on an exam. Feature-based distillation is like also seeing the teacher’s scratch work — the intermediate reasoning steps that led to those answers.

Relation-Based Distillation


Self-Distillation

Self-distillation is one of the most surprising results in knowledge distillation: you can improve a model by distilling it from itself. There is no separate, larger teacher. The model’s own deeper layers teach its shallower layers, or a previously trained copy of the same architecture serves as the teacher. The fact that this works at all suggests that the “dark knowledge” in soft targets provides a regularization benefit that goes beyond the information in hard labels.
Born-Again Networks (self-distillation through iterative retraining) typically gives diminishing returns after 2-3 generations. The first self-distillation step usually provides the most improvement (0.5-1% accuracy). Beyond generation 3, the student often plateaus or slightly degrades. Do not assume more generations equals more improvement.

Task-Specific Distillation

The methods above are general-purpose, but real-world distillation often requires task-specific adaptations. Object detection models have multiple heads (classification + regression) and multi-scale feature pyramids. Language models have attention patterns and layered hidden states. Simply applying vanilla KD to the final output of these models leaves significant knowledge on the table. The following recipes show how to distill knowledge from each component of complex architectures.
For NLP model distillation, the most impactful technique is usually attention pattern matching (used in TinyBERT and MiniLM). The attention matrices encode which tokens the model considers related, and this structural knowledge transfers very effectively. For vision models, FPN feature distillation at all scales tends to give the biggest gains because different scales capture different-sized objects.

Advanced Distillation Techniques


Exercises

Train students with different temperatures (1, 2, 4, 8, 16). Plot accuracy vs temperature and find optimal value.
Combine feature distillation with soft target distillation. Compare to using each alone.
Implement Born-Again Networks:
  • Train for 3 generations
  • Compare each generation’s accuracy
  • Try different temperatures per generation

What’s Next?

Continual Learning

Learn new tasks without forgetting old ones

Quantization

Model compression with quantization