Controlling the Quality of Distillation in Response-Based Network Compression

The performance of a distillation-based compressed network is governed by the quality of distillation. The reason for the suboptimal distillation of a large network (teacher) to a smaller network (student) is largely attributed to the gap in the learning capacities of given teacher-student pair. While it is hard to distill all the knowledge of a teacher, the quality of distillation can be controlled to a large extent to achieve better performance. Our experiments show that the quality of distillation is largely governed by the quality of teacher's response, which in turn is heavily affected by the presence of similarity information in its response. A well-trained large capacity teacher loses similarity information between classes in the process of learning fine-grained discriminative properties for classification. The absence of similarity information causes the distillation process to be reduced from one example-many class learning to one example-one class learning, thereby throttling the flow of diverse knowledge from the teacher. With the implicit assumption that only the instilled knowledge can be distilled, instead of focusing only on the knowledge distilling process, we scrutinize the knowledge inculcation process. We argue that for a given teacher-student pair, the quality of distillation can be improved by finding the sweet spot between batch size and number of epochs while training the teacher. We discuss the steps to find this sweet spot for better distillation. We also propose the distillation hypothesis to differentiate the behavior of the distillation process between knowledge distillation and regularization effect. We conduct all our experiments on three different datasets.


Introduction
Wider and deeper deep learning (DL) models have helped us build more and more sophisticated systems across a broad range of areas LeCun et al. [2015]. But the huge computation and memory requirements of these models create hurdles in its deployment on edge devices Simonyan and Zisserman [2015], Howard et al. [2017]. A number of network compression techniques have been developed to compress large DL models into computationally efficient models with comparable performance, like model quantization Wu et al. [2016], model binarization Courbariaux et al. [2016], parameter sharing Han et al. [2015], Wang and Yoon [2021], low-rank factorization Denton et al. [2014], Yu et al. [2017], convolution filter compression Zhai et al. [2016] and knowledge distillation (KD) Buciluǎ et al. [2006], . KD has two basic steps, knowledge extraction and distillation. Knowledge extraction can be response-based, feature-based, or relation-based and its distillation can be offline, online, or self-distillation Gou et al. [2021]. In this paper, we explore the KD process that uses a teacher's response to distill the knowledge in an offline manner to achieve network compression. Figure 1: (a) sweet spot between batch size and number of epochs for a given teacher-student pair for effective KD (b) and (c) difference in teacher's response in presence and absence of similarity information, respectively.

