Chapter 43 of 57
Temperature in Distillation, and Why the Loss Is Multiplied by T²
Created Sep 19, 2026 Updated Oct 25, 2026
In the classic distillation loss you will usually see a temperature and, in front of the soft-target term, a factor of :
L = α · CE(y, q₁) + (1 − α) · T² · L_soft, L_soft = KL(p_T ‖ q_T)
Only the second term runs at temperature T: the hard-label term compares the student's unsoftened q₁ with the label.
Both parts get misread. The temperature here softens two distributions at once, not one, and the is not a second knob: it compensates for the way changing changes the size of the gradient. is a real hyperparameter; is a rescaling convention attached to it, not a term with a life of its own.
The same operation as the sampling temperature, in a different job. Dividing logits by T before the softmax is exactly what happens in LLM decoding; the arithmetic does not know which field it is in. What changes is the use. In decoding, one distribution is reshaped and a token is sampled from it. In distillation nothing is sampled: two distributions are softened, the teacher's and the student's, and the loss compares them. Raising T makes the teacher's ranking of the wrong classes legible — the dark knowledge — and asks the student to reproduce it.
Where the comes from. Two factors of appear in the soft term, and they have different origins. Differentiating with respect to a student logit gives one of them directly:
The second is not in the derivative but in the quantity it contains. At a high temperature both distributions flatten, so the probability differences themselves shrink roughly as : with classes and logits centred to mean zero, , where are the teacher's logits. Together:
So the soft-target gradient scales roughly as . Uncorrected, raising the temperature would quietly turn the distillation term down, and every temperature sweep would be a learning-rate sweep in disguise. Multiplying by compensates for that shrinkage and keeps the two terms' gradients comparable as moves — approximately, not exactly, because the result is a high-temperature approximation and the distributions change shape non-linearly below it.
On the teacher's real logits the raw gradient falls by two orders of magnitude between and ; scaled by it holds to within 1.4× from upward, and still moves 3.4× across the whole range.
That also says what the two ends of the range are. As grows, both distributions flatten and the raw goes to zero; what stays finite is , which approaches a squared error between the teacher's and the student's centred logits. So high-temperature distillation is logit regression, is cross-entropy against the teacher's probabilities, and for the temperature interpolates between them — below 1 it sharpens instead, and the soft targets lose the thing they were for.
And the loss is cross-entropy either way. KL splits into cross-entropy minus the teacher's own entropy:
KL(p ‖ q) = −H(p) + CE(p, q)
The teacher is frozen, so H(p) is a constant: the two objectives have identical gradients. Nothing here is distillation-specific — it is the maximum-likelihood cross-entropy you already use, pointed at a soft target instead of a one-hot one.
And in a measured sweep the knob is mild. On a ten-class image problem (the widget's second view) was worth 2.7 percentage points over , and gave a quarter of that back: the movement is the step from "almost one-hot" to "actually softened", not a sharp optimum. Whether that holds with a hundred thousand classes is a different measurement.
So: one temperature, applied to both sides, with a T² that exists to make temperature sweeps mean what they appear to mean. The measured sweep, and what happens when the label term α is mixed back in, are in Knowledge Distillation: What a Teacher Actually Teaches.