跪拜 Guibai
← All articles
Artificial Intelligence

Knowledge Distillation Isn't Model Shrinking — It's Teaching a Student to Think Like the Teacher

By 东风破_ ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Running large models in production is expensive and slow. Distillation produces smaller models that retain much of the teacher's judgment at a fraction of the inference cost, making real-time, on-device, and high-throughput deployments practical without sacrificing as much accuracy as training a small model from scratch.

Summary

Knowledge distillation transfers capability from a large teacher model to a smaller student by having the student imitate the teacher's softened probability distribution, not just memorize correct answers. Hard labels discard valuable information about class similarity — a cat photo labeled only as "cat" loses the signal that dogs and tigers are visually closer to cats than cars are. The teacher's output distribution captures these relationships as "dark knowledge."

A temperature parameter in the softmax function controls how much of that secondary information the student sees. Higher temperatures smooth the distribution, exposing subtle class affinities that a hard label would flatten to zero. The student optimizes a combined loss: cross-entropy against ground-truth labels plus a divergence term that pulls its softened output toward the teacher's softened output.

Distillation is not lossless compression. Student capacity sets a hard ceiling on what can transfer, teacher errors propagate, and the training data's coverage bounds what the student learns. The technique sits alongside quantization and pruning in the model-compression toolkit, and the methods are often stacked — distill first, then quantize.

Takeaways
Hard labels discard class-relationship information by setting all incorrect options to zero; soft labels from a teacher model preserve relative similarities across classes.
Raising the softmax temperature above 1 smooths the teacher's probability distribution, exposing secondary class affinities that a student can learn from.
The student's total loss combines cross-entropy against true labels with a KL-divergence or cross-entropy term that matches its softened output to the teacher's softened output.
Distillation loss is typically scaled by T² to compensate for gradient shrinkage caused by the temperature parameter.
Collecting text answers from a large-model API without access to logits or token probabilities is response-based distillation, not classic logit-level distillation.
Student capacity is a hard upper bound — a model that is too small cannot absorb the teacher's full knowledge regardless of data volume.
Teacher biases, hallucinations, and errors transfer to the student; the teacher's output is not ground truth.
Distillation, quantization, pruning, and fine-tuning are complementary and frequently combined in deployment pipelines.
Conclusions

The term "dark knowledge" captures something counterintuitive: the most valuable information a teacher model provides is not the correct answer but the relative probabilities it assigns to wrong answers. Those probabilities encode structural knowledge about the data that a one-hot label destroys.

Temperature is a dial for how much secondary information the student receives, not a hyperparameter to maximize. Too high, and class differences wash out; too low, and distillation collapses into ordinary hard-label training.

The distinction between logit-level distillation and response-based distillation matters practically. Many teams that think they are doing knowledge distillation are actually just generating synthetic training data from an API, which provides far less supervisory signal.

Distillation's cost is easy to underestimate. Running the teacher to generate training data, storing outputs, and training the student all consume resources. It is a deployment-time trade-off, not a free lunch.

Concepts & terms
Hard Label
A one-hot encoded training target where only the correct class is 1 and all others are 0. It tells the model what the answer is but discards information about how classes relate to each other.
Soft Label
A probability distribution over classes, typically from a teacher model, that assigns non-zero probabilities to incorrect classes. It encodes the teacher's judgment about class similarity and decision boundaries.
Dark Knowledge
The structural information about class relationships embedded in a teacher model's soft label distribution — for example, that a cat photo is more similar to a dog than to a car. This knowledge is invisible in hard labels.
Temperature (T)
A parameter in the softmax function that controls the sharpness of the output probability distribution. Higher values produce softer, more uniform distributions that reveal secondary class relationships; T=1 is standard classification.
Response-based Distillation
A form of distillation where the student learns from the teacher's final text output rather than from logits or token-level probabilities. Common when only an API endpoint is available, but it provides less information than classic logit-level distillation.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