Self-Distillation & Internal Knowledge Transfer
When the model teaches itself: self-distillation within a single network, deeper layers teaching shallower ones, auxiliary classifiers as teachers, label refinery, and why self-distillation improves even large models.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- Be Your Own Teacher (BYOT)
- Layer-Wise Self-Distillation
- Label Refinery
- Snapshot Distillation
- PS-KD: Progressive Self-Knowledge Distillation
- Why Self-Distillation Works
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Explain how a model can improve by teaching itself.
- Describe BYOT's auxiliary classifier mechanism.
- Derive label refinery's iterative self-improvement.
- Connect self-distillation to implicit regularization.
- Identify when self-distillation provides meaningful gains.
Notation
- — feature at layer
- — auxiliary classifier at layer
- — predictions from previous epoch/checkpoint
Core Intuition
Self-distillation seems paradoxical: how can a model teach itself something it doesn't already know? The answer: knowledge is distributed unevenly. Deep layers have better features than shallow ones. Late-training predictions are better than early-training ones. By making the model's "better parts" teach its "worse parts," overall performance improves. It's like revising your own notes — you consolidate and improve understanding.
Self-Distillation
Be Your Own Teacher (BYOT)
Zhang et al. (2019): Attach auxiliary classifiers at intermediate layers:
Training objective: Each intermediate classifier is distilled from the final (deepest) classifier:
Effect on the backbone:
- Intermediate features are pushed to be more discriminative (they must support classification).
- The final classifier provides smooth labels to intermediate classifiers.
- Backbone features improve at ALL layers (not just the final one).
Deployment: Remove auxiliary classifiers. Only the backbone + final head is used. But the backbone is better because of the self-distillation training.
Layer-Wise Self-Distillation
Deeper layers teach shallower ones:
where is stop-gradient (deeper layer is treated as the "teacher").
DINO/BYOL connection: Self-supervised methods like DINO use a similar principle — the momentum encoder (EMA of the student) acts as the teacher. This IS self-distillation in the temporal dimension.
Effect: Each layer tries to approximate the representation of the next layer, creating a hierarchical regularization that encourages smooth feature progression.
Label Refinery
Bagherinezhad et al. (2018): Iteratively improve labels using the model's own predictions:
- Epoch 1: Train on hard labels → get predictions .
- Epoch 2: Train on soft labels (+ hard label) → get predictions .
- Epoch : Train on → get .
Why it helps: The model's own predictions are smoother than hard labels (implicit label smoothing). Each generation produces better-calibrated soft labels for the next.
Connection to born-again: Label refinery is born-again networks within a single training run (using checkpoints instead of retrained models).
Snapshot Distillation
Use historical checkpoints as teachers:
where is the model's prediction steps ago.
Exponential moving average (EMA) teacher:
The EMA model is smoother (averaged over many steps) and provides better-calibrated soft labels than the current model.
PS-KD: Progressive Self-Knowledge Distillation
Kim et al. (2021): Progressively increase self-distillation strength during training:
where increases from 0 to over training.
Schedule: (linear increase).
Rationale:
- Early training: model predictions are poor → don't trust them ().
- Late training: model predictions are good → use them as soft labels ().
Why Self-Distillation Works
Theoretical perspectives:
-
Regularization: Soft labels from the model prevent overconfidence on individual training examples.
-
Implicit ensemble: EMA teacher or historical predictions average over many optimization steps → smoother than any single checkpoint.
-
Dark knowledge from itself: The model's soft predictions on CORRECT examples encode learned similarities (which wrong classes are likely), providing richer gradient signal.
-
Feature compression: Intermediate distillation forces early layers to compress information efficiently (can't rely on later layers fixing bad representations).
-
Calibration: Self-distilled models are better calibrated (confidence matches accuracy).
Common Pitfalls
Pitfall 1. Self-distilling from the first epoch's predictions. Early predictions are near-random — using them as soft labels adds noise, not signal. Wait until the model has reasonable accuracy (after 20-30% of training).
Pitfall 2. Using (only self-distillation, no hard labels). Without grounding in hard labels, the model can drift (accumulate errors across self-distillation steps). Always maintain some hard label signal.
Pitfall 3. Self-distilling a model that's already overconfident. If the model outputs near-one-hot predictions, self-distillation provides minimal benefit (soft labels are already near-hard). Use temperature or earlier checkpoints.
Summary
- BYOT: Deeper layers teach shallower via auxiliary classifiers.
- Label refinery: Iteratively improve labels from own predictions.
- Snapshot distillation: EMA or historical checkpoints as teachers.
- PS-KD: Progressive increase of self-distillation strength.
- Why it works: Regularization, implicit ensemble, calibration improvement.
- Typical gain: 0.5-1.5% accuracy improvement with zero additional teacher cost.
Exercises
Exercise 1. For a 50-layer ResNet with BYOT classifiers at layers 16, 33, 50: estimate the additional training cost (FLOPs for auxiliary classifiers vs backbone).
Exercise 2. Implement label refinery for CIFAR-10 over 5 epochs. Track calibration (ECE) across iterations.
Exercise 3. Compare EMA teacher () vs snapshot teacher ( steps) in terms of staleness and smoothness.
Exercise 4. Prove that self-distillation with temperature is equivalent to label smoothing with a specific smoothing parameter (derive the equivalence).
Exercise 5. Design a self-distillation strategy for GPT-2: what would the "auxiliary classifiers" be, and how would you apply layer-wise self-distillation to a causal language model?