In knowledge distillation, the student minimises L=(1−α)LCE(y,pS)+αT2KL(pT(T)∥pS(T)), where p(T)=softmax⁡(z/T) uses temperature T>1. How do you derive the gradient of KL(pT(T)∥pS(T)) with respect to student logit zi in the high-temperature limit to show why the T2 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 1/T2.

Key idea

Differentiating KL(pT(T)∥pS(T)) with respect to student logits zi brings out a factor of 1/T, and in the high-temperature limit T≫∣zi∣ the probability difference (pS,i(T)−pT,i(T)) itself scales as 1/T, so the gradient scales as 1/T2 unless multiplied by T2.

Steps

  1. Write the KL term up to a constant independent of the student: KL(pT(T)∥pS(T))=−∑kpT,k(T)ln⁡pS,k(T)+const, where pS,k(T)=exp⁡(zk/T)∑jexp⁡(zj/T).
  2. Differentiate with respect to student logit zi by the chain rule: since ∂∂(zi/T)(−∑kpT,k(T)ln⁡pS,k(T))=pS,i(T)−pT,i(T), dividing by T gives ∂KL∂zi=1T(pS,i(T)−pT,i(T)).
  3. Take the high-temperature limit (T≫∣zj∣,∣vj∣, where vj are teacher logits): using eu≈1+u, for zero-mean logits (∑jzj=∑jvj=0) we get pS,i(T)≈1+zi/TK and pT,i(T)≈1+vi/TK, where K is the number of classes.
  4. Substitute into the gradient: ∂KL∂zi≈1KT2(zi−vi) (and without zero-meaning, 1KT2[(zi−zˉ)−(vi−vˉ)], where zˉ and vˉ are the mean student and teacher logits).
  5. Conclude: the gradient shrinks by 1/T2 as T grows, so multiplying the soft KL loss by T2 keeps its gradient magnitude comparable to the hard cross-entropy gradient as T varies.

Common mistakes

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 (Z=0) and severe (Z=1) cases, recovery rates for treated (T=1) vs untreated (T=0) patients are 90/100 vs 320/400 among mild cases and 200/400 vs 40/100 among severe cases. How do these numbers exhibit Simpson’s paradox, what is the causal DAG and backdoor-adjusted effect P(Y=1∣do⁡(T=1))−P(Y=1∣do⁡(T=0)), and why does adjusting for a collider instead of a confounder introduce bias?