Computing Library › Machine Learning
Machine Learning

Knowledge Distillation

Distillation trains a small student model to mimic a large teacher, transferring its behavior into a cheaper package.

Compressing behavior, not just weights

Knowledge distillation trains a compact student model to reproduce the behavior of a larger, more accurate teacher model. Rather than compressing the teacher weights directly, it transfers what the teacher has learned by training the student on the teacher outputs, so the student can match much of the teacher accuracy at a fraction of its size and cost.

Soft targets carry more information

Kronos motion — lego machine

The key insight is that the teacher full probability distribution, its soft targets, contains richer information than a hard label. When a teacher assigns 0.7 to one class and 0.2 to a similar one, it reveals learned relationships between classes, its dark knowledge. The student trains to match these softened probabilities, produced by dividing the teacher logits by a temperature before the softmax to expose the smaller probabilities.

python
# Distillation loss combines soft and hard targets
soft = kl_div(log_softmax(student/T), softmax(teacher/T)) * T*T
hard = cross_entropy(student, labels)
loss = alpha * soft + (1 - alpha) * hard

Variants

Why it matters

Distillation is a primary tool for deploying capable models on constrained hardware, phones, browsers, edge devices, where the teacher would be too slow or large. It complements other compression methods: a distilled student can be further shrunk with quantization and pruning. It also transfers robustness and calibration, and it lets a small model benefit from unlabeled data by learning from the teacher predictions on it.

The student rarely fully matches the teacher, so distillation is a deliberate accuracy-for-efficiency trade, tuned to the deployment budget.