Knowledge Distillation Performs Partial Variance Reduction

Mher Safaryan, Alexandra Peste, Dan Alistarh

TL;DR

This paper reveals that Knowledge Distillation (KD) works by acting as a partial variance reduction mechanism. By using a teacher model's gradients to "cancel out" noise in the student's stochastic gradients, KD allows for cleaner convergence and lower training loss, effectively functioning like a specialized version of the SVRG optimization algorithm.

What Problem Does This Paper Address?

Knowledge Distillation—the process of training a small "student" model to mimic a larger "teacher" model—is a cornerstone of modern AI. We know it works, but the why has remained somewhat mysterious. Most theories focus on the "dark knowledge" in soft labels or the idea that teachers provide a smoother decision surface.

However, these explanations don't fully account for how KD interacts with the actual engine of training: Stochastic Gradient Descent (SGD). In standard SGD, we use small batches of data to estimate the true gradient, which introduces "noise" (variance). This noise can slow down convergence or prevent the model from reaching a better optimum. The authors of this paper ask: Does KD help the student by cleaning up this optimization noise?

Methods

The authors bridge the gap between KD and classical optimization theory. Their key move is reformulating the KD gradient. For linear and deep linear models, they show that the gradient of the distilled student model can be written as:

$$\nabla f_{student} \approx \nabla f(x) - \lambda \nabla f(\theta)$$

Where $x$ is the student, $\theta$ is the teacher, and $\lambda$ is the distillation weight.

This looks remarkably like SVRG (Stochastic Variance Reduced Gradient), a famous optimization technique that uses a "reference" gradient to reduce noise. The difference is that while SVRG uses a perfect, full-batch gradient as a reference, KD uses the teacher’s stochastic gradient.

The researchers provide a rigorous convergence analysis under two standard settings:

  1. Strongly quasi-convex losses (common in simpler models).
  2. Non-convex losses satisfying the Polyak-Łojasiewicz (PL) condition (a more realistic proxy for deep learning landscapes).

They also introduce an "Unbiased KD" variant that adds a correction term to achieve full variance reduction, and they extend their theory to "Distillation for Compression," where the student is a pruned or compressed version of the teacher.

Key Insights and Ideas

  • KD as Noise Cancellation: Think of the teacher as a pair of noise-canceling headphones. Because the student and teacher are evaluated on the same data batch, their gradient noise is highly correlated. Subtracting the teacher's gradient "cancels out" the shared noise, leaving a cleaner signal for the student to learn from.
  • The "Partial" in Partial Variance Reduction: Unlike traditional variance reduction, KD doesn't usually eliminate noise completely. This is because the teacher isn't perfect (it isn't at the true global optimum). The "better" the teacher, the more noise it can cancel.
  • The Goldilocks Distillation Weight ($\lambda$): The theory predicts—and experiments confirm—that there is an optimal value for $\lambda$. If $\lambda$ is too small, you don't get the variance reduction benefit. If it's too large, the "bias" of the teacher (its own errors) starts to overwhelm the student.
  • Self-Distillation Logic: This explains why "self-distillation" (where a model acts as its own teacher from a previous epoch) works. Even if the architecture is the same, the older, more stable version of the model helps the current version navigate the optimization landscape with less noise.

Key Results

  • Convergence Rates: The authors prove that KD preserves the linear convergence speed of SGD but "dampens" the noise term ($\sigma^2$). The reduction is proportional to how close the teacher is to the optimum.
  • Empirical Validation: In experiments on MNIST and CIFAR-10, the training loss curves show a clear U-shape relative to $\lambda$. As predicted, there is a "sweet spot" where KD significantly outperforms standard SGD.
Train Loss vs Lambda
  • Gradient Correlation: The authors measured the cosine similarity between the "true" KD gradient and their simplified linear approximation. They found high correlation (often >0.9), suggesting their theoretical model holds up well even for non-linear neural networks.
Gradient Correlation and SNR

Limitations and Future Work

  • Linear Approximation: While the authors provide evidence that their formula works for deep nets, the math is strictly exact only for linear and "deep linear" models. The complex non-linearities of modern transformers or CNNs might introduce dynamics not captured here.
  • Convexity Assumptions: Much of the proof relies on quasi-convexity or the PL condition. While these are standard in optimization papers, the wild, non-convex nature of massive neural networks remains a frontier.
  • Compression Constraints: Their analysis of compressed models requires the compression operator (like pruning or quantization) to be "unbiased," which isn't always the case for popular methods like Top-K pruning.

The authors suggest that future work could involve designing new, "optimization-aware" distillation losses that explicitly aim to maximize this noise-canceling effect.

Summary updated

BibTeX
@inproceedings{safaryan2023knowledge,
  author = {Mher Safaryan and Alexandra Peste and Dan Alistarh},
  title = {{Knowledge Distillation Performs Partial Variance Reduction}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=tzxP9Rx0LV},
}
Figure