What is Knowledge distillation?

Training a small student model to mimic a large teacher model's outputs so the small model achieves similar performance.

Field: AI Hardware & Software Stack

Japanese name: 知識蒸留

Imitating the teacher's output

The large trained model is called the teacher, and the small model about to be trained is called the student. The student learns to approach the probability distribution the teacher outputs, in addition to the correct labels. Suppose that for a picture of a cat the teacher answers cat 0.9, dog 0.09 and car 0.01. This contains the information that a dog resembles a cat more than a car does. The correct label says nothing more than 'cat'. The student can use relationships like this that the teacher has learned.

Temperature and loss

In a teacher's output, the probability of the correct answer is often close to 1 and the others are very small. As it stands, the differences among the small probabilities contribute little to learning. A value called temperature is therefore put into the softmax to make the distribution smoother. The higher the temperature, the larger the small probabilities become in relative terms. A commonly used loss is a weighted sum of two terms, the difference from the teacher's distribution and the difference from the correct labels.

Uses and limits

Knowledge distillation is used to reduce the computation and memory of inference. It can be combined with quantization and pruning. Besides the computation for training the student, computation for obtaining the teacher's outputs is needed. What is obtained is performance close to the teacher's, not necessarily the same. If the student is too small, it becomes hard to get close to the teacher's performance. How small it can be made depends on the task and the accuracy required.

Try it: questions about Knowledge distillation

Which describes knowledge distillation?

  1. AHeating model weights to evaporate and shrink them
  2. BWashing the training data with distilled water
  3. CTraining a small student model to mimic a large teacher model's outputs so the small model achieves similar performance
Show answer and explanation

Answer: C. Training a small student model to mimic a large teacher model's outputs so the small model achieves similar performance

In knowledge distillation, a small model (the student) is trained to match outputs of an already trained large model (the teacher), such as its probability distribution over answers. Learning not just the correct labels but also how likely the teacher considered each answer lets the small model approach the original's performance. It is used alongside quantization and pruning to reduce inference compute and memory.

FAQ

How does it differ from quantization and pruning?

What is made lighter is different. Quantization and pruning reduce the number of bits or the number of weights of the same model. Knowledge distillation trains a separate, smaller model.

Does the student model need the same structure as the teacher?

No. In the form that imitates the output distribution, the student can be trained as long as the shape of the output matches, even if the number and width of layers differ. Giving the student a smaller structure than the teacher is the usual way the method is used.

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary