Exploring the Connection between Knowledge Distillation and Logits Matching

Defang Chen, Can Wang, Yan Feng, Chun ChenarXiv 2021 · OpenReview

Abstract: Knowledge distillation is a generalized logits matching technique for model compression. Their equivalence is previously established on the condition of $\textit{infinity temperature}$ and $\textit{zero-mean normalization}$. In this paper, we prove that with only $\textit{infinity temperature}$, the effect of knowledge distillation equals to logits matching with an extra regularization. Furthermore, we reveal that an additional weaker condition -- $\textit{equal-mean initialization}$ rather than the $\textit{zero-mean normalization}$ already suffices to set up the equivalence. The key to our proof is we realize that in neural networks with the cross-entropy loss and softmax activation, the mean of back-propagated gradient on logits always keeps zero.

Introduction

In the field of deep learning, model compression is essential for deploying high-performance architectures on resource-constrained devices. Two fundamental techniques have emerged to facilitate this: Logits Matching (LM) and Knowledge Distillation (KD). Logits Matching involves minimizing the Mean Squared Error (MSE) between the raw, unnormalized outputs (logits) of a large "teacher" model and a smaller "student" model. Knowledge Distillation, popularized by Hinton et al. (2015), instead minimizes the KL-divergence between the softened probability distributions of the two models, controlled by a temperature hyperparameter $\tau$.

While it has long been accepted that LM is a special case of KD under the limit of infinite temperature, the exact mathematical conditions required for this equivalence have often been overlooked. This research note provides a rigorous derivation to bridge these two methods, revealing the specific regularization terms and normalization conditions that define their relationship.

Theoretical Framework

To establish the connection, the analysis focuses on the gradients of the loss functions with respect to the student's logits ($z_i^s$). The core of the proof involves taking the limit of the KD loss as the temperature $\tau \to \infty$. By applying a Taylor expansion to the exponential functions within the softmax activation, we can simplify the gradient of the KD loss.

The Regularized Logits Matching Loss

The primary mathematical finding is that at infinite temperature, KD does not simply collapse into standard Logits Matching. Instead, it becomes equivalent to a Regularized Logits Matching Loss ($L_{LM_r}$):

$$L_{LM_r} = \frac{1}{2k} \|z^t - z^s\|_2^2 - \frac{1}{2k^2} \left( \sum_{j=1}^k z^s_j - \sum_{j=1}^k z^t_j \right)^2 + \text{Constant}$$

This formula demonstrates that the gradient of $\tau^2 L_{KD}$ as $\tau \to \infty$ is identical to the gradient of this regularized MSE loss. The "extra" term in the equation penalizes the difference between the sum of the student's logits and the sum of the teacher's logits. This reveals that the temperature parameter in KD acts as a mechanism to control how closely the loss function mimics a simple MSE on raw outputs.

Conditions for Equivalence

Historically, it was believed that "zero-mean normalization" (ensuring the average value of logits for both models is zero) was necessary for KD and LM to be equivalent. However, this paper reveals a more nuanced requirement: equal-mean initialization.

If the logits are equal-mean normalized—meaning the average value of the logits is the same for both the teacher and the student—the extra regularization term in the $L_{LM_r}$ equation disappears, resulting in a direct equivalence to standard Logits Matching. The author identifies a critical property of neural networks using cross-entropy loss and softmax activation: the mean of the back-propagated gradient on logits always remains zero. This property suggests that the weaker condition of equal-mean initialization is sufficient to maintain equivalence throughout training.

Knowledge Distillation as Adaptive Label Smoothing

Beyond the comparison with Logits Matching, this research offers a unified perspective on output-based regularization. Standard label smoothing regularizes a model by mixing hard labels with a uniform distribution. This paper demonstrates that KD, when combined with standard cross-entropy, functions as a form of adaptive label smoothing.

In this framework, the "smoothing" distribution is not uniform but is instead the teacher model's predicted distribution. This allows the regularization to adapt to the specific characteristics of each input. Furthermore, the paper connects KD to other techniques such as Confidence Penalty and Entropy-based regularization, suggesting they all belong to a family of methods that can be unified using skew-Jensen divergence.

Conclusion

By providing a formal derivation of the relationship between Knowledge Distillation and Logits Matching, this work clarifies the role of temperature and logit normalization in model compression. The discovery of the regularized MSE loss and the sufficiency of equal-mean initialization provides a deeper theoretical foundation for KD. These insights suggest that viewing KD as a form of adaptive output regularization may lead to the development of new, more efficient regularizers that do not necessarily require the overhead of a pre-trained teacher model.

Summary updated

Abstract

Knowledge distillation is a generalized logits matching technique for model compression. Their equivalence is previously established on the condition of $\textit{infinity temperature}$ and $\textit{zero-mean normalization}$. In this paper, we prove that with only $\textit{infinity temperature}$, the effect of knowledge distillation equals to logits matching with an extra regularization. Furthermore, we reveal that an additional weaker condition -- $\textit{equal-mean initialization}$ rather than the $\textit{zero-mean normalization}$ already suffices to set up the equivalence. The key to our proof is we realize that in neural networks with the cross-entropy loss and softmax activation, the mean of back-propagated gradient on logits always keeps zero.
BibTeX
@misc{chen2021exploring,
  author = {Defang Chen and Can Wang and Yan Feng and Chun Chen},
  title = {{Exploring the Connection between Knowledge Distillation and Logits Matching}},
  year = {2021},
  eprint = {2109.06458},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.06458},
}

Loading related content...

Figure