Skip to content

Distilling the Knowledge in a Neural Network

Skip →Pruning LLMs (SparseGPT, Wanda, Minitron)
LLM stage 2 #12extendedfundamentalpaperrubric 7/122015 · NIPS 2014 Deep Learning Workshop · ~25 min

Geoffrey Hinton, Oriol Vinyals, Jeff Dean

Status

TL;DR. A large model (or an ensemble) assigns small but meaningful probabilities to wrong answers. Raising the softmax temperature makes those visible, and training a small model to match them transfers much of the large model’s generalisation. The paper calls this distillation.

Soften both teacher and student with a temperature TT:

qi=exp⁡(zi/T)∑jexp⁡(zj/T).q_i = \frac{\exp(z_i / T)}{\sum_j \exp(z_j / T)}.

The student is trained on a weighted sum of two cross-entropies: one with the teacher’s soft targets at temperature TT, and one with the true labels at T=1T = 1. Since the soft-target gradients scale as 1/T21/T^2, the soft term is multiplied by T2T^2. The hard-label term gets a considerably lower weight. In the high-temperature limit, distillation reduces to matching logits.

On MNIST, a large regularised net makes 67 test errors and a small unregularised net 146. Adding soft targets from the large net at T = 20 brings the small net to 74. On speech recognition (85M-parameter acoustic model, 14,000 output labels, Table 1), the baseline gets 58.9% frame accuracy and 10.9% WER, a 10-model ensemble 61.1% and 10.7%, and a single distilled model 60.8% and 10.7%, transferring more than 80% of the ensemble’s frame-accuracy gain. On JFT, 61 specialist models raise the baseline’s test accuracy from 25.0% to 26.1%.

  • Alongside: LoRA and QLoRA adapt a big model cheaply; distillation instead makes a small one.
  • Inference: a distilled student is a natural draft model for speculative decoding.
  • IR: distilling cross-encoder scores into late-interaction retrievers is central to ColBERTv2.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    A teacher produces logits (6, 3, 0) over three classes. Compute its softmax at temperature 1 and at temperature 3. Then use the paper's gradient of the soft-target cross-entropy to explain why the soft loss must be multiplied by T squared when it is combined with the hard-label loss, and what the high-temperature limit reduces to.

    What a strong answer covers
    • T = 1: exp(6), exp(3), exp(0) normalise to about (0.950, 0.047, 0.002). T = 3: logits become (2, 1, 0), giving about (0.665, 0.245, 0.090). The ranking among wrong classes becomes visible.
    • With student logits z and teacher logits v, ∂C/∂z_i = (1/T)(q_i − p_i), where q and p are the student and teacher softmaxes at temperature T.
    • For large T and zero-mean logits over N classes this is about (1/(N T²))(z_i − v_i), so soft-target gradients shrink as 1/T². Multiplying by T² keeps the soft and hard terms in proportion when T is changed.
    • In that limit distillation equals minimising ½(z_i − v_i)², i.e. matching logits, which is what earlier logit-matching methods did.
  2. Mechanism

    Why do soft targets carry more information per example than hard labels? Use the paper's MNIST experiment with all 3s removed from the transfer set and its speech experiment with 3% of the data to explain what is being transferred, and how temperature trades off noisy negative logits against useful ones.

    What a strong answer covers
    • Relative probabilities of wrong classes encode similarity (which 2s look like 3s), so each example constrains the student much more than a one-hot label. The paper notes that high-entropy soft targets give much less gradient variance between cases, so the student can often train on much less data with a much higher learning rate.
    • MNIST without 3s: the student makes 206 errors, 133 of them on the 1010 test 3s. Raising the 3 bias by 3.5 gives 109 errors and 98.6% of 3s correct, although it never saw a 3. The knowledge came only through soft probabilities on other digits.
    • Speech with 3% of the data: hard targets overfit and stop at 44.5% frame accuracy; soft targets reach 57.0%, close to the 58.9% of the full-data baseline, without early stopping.
    • Temperature: at low T, very negative logits are ignored, which helps if they are noise; at high T, they are matched, which helps if they carry knowledge. With a very small student (30 units per layer), T between 2.5 and 4 worked best.
  3. Design

    Design a distillation recipe that turns a 7B LLM listwise reranker into a 100M-parameter cross-encoder for first-stage reranking. Specify the transfer set, the soft targets, temperature and loss weighting, and how you would check that the student kept the teacher's knowledge rather than just its top-1 choices.

    What a strong answer covers
    • Transfer set: real queries with retrieved candidate lists, not only labelled pairs, since soft targets do not need labels. Include hard negatives so the teacher's relative scores are informative.
    • Targets: a softmax over the teacher's scores for the candidates of each query, at temperature T > 1, with a KL or cross-entropy loss; add a hard-label loss with a much lower weight, and scale the soft loss by T² as the paper prescribes.
    • Tune T on a dev set; the paper found that a small student prefers intermediate temperatures.
    • Checks: nDCG@10 and rank correlation with the teacher over the full list, not just top-1 agreement, plus out-of-domain queries to see whether the similarity structure transferred.

Done with this page?

Status