Comparing Kullback-Leibler Divergence and Mean Squared Error Loss in Knowledge Distillation

Taehyeon Kim, Jaehoon Oh, Nakyil Kim, Sangwook Cho, Se-Young Yun

Introduction

Knowledge Distillation (KD) has become a cornerstone of model compression, enabling the transfer of knowledge from a large, high-capacity "teacher" model to a smaller, efficient "student" model. Traditionally, this process relies on minimizing the Kullback-Leibler (KL) divergence between the softened probability distributions of the two models. However, the fundamental reasons behind the effectiveness of this "softening" and whether KL divergence is the optimal loss function remain subjects of active research. This paper, presented at IJCAI-21, critically examines these assumptions, proposing that direct logit matching via Mean Squared Error (MSE) may often be a superior alternative.

Methodology: KL Divergence vs. MSE

The standard KD approach involves a temperature hyperparameter, $\tau$, which smooths the output probability distributions. The researchers performed a rigorous gradient analysis of the KL divergence loss, revealing that its behavior shifts significantly with $\tau$. At high temperatures, the gradient approaches a biased version of the difference between teacher and student logits (logit matching), while at low temperatures, it behaves more like standard label matching.

To address the inherent complexities and potential biases of KL divergence, the authors propose using Mean Squared Error (MSE) directly on the raw logit vectors: $L_{MSE} = ||z^s - z^t||_2^2$. This approach eliminates the need for the temperature hyperparameter in the distillation loss and aims for direct alignment of the models' internal representations.

Comparison of Knowledge Distillation frameworks using KL divergence loss (top) and Mean Squared Error loss (bottom).

Key Insights: The Bias of KL Divergence

A critical finding of this work is that KL divergence is mathematically biased. The authors demonstrate the existence of a "hidden term" ($\delta_\infty$) in the KL gradient that prevents the student from perfectly matching the teacher's logits. This term causes a shift in the mean of the student's logit vector, which can impede the learning process. In contrast, MSE-based logit matching is unbiased, allowing for a more precise alignment.

Histograms showing the distribution of logits for the teacher (left) and the student trained with KL divergence at various temperatures (right), illustrating the distribution shift.

Furthermore, the choice of $\tau$ represents a trade-off. High $\tau$ encourages the student to mimic the teacher's entire distribution (logit matching), while low $\tau$ focuses the student on the teacher's primary class prediction (label matching). Visualization of the penultimate layer representations suggests that KL divergence tends to "elongate" latent space clusters, whereas MSE maintains a more cohesive geometry similar to the teacher's.

Experimental Results

The proposed MSE-based distillation was validated across several benchmarks:

  • CIFAR-100: In various teacher-student pairings (e.g., Wide-ResNet family), MSE consistently outperformed KL-based KD. For instance, a WRN-16-2 student achieved 75.54% accuracy with MSE, compared to 73.53% with standard KD.
  • Sequential Distillation: For large capacity gaps between models, the authors found that distilling through an intermediate "assistant" model using MSE was highly effective.
  • ImageNet: Results on ImageNet were more nuanced. While MSE was competitive, high-temperature KL ($\tau=20$) achieved the highest accuracy (77.52% vs. 75.84% for MSE). This suggests that on massive datasets, the regularization provided by the KL bias might offer some benefit.

Conclusion and Limitations

While MSE-based logit matching offers a simpler and often more effective alternative to KL divergence, it is not without limitations. Its primary weakness is sensitivity to noise; because MSE forces exact logit matching, it can lead the student to perfectly mimic a "noisy" teacher's errors. In such scenarios, low-temperature KL divergence remains superior as it effectively filters out "negative information" from incorrect logit distributions. Future research will likely focus on robust sequential distillation strategies and further exploring the geometric implications of different loss functions in the latent space.

Summary updated

BibTeX
@inproceedings{kim2021comparing,
  author = {Taehyeon Kim and Jaehoon Oh and Nakyil Kim and Sangwook Cho and Se-Young Yun},
  title = {{Comparing Kullback-Leibler Divergence and Mean Squared Error Loss in Knowledge Distillation}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.24963/ijcai.2021/362},
}
Figure