Figure 2: The distillation hypothesis
Our experiments suggest that the quality of distillation is largely controlled by the amount of "similarity information" about classes that a teacher provides in its responses. In other words, teachers provide a distribution over the possible class labels for any given example. A highly-confident teacher produces a "hard" result that has a peak response for exactly one class, whereas a less-confident teacher provides a more spread, higher-entropy distribution. We find, somewhat counter-intuitively, that the less-confident teacher provides the student more information about the relationships between classes through the non-zero responses to the other classes. We find that careful training of the teacher can largely offset the negative effect of the gap between models. Fig. 1 (a) presents the idea. For a given teacher-student pair of any capacity gap, we can find a balance between batch size and number of epochs of training a teacher to retain similarity information in its response. Fig. 1 (b) and (c) show the fundamental difference in the quality of a teacher's response in the presence and absence of similarity information, respectively. A good response has relevant information about similarity between two classes and a poor response lacks this information. The RBKD process is fast and effective with the similarity-rich response as it learns about more than one class from a single input -one example-many class learning. It requires fewer examples per class to learn about the whole distribution of examples. In contrast, the process is slow, less effective, and requires more examples per class when similarity information is absent.
We also observe that for a fixed student network, as the teacher model becomes more powerful, wider and deeper in size, it loses the rich similarity information present in the soft labels and behaves like a label smoothing (LS) Müller et al. [2019], Szegedy et al. [2016 process. We use this observation to differentiate the nature of the distillation process between KD and regularization effect through the distillation hypothesis shown in Fig. 2. We argue that any distillation process with little or no similarity information in the teacher's response brings more of a regularization effect than the distillation effect and when it completely lacks similarity information, the KD process is equivalent to the LS.
Our contributions are as follows: (i) We show that rich similarity information in teacher's response can facilitate one example-many classes learning and accelerates KD. (ii) We argue that the gap in teacher-student pair is not the root cause or the dominating factor of poor distillation, and provide a method to carefully train any teacher to retain more similarity information in its response to achieve better distillation. (iii) We also propose the distillation hypothesis to understand the underlying nature of the distillation process. Buciluǎ et al. [2006] devise a method of network compression by distilling the knowledge of a teacher network, input to the softmax layer, to a student network.  popularized this idea by introducing a temperature term T ,

Related Work
class probabilities (q i ) and logits (z i ), in softmax that controls the softness of response. Increasing  Table 1: The LS labels for different input images of same class at α LS = 0.6. It shows that the distribution of soft-labels in the absence of similarity information. This distribution promotes one example-one class learning.
T decreases q i for correct class, indicating decrease in the confidence of network's response, while increasing q i for incorrect classes, indicating increase in similarity information in network's response.
The response-based network compression is a very effective tool to instill the knowledge of a cumbersome model into an efficient model to achieve uncompromised network compression. A common understanding is that a more powerful teacher should be able to provide more knowledge to its student. But it is observed that wider and deeper networks do poor distillation Mirzadeh et al. [2020], Yuan et al. [2020], Gao et al. [2020]. Kim and Kim [2017] and Müller et al. [2019] ascribe the effectiveness of RBKD being similar to the effectiveness of LS. Ding et al. [2019] explain RBKD as the regularization effect brought about by the response of the teacher model. However, the RBKD process relies on the teacher's response and can not properly explain the hidden-layer supervision Gou et al. [2021]. We argue that whether RBKD behaves as regularization, distillation, or LS, depends on the presence of similarity information in the teacher's response. This, in tern, affects the extent of network compression that can be achieved by this method.
Mirzadeh et al. [2020] attribute the gap in learning capacities of teacher-student pair as the only reason for poor distillation, and propose a teacher assistant (TA) model, with a learning capacity in between teacher and student, to address this problem. The knowledge from the teacher is routed through one or more TA(s) to the student. While TAs improve the distillation performance but it also makes the whole process of network compression computationally expensive.
With a similar hypothesis, Yuan et al. [2020] propose a teacher-free KD (TFKD) process to reduce the gap between teacher-student pairs. The TFKD process distills its knowledge to itself during training. Theoretically, TFKD reduces the gap to zero, but its knowledge is limited by its learning capacity and extent of training. It also deviates from the network compression task. Gao et al. [2020] propose residual KD to distill the knowledge by introducing an assistant model to learn the residual error between teacher and assistant models. This method also tries to reduce the gap between teacher-student pairs. This method is also effective, but it does bring additional computational costs with added networks to achieve network compression.
All the above methods try to find a solution to reduce the gap between the teacher-student pair. They focus specifically on the distillation process and not on the knowledge inculcation process. In this paper, we show that the quality of knowledge distillation can be controlled by controlling the quality of knowledge inculcation in a teacher. We also explain how the nature of KD changes with a change in similarity information in the teacher's response with the distillation hypothesis.

Label Smoothing
The LS process uses a less confident form of one-hot label to train a model. It decreases the model confidence about the correct class and treats all other classes as equal, providing no similarity information Müller et al. [2019], Szegedy et al. [2016]. The LS labels are computed as, where, y c is the one-hot vector, c is the number of classes, and 1/c is a uniform distribution. Examples are shown in Table 1. To calculate the cross-entropy over these labels, we denote the true soft-label distribution q(c|x) (x is input) as q for LS process, q for RBKD process and use p to denote distribution p(c|x) generated by model Yuan et al. [2020]. The loss function is then,  Table 2: Soft-labels generated by small capacity teacher model with 3 hidden layers on MNIST data.

Input class
Soft-labels by large learning capacity teacher  Table 3: Soft-labels generated by a large capacity teacher model with 6 hidden layers on MNIST data where H(u) is a fixed entropy value of uniform distribution and D KL is the Kullback-Leibler divergence (KL), The soft-labels on the LS process is shown in Table 1. The LS process use a fixed distribution to produce "hard" result that has a peak response for exactly one class, and assigns all other classes equal value without considering the similarity between classes. This paradigm promotes one example-one class learning ( Fig. 1 (c)) i.e. each example provides useful information only about its class and treat all other classes equally.

Response-Based Knowledge Distillation
The RBKD process has the teacher produce probabilistic distribution for each class at a temperature T . It contains rich similarity information between classes to support one examples-many classes learning ( Fig. 1 (b)) . These information-rich labels are used to distill the knowledge to the student by minimizing the weighted sum of KL divergence and cross-entropy losses as, where H(p, q), p, p T , and p t T denote the cross-entropy loss for student with true labels (q), output of student model, output of student model softened at T and output of teacher model softened at T , respectively. α KD is the contribution factor for loss function.
The loss functions of RBKD and LS processes have similar formulations as shown in Equation (2) and (4), but they use different methods for generating soft-labels. The only difference is the p t T in D KL (p t T , p T ), which is generated by a teacher model, and u in D KL (u, p), which is a uniform distribution Yuan et al. [2020]. This difference decides the extent of similarity information in the response, and that governs the nature of the distillation process. We discuss this later in Section 4. It is safe to conclude that LS is a special case of the RBKD process in which soft labels are generated by a constant distribution as prior knowledge instead of learned-knowledge of a pre-trained teacher.

MNIST
F-MNIST CIFAR-10   Table 4: Student accuracy on missing class (MNIST) when distilled with small and large learning capacity teacher

Quality of Teacher's Response
The student mimics the teacher's response by minimizing the KL divergence between their response at T . The RBKD loss, Equation (4), is weighed higher α KD , 0.99, for KD. Each example generates two types of soft-labels, for itselfconfidence label, and for all other classes -similarity labels. The confidence label shows the confidence of a teacher for the correct class and the similarity labels provide a probabilistic value of similarity of all other classes with input class. Tables 1, 2, and 3 show the confidence label in bold text and similarity labels in plain text. The hyper-parameter α LS is 0.6 for LS process in Table 1, while temperature T is 9 for RBKD process in Tables 2 and 3.
The quality of distillation is controlled by the similarity information in the teacher's response, which can be controlled through T . But the increase and decrease in similarity information are not linear with T , but instead dependent on the similarity relation learned by the teacher during knowledge inculcation. The teacher perceives each example differently, even within the same class, and assigns a different confidence and similarity labels in its response. This introduces a variation in confidence and similarity labels -a variance in response, as shown row-wise and column-wise in Tables 2 and 3. More variance in similarity is desirable for KD as it provides knowledge about which classes are most similar to others. A highly confident teacher produces less variance as compared to a less confident teacher in its response, degrading the quality of distillation.
The behavior of a highly confident teacher model is analogous to the LS process. The similarity labels are treated equally with a little or no variance in response, providing neither similarity information nor variance in response. We describe this observation through the distillation hypothesis.

The Distillation Hypothesis
The distillation hypothesis, Figure 2, defines the nature of distillation by observing the quality of similarity labels and variance in response of a teacher. It states that for a given student network, as the learning capacity of the teacher

Missing
KD by small capacity teacher KD by large capacity teacher class Student accuracy(%) on removed class Student accuracy (%) on missing class  T=3  T=6  T=9  T=12 T=15 T=20 T=3 T=6 T=9 T=12 T=15 T=20  T- Table 6: Student accuracy on missing class (CIFAR 10) when distilled with small and large learning capacity teacher network increases, the nature of the distillation process starts to move away from a similarity label-based RBKD process to a non-similarity-based LS process. The shift towards the LS process is caused by the loss of similarity information and variance in response of a teacher and leads to poor distillation. In other words, the nature of the knowledge distillation process shifts away from one example-many classes learning to one example-one class learning.
Since the quality of distillation is directly dependent on the knowledge inculcation process of a teacher. We argue that any teacher model can be trained to retain more similarity information by finding a sweet spot between the batch size and the number of epochs for a given teacher-student pair (see Figure 1 (a)). The blue region symbolizes the right balance between the batch size and the number of epochs for better knowledge distillation.
Every DL model has an optimal batch size for optimum learning. The optimal batch size is the number of examples that the model is effectively able to process. If the batch size is larger than its optimal value, then the model is not able to process all the information at once and takes more epochs to achieve high confidence. These two factors can be iteratively balanced to reach the optimal batch size and number of epochs for knowledge inculcation of a teacher.

Experiments and Results
First, we present empirical results to support the distillation hypothesis, and then show the results of improved distillation achieved using our proposed method on MNIST, Fashion-MNIST, and CIFAR-10 datasets.

Similarity Information in Teacher's Response
The entropy of the soft labels is directly proportional to the presence of similarity information in the teacher's response. It is calculated as E Sof t−labels = − C i=1 p i log(p i ) where C is the number of classes in the dataset, p i is the probabilistic value from teacher. We use two different capacities of teachers, one with large learning capacity and the second with small learning capacity, to study this behavior. We argue that small capacity teachers having fewer parameters are not able to learn the fine-grained discriminative properties between classes and retain more similarity information in  their response as compared to the large capacity teacher which can learn fine-grained properties and lose similarity information in the process.
We show two experiments to support our argument. First, we compare the average entropy in teachers' responses for both small and large capacity teachers at different T , see Figure 3. At all T the average entropy of small capacity teachers remains higher than large capacity teachers. In other words, it is safe to say that a moderately confused teacher is better for knowledge distillation as compared to a well-trained large capacity teacher.
Second, we scrutinize the impact of similarity information for KD. We remove one out of N classes from distillation set during the KD process, and then check the performance of the student on the removed class, see Tables 4, 5, and 6. For the student network, the missing class is something it has never seen during training. It learns about the removed class only through the probabilistic value of the similarity information in the teacher's response.
The impact of similarity information on the quality of distillation is visible in Table 4, 5 and 6. Each table is divided into two columns, KD by the small and large capacity teachers. For each teacher, we perform KD on the same student and check its accuracy on the removed class on all three datasets. KD by the small teacher is very effective throughout but KD by the large teacher significantly under-performs on the removed class test. This shows that the quality of KD  is controlled by the presence of similarity information in the teacher's response. In presence of similarity-rich soft responses to classes, the student can learn about more than one class from a single input example (one example-many class learning), while it can learn about only one class from one input example if the response is "hard". We further argue that this critical information in soft labels defines the nature of distillation to be KD, regularization, or LS. We use entropy as an indicator of similarity information in the rest of the paper.

KD is one example-many class learning
We established that similarity labels are the most critical information for KD. Now, we show that similarity information accelerates the KD process and only requires a handful of examples to distill knowledge from the teacher. With two different capacity teacher models and using entropy as an indicator at T = 9, we select different number of examples varying from 5 to 2000 per class for KD. We compare the highest validation accuracy achieved by the student network at each step as shown in Figure 4. The validation accuracy of the student network distilled by a large capacity teacher always remains smaller than by a small capacity teacher on each dataset. For MNIST, distillation by a large capacity teacher requires 10 times more examples per class to achieve similar accuracy, and this gap increases for more complex datasets (15 times for Fashion-MNIST and 18 times for CIFAR-10). This shows that a large capacity teacher with less similarity information in its response fails to distill its knowledge using one example-many class learning and requires a much larger transfer set to achieve the same performance. This also establishes that one example-many class learning is a very important component of a good KD process.  Müller et al. [2019] argue that clusters that are relatively spread carry more similarity information in their response as compared to compact clusters.

Penultimate Layer Representation
The distillation hypothesis says that with the increase in learning capacity of a teacher model it loses similarity information in its response. This loss of similarity indicates that the nature of distillation shifts towards the nature of the LS process. We use this experiment to corroborate the distillation hypothesis by showing the change in clustering of penultimate layer projection which directly relates to similarity information in soft labels.
We randomly select three classes and then choose 300 examples from each class randomly. We extract its activation from the penultimate layer of both small and large capacity models and plot its projection, see Figure 5. We observe that the penultimate layer representation of the stronger teacher model forms tighter clusters as compared to small capacity teachers for each dataset. The spread-out clusters indicate that the presence of similarity information between classes that transcends to soft-labels generated by respective teachers, whereas the tighter cluster indicates the absence of similarity information between classes. This provides strong evidence for the distillation hypothesis.

Similarity-Rich Knowledge Inculcation
We already established the importance of similarity information in a teacher's response. But instead of trying to improve the KD process, we focus on the knowledge inculcation process -training the teacher. We carefully calibrate the optimum value of batch size and number of epochs to train the teacher described in section 3.4. We show improvement for each experiment shown before.
Based on our hypothesis, we show the change in average entropy of teachers' responses for different batch sizes and number of epochs in Figure 6. It shows that to increase the entropy of soft labels, we can either increase in batch size at a fixed epoch or we can decrease the number of epochs for given batch size. By carefully and iteratively balancing these two factors, we can find one of the many possible sweet spots suited for KD. This controls the extent of similarity information in the teacher's response, which is responsible for the quality of KD and network compression in this process.
Next, we show the improvement in penultimate layer representation of the large capacity teacher by adapting to our method of knowledge inculcation in Figure 7. Figure 7(a) shows tight clusters, indicating a lack of similarity information. These clusters spread out for many combinations of batch sizes and number of epochs indicating more similarity information in the teacher's response. A similar clustering is observed for batch size 4096 -epochs 50 and for batch size 8192 -epochs 40 in Fig. 7(b) and (c), respectively. We can conclude that there can be many combinations of batch size and number of epochs for a given teacher-student pair for a more efficient KD.
With all these improvements in the quality of teachers' responses, the minimum number of examples needed to achieve optimal performance should also reduce for large teachers. As shown in Fig. 8, we improve around 5 times in the minimum number of examples required per class to achieve similar performance, decreased from 500 to 100 examples Figure 9: Improved performance on training with suitable batch size and epochs, per class, for efficient KD. This provides further support to our idea of focusing on the knowledge inculcation process for achieving better and faster distillation, leading to better network compression.
Even with the above empirical results supporting our hypothesis, we still wanted to test our hypothesis for extreme teacher-student pair situations by maximizing the learning capacity gap between them. To achieve this, we use a single-layer student (baseline student) model with only a classification layer (we provide detail of models used in this paper in Table 7). We retrain the same large capacity teacher models for each dataset but train it differently -with different batch sizes and number of epochs, to accommodate for the larger gap in model capacities and use it for KD to the baseline student. We also use the small capacity teacher model to show the relative improvements in Fig. 9. The black, blue, and red lines in Fig. 9 shows the performance of baseline students on RBKD by small, and large capacity teachers trained with different batch size and epochs at different temperatures. The gap between the red and the blue line shows the improvement in KD performance by a single-layer student.

Summary and Conclusion
For building intuition about the nature of distillation, we present the entropy-version of the distillation hypothesis (previously shown in Fig. 2) to approximate the nature of the distillation process in Figure 10. For all the processes lying on the extreme ends in Fig. 2, we can imaging multiple lines with different entropy spread across, as shown in Fig.  10. We can draw an imaginary line (the dashed line in the figure) that separates the RBKD process and the LS process.  Table 7: Details of teacher and student models for different datasets. Conv, Dense, Dropout, and BN denote the number of convolution layers, number of Dense layers, dropout layers, and Batch Normalization layers, respectively. For efficient distillation from any teacher to any student, the corresponding entropy line should lie in the RBKD region. This can be achieved using our proposed method of knowledge inculcation during teacher's training. We emphasize that this representation is to develop an intuitive understanding of the KD process.
We discuss that the quality of distillation can be controlled at various stages of the KD process. While most works focuses on perfecting the distillation step of the KD process, we focus on controlling the quality of distillation by improving the knowledge inculcation process of the teacher model. Our experiments suggest that similarity information in a teacher's response plays a dictating role in determining the quality of distillation. We show the role of similarity information in accelerating the distillation process through one example-many class learning, making the KD process more effective and efficient. The distillation hypothesis can help in approximating the nature of the KD process to be RBKD, regularization, or LS process and to help make the process more effective. While we argue that the distillation performance of any teacher-student pair can be improved by our method of knowledge inculcation, we do not explore the extent to which the KD process can be improved. We believe that the factor of improvement should be different for each teacher-student pair. We leave this for future exploration.