Visual explainer
Knowledge Distillation
Train a student to match a teacher distribution, then serve the student alone. Follow temperature, gradients, hard labels and the limits of imitation.
Knowledge distillation trains a student using a teacher's outputs. A smaller student can be easier to deploy, but accuracy must be checked. Our synthetic budget has 10 million float32 teacher weights and 2 million student weights: at four bytes each, that is 40 MB versus 8 MB. The dashed 16 MB budget excludes the teacher's weights but accommodates the student's. Bars use eight drawing units per MB; runtime buffers and activations are excluded.
More than one label
Use class order D=dog, C=cat, V=vehicle throughout. A hard dog target is . Teacher logits at temperature one give approximately . Each bar has height ; zero targets are dots, not short positive bars. The teacher assigns different probabilities to the two alternatives. Those are model beliefs, not a universal semantic-distance scale.
Compute the soft targets
For logits , . At , the scaled logits are , exponentials approximately and their sum . Division gives . Both panels keep the scale; the smaller bars have gained mass from dog. Temperature four is an illustrative setting, not a prescription.
Update only the student
The input forks to both models; their predictions enter the matching objective. The double border marks the frozen teacher, and the lower return lane updates only the student. This form of distillation imitates output distributions; it does not establish that internal reasoning or representations have been copied. The distillation paper defines the temperature-based training setup.
Serve the smaller path
The teacher has no connection to the serving path. The three output bars illustrate a student that exactly matches the original logits; their heights use , a deliberate smaller scale to fit the pipeline. This is a possible output, not a measured training outcome. Teacher prediction generation and student training cost computation before deployment; the deployed student need not run the teacher.
Return to inference temperature
This controlled example holds the student's final logits at and changes only the stage: matching at , serving at . The bars return to the scale. Both models use the same temperature for soft-target matching. The original method returns the student to one for ordinary inference. Sharper probabilities do not establish correctness.
Check the student family
Switch to a synthetic scalar regression problem to isolate capacity. Teacher outputs at inputs are . Restrict the student to . No line passes through all three points; its least-squares solution is , with mean squared error . Coordinates use and . This limit follows from the restricted student family, not from a universal minimum model size.
Follow one gradient
Return to classification. Solid bars show a uniform student ; dashed outlines show the teacher's targets, again at . For , the gradient with respect to student logits is . It equals approximately . Gradient descent raises the dog logit and lowers the other two. Equal arrow lengths encode signs only, not gradient magnitudes; softmax couples probability changes.
Anchor with trusted labels
A new illustrative teacher target is wrong for a dog. At temperature one and uniform student logits, the soft objective lowers the dog logit, while the hard dog label raises it. These bars use . A combined objective can use . The loss weight and temperature need validation. Labels are optional for pure distillation; trusted labels supply a separate corrective signal when available.
Where It Breaks
Both models now output at the same scale, so both choose cat for a dog. Their agreement is perfect on this example and their prediction is wrong. Evaluate the student against trusted held-out outcomes and deployment constraints; teacher agreement alone does not measure task success.
The Quick Version
- Smaller student weights can meet a deployment budget.
- Soft targets distinguish alternative classes.
- Temperature changes probabilities while preserving logit order.
- The frozen teacher guides student updates.
- Serving can use the student alone.
- Soft-target training and ordinary inference use different temperatures.
- Restricted student capacity can prevent an exact match.
- Distillation gradients move logits toward teacher targets.
- Trusted labels can oppose erroneous teacher outputs.
- Perfect teacher agreement can still mean a wrong prediction.