In knowledge distillation, the student minimises , where uses temperature . How do you derive the gradient of with respect to student logit in the high-temperature limit to show why the multiplier is needed?
ML systems and evaluation, Model compression
Level L4 Advanced. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can differentiate the temperature-scaled cross-entropy/KL objective and understand why soft-target gradients shrink as .
Key idea
Differentiating with respect to student logits brings out a factor of , and in the high-temperature limit the probability difference itself scales as , so the gradient scales as unless multiplied by .
Steps
- Write the KL term up to a constant independent of the student: , where .
- Differentiate with respect to student logit by the chain rule: since , dividing by gives .
- Take the high-temperature limit (, where are teacher logits): using , for zero-mean logits () we get and , where is the number of classes.
- Substitute into the gradient: (and without zero-meaning, , where and are the mean student and teacher logits).
- Conclude: the gradient shrinks by as grows, so multiplying the soft KL loss by keeps its gradient magnitude comparable to the hard cross-entropy gradient as varies.
Common mistakes
- Forgetting one of the two factors (thinking the gradient scales as instead of and scaling the KL term by instead of ), which under-weights the teacher signal at by .
- Omitting the factor in code when tuning temperature , which changes the effective balance between hard and soft losses every time changes.
How long your answer should be
Four to five lines of calculus and two sentences of interpretation; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in ML systems and evaluation: How do partial dependence plots (PDP) and LIME explain a black-box model, why do correlated features mislead both via out-of-distribution extrapolation, and how do individual conditional expectation (ICE) plots fix a separate weakness of PDPs?
Next in ML systems and evaluation: In a hospital study of 1,000 patients split evenly between mild () and severe () cases, recovery rates for treated () vs untreated () patients are vs among mild cases and vs among severe cases. How do these numbers exhibit Simpson’s paradox, what is the causal DAG and backdoor-adjusted effect , and why does adjusting for a collider instead of a confounder introduce bias?