{'fraction_non_alphanumeric': 0.019656279775558456, 'fraction_numerical': 0.011892578607474327, 'mean_word_length': 5.161774298760601, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Online Ensemble Model Compression using Knowledge Distillation

This paper presents a novel knowledge distillation based model compression framework consisting of a student ensemble. It enables distillation of simultaneously learnt ensemble knowledge onto each of the compressed student models. Each model learns unique representations from the data distribution due to its distinct architecture. This helps the ensemble generalize better by combining every model's knowledge. The distilled students and ensemble teacher are trained simultaneously without requiring any pretrained weights. Moreover, our proposed method can deliver multi-compressed students with single training, which is efficient and flexible for different scenarios. We provide comprehensive experiments using state-of-the-art classification models to validate our framework's effectiveness. Notably, using our framework a 97% compressed ResNet110 student model managed to produce a 10.64% relative accuracy gain over its individual baseline training on CIFAR100 dataset. Similarly a 95% compressed DenseNet-BC(k=12) model managed a 8.17% relative accuracy gain.


Introduction
Deep Learning based neural networks have provided tremendous improvements over the past decade in various domains of Computer Vision. These include Image Classification [24,17,20,40], Object Detection [31,3,26,30,12], Semantic Segmentation [16,4,44,5,45] among others. The drawbacks of these methods however include the fact that a large amount of computational resources are required to achieve state-of-the-art accuracy. A trend started setting in where constructing deeper and wider models provided better accuracy at the cost of considerable resource utilization [35,38,27]. The difference in resource utilization is considerable compared to traditional computer vision techniques. To alleviate this gap, model compression techniques started being developed to reduce these large computational requirements. These techniques can broadly be classified into four types [7] i.e. Parameter Pruning [15,37,6,14], Low Rank Factorization [8,29,36], Transferred Convolutional Filters [9,33,25,11] and Knowledge Distillation methods The original model is the first student in the ensemble, termed as pseudo teacher due to its simultaneous knowledge transfer capability and training from scratch properties. The ensemble teacher is a weighted combination of all student's output logits. Each student is divided into four blocks such that each block incorporates approximately the same number of layers. The layer channels for the compressed student branches are reduced by a specific ratio with respect to the original model. For a 3 student ensemble, the layer channels assigned are M, 2M/3 and M/3, where M is the original layer channel count. Channel adaptation layers help map the compressed student's block output channels to the pseudo teacher's output channels in order to compute an intermediate feature representation loss [18,21,1,13,22,46]. Each of these types was able to provide impressive computational reductions while simultaneously managing to keep the accuracy degradation to a minimum.
Knowledge Distillation (KD) in particular has provided great model compression capabilities using a novel teacher-student model concept [18]. Here a teacher, the original model trained for a specific task is used to teach a compressed or replicated version of itself referred to as student. The student is encouraged to mimic the teacher output distribution, which helps the student generalize much better and in certain cases leads to the student performing better than the teacher itself. Drawbacks of these methods include the fact that a pre-trained model is required to distill knowledge onto a student model. To solve this, simultaneous distillation methods [2,46] were developed wherein multiple students were being trained with an ensemble teacher learning on the fly with the students itself in an ensemble training scheme. These methods however primarily focused on replicating the teacher multiple times, causing the ensemble to gain sub-optimal generalized knowledge due to model architecture redundancy. Also in parallel, methods [22,34,1] were developed which focused on distilling not only the output knowledge but also the intermediate representations of teacher onto the student to have more effective knowledge transfer. These techniques are efficient, however still suffering from the drawback of requiring teacher model pre-training in addition to the student training.
In this paper, we present a novel model compression and ensemble training framework which improves on all aforementioned drawbacks and provides a new perspective for ensemble model compression techniques. We present a framework which enables multiple student model training using knowledge transfer from an ensemble teacher. Each of these student models represents a version of the original model compressed to different degrees. Knowledge is distilled onto each of the compressed student through the ensemble teacher and also through intermediate representations from a pseudo teacher. The original model is the first student in our ensemble, termed as pseudo teacher due to its simultaneous knowledge transfer capability and training from scratch property. Moreover this framework simultaneously provides multiple compressed models having different computational budget with each having benefited from every other model's training. Our framework facilitates the choice of selecting a student that fits the resource budget for a particular use case with the knowledge that every student provides decent comparable performance to the original model. Also, the ensemble training significantly reduces the training time of all student combined, compared to when they are trained individually. We specifically focus on image classification task while providing extensive experimentation on popular image classification models and bench-marked datasets. Our contributions from this paper can be thus summarized as follows: 1. We present a novel ensemble model compression framework based on knowledge distillation that can generate multiple compressed networks simultaneously with a single training run and is completely model agnostic. 2. We provide extensive experiments on popular classification models on standard datasets with corresponding baseline comparisons of each individual student training to provide evidence of our framework's effectiveness. 3. We provide hyper parameter ablation studies which help provide insights into the effective ensemble knowledge distillation provided by our framework.

Model Compression using Knowledge Distillation
Hinton et al. [18] introduced the concept of distilling knowledge from a larger teacher model onto a smaller compressed student model. Mathematically this meant training the student on softened teacher output distribution in addition to the traditional cross entropy with dataset labels. The paper argued that the teacher distribution provided much richer information about an image compared to just one hot labels. For e.g. consider a classification task of differentiating between various breeds of dogs. The output distribution of a higher capability teacher provides the student with the information of how alike one breed of dogs looks to the other. This helps the student learn more generalized features of each dog breed compared to providing just one hot labels which fails to provide any comparative knowledge. Also, in process of trying to mimic the distribution of a much deeper teacher model the student tries to find a compact series of transformation that tries to mimic the teacher's larger series of transformations. This inherently helps the student negate the accuracy loss due to compression. Impressively, in certain cases the student manages to outperform its teacher due to this superior generalization training. Further works extended this concept by using internal feature representations [1], adversarial learning [34] and inner product between feature maps [42].

Online Knowledge Distillation
The single practical drawback of Knowledge Distillation is the fact that a pretrained model is required to play the role of a teacher. This entails multiple sequential training runs on the same dataset. Anil et al. [2] came up with a method to train the student in parallel with the teacher termed as codistillation.
Here the student is an exact replica of the teacher and roles of teacher and student were continuously interchanged between the models during training with one training the other iteratively. The primary distinguishing property between the models was their distinct parameter initialization. This enabled each model to learn unique features which were then distilled from one to the other as training progressed.
Zhang et al. [43] employed a unique KD loss, by using KL divergence loss between two model output distributions to penalize the differences between them. Each model's training involved a combination loss of KL divergence loss with other model's distribution and traditional cross entropy loss. Both models acting as teacher and student simultaneously were trained jointly in an online fashion.
Lan et al. [46] extended this online KD concept by having multiple replicas of a given model in a multi branch architecture fashion. Multi branch architecture designs became popular with the image classification models like Resnet [17], Inception [38,39] and ResNext [41]. In this paper, the multiple replicated models have a common base of block of layers with each model represented as a branch on top of this base with subsequent layer blocks from the original model architecture right until the final fully connected layers. The teacher in this concept was the combined output of all the student models in the ensemble. Each student model learnt from the ensemble joint knowledge represented by the teacher outputs. Our paper builds on this core concept however is fundamentally different as we incorporate compressed student branches, more efficient training procedure, incorporate intermediate representation distillation in addition to the final output distillation among others.

Intermediate Representation Knowledge Distillation
A separate branch of Knowledge Distillation focuses on training the student to mimic the intermediate representations obtained in form of feature maps from certain intermediate layer blocks within the teacher. This provides a more stricter learning regime for the student who has to focus not only on the final teacher output distribution but also on its intermediate layer feature maps. Romero et al. [1] provide one of the preliminary works in this direction by distilling a single intermediate layer's knowledge onto the student which they term as providing hint to the student. Mathematically, hint training involves minimizing a combination of L2 loss between the features maps at an immediate layer of the two models and the regular KD (KL divergence loss) between the output distributions.
Koratana et al. [22] extend this concept by comparing feature maps at not just one but multiple intermediate locations within the model which can be related to as multiple hint training. This method however again requires a pretrained teacher model which might be time consuming and compute expensive for certain real world scenarios. Our method incorporates multiple hint training for all student models with respect to pseudo teacher, which is also the first student in the ensemble. A network's depth measures its function modeling capacity in general. Koratana et al. [22] compress the model by removing blocks of layers from the network which severely affects the network depth. Our work incorporates a more robust compression logic where the number of channels in every student layer are simply reduced by a certain percent, thus preserving the model depth.

Methodology
An overview of our ensemble compression framework is presented in Figure 1, which can be split up into three major sections for the ease of understanding. We would be going into their details in the following sections.

Ensemble Student Model Compression
First, the entire architecture of a given neural network is broken down into a series of layer blocks, ideally into four blocks. The first block is designated as a common base block and the rest of the blocks are replicated in parallel to create branches as shown in Figure 1. A single student model can be viewed as a series of base block and one of the branches on top of it. As previously mentioned, the original network is designated as the first student model, also termed as pseudo teacher. For every successive student branch the number of channels in each layer of its blocks is reduced by a certain ratio with respect to the pseudo teacher. This ratio becomes higher for every new student branch created. For example, for a four student ensemble and C being number of channels in pseudo teacher, the channels in other three students are assigned to be 0.75C, 0.5C and 0.25C. The students are compressed versions of the original model to varying degrees, which still manage to maintain the original network depth. The channels in the common base block are kept the same as original whose main purpose is to provide constant low level features to all the student branches.
The output logits from all the student models are averaged together to create the ensemble teacher logits. This ensemble teacher output distribution represents the joint knowledge of the ensemble. During inference stage, any of the individual student models can be selected from the ensemble depending on the computational hardware constraints. In case of lenient constraints, the entire ensemble can be used with the ensemble teacher providing inference based on the learnt ensemble knowledge. From our studies we find that having 5 students (inclusive of pseudo teacher) provides an optimal trade off between training time and effective model compression. Table 1 provides an overview of compressed student model sizes and their CIFAR10 [23] trained accuracies for a five student ensemble based on various classification model architectures.

Intermediate Knowledge Distillation
The intermediate block knowledge (feature map representation) is additionally distilled onto every compressed student from the pseudo teacher. This provides a more stricter training and distillation regime for all the compressed students. The loss in every student's representational capacity due to compression is countered, by making each student block try and learn the intermediate feature map of its corresponding pseudo teacher block. The feature map pairs are compared using traditional Mean Squared Error loss, on which the network is trained to reduce any differences between them. Since the number of feature map channels varies across every corresponding student and pseudo teacher block, an adaptation layer consisting of pointwise convolution (1×1 kernel) is used to map compressed student block channels to its pseudo teacher counterpart. Figure 2 (a) presents this idea in detail for an EfficientNet-B0 [40] based ensemble. The intermediate knowledge is transferred at three locations corresponding to the three blocks in every student branch as shown in Figure 1.

Knowledge Distillation Based Training
The overall ensemble is trained using a combination of three separate losses which are described in detail as follows: Cross-Entropy Loss Each student model is trained individually on classical cross entropy loss [Equation 1, 2] with one hot vector of labels and student output logits. This loss helps each student directly train on a given dataset. This loss procedure makes the pseudo teacher learn alongside the compressed students as the framework doesn't use pretrained weights of any sort. It also helps the ensemble teacher gain richer knowledge of the dataset as it incorporates combination of every student's learnt knowledge. It additionally enables the framework to avoid training the ensemble teacher separately and is trained implicitly through the students. The output softmax distribution and combined normal loss can be expressed as follows, where i, j, k represents student, batch sample and class number indices respectively. 1 jk is an one hot label indicator function for j th sample and k th class.
Similarly, x ijk is a single output logit from i th student model for j th batch sample and k th class and X ijk is its corresponding softmax output.
Intermediate Loss For every pseudo teacher and compressed student pair, the output feature maps from every pseudo teacher block are compared to the ones at its corresponding compressed student block. In order to facilitate an effective knowledge distillation between these respective map pairs, the compressed student maps are first passed through an adaptation layer which as mentioned earlier is a simple 1 × 1 convolution, mapping the student map channels to the pseudo teacher map channels. A Mean Squared Error loss is used to compare each single element of a given pseudo teacher-student feature map pair. This loss is averaged across the batch. The loss for a single block across all students can be expressed as follows, where x l m is a feature map of size H × W × C corresponding to m th batch sample of the l th student model. |.| 2 represents element wise squared L2 norm. l = 1 represents the pseudo teacher, also designated as PT in x P T m which is the corresponding pseudo teacher feature map. The overall intermediate loss can be expressed as: This loss is used to update only the compressed student model parameters in order to have the compressed student learn from the pseudo teacher and not the other way round. In our experiments we observed that the mean of adaptation layer weights is on average lower for larger student models. This in turn propagates a smaller model response term in the intermediate loss equation, thus increasing their losses slightly compared to thinner students. This helps balance this loss term across all students.
Knowledge Distillation Loss To facilitate global knowledge transfer from the ensemble teacher to each of the students, a KD loss in form of Kullback-Leibler Divergence Loss is incorporated between the ensemble teacher and student outputs. The outputs of the ensemble teacher and each respective student are softened using a certain temperature T to help students learn efficiently from highly confident ensemble teacher predictions where the wrong class outputs are almost zero. The softened softmax and overall KD loss can be expressed as follows, where X ijk is the softened softmax output of the i th student for j th batch sample and k th class. Similarly X T jk represents the ensemble teacher softened softmax output for j th batch sample and k th class.
Combined Loss The above presented three losses are combined using a weighted combination, on which the entire framework is trained to reduce this overall loss. This can be mathematically expressed as, The optimal weight value combination which was found out to be α = 0.7, β = 0.15, γ = 0.15 is discussed in detail in an ablation study presented in later sections.

Experiments
Datasets. We incorporate four major academic datasets: (1) CIFAR10 dataset [23] which contains 50,000/10,000 training/test samples drawn from 10 classes. Each class has 6,000 images included in both training and test set sized at 32 × 32 pixels. (2) CIFAR100 dataset [23] Table 4. (3) Compare the time taken for training our five student based ensemble versus the combined time taken for training each of those students individually. This comparison helps substantiate the training time benefits of our hybrid multi-student architecture compared to training each student alone either sequentially or in parallel. These are presented in Figure 2 (b). Performance Metrics. We compare the test set accuracy (Top-1) of each of our student models within the ensemble, trained using our framework and as an individual baseline model with only the traditional cross entropy loss. For each of our ensemble students, this test set accuracy is computed as an average of the best student test accuracies achieved during each of five conducted runs.  Experimental Setup. For fair comparison, we keep the training schedule the same for both our ensemble framework and baseline training. Specifically, for ResNet, DenseNet and ResNeXt models SGD is used with Nesterov momentum set to 0.9, following a standard learning rate schedule that drops from 0.1 to 0.01 at 50% training and to 0.001 at 75%. For EfficientNet models RMSProp optimizer is implemented with decay 0.9 and momentum 0.9 and initial learning rate of 0.256 that decays by 0.97 every 3 epochs. The models are trained for 350/450/50/100 epochs each for the CIFAR10/CIFAR100/SVHN/ImageNet datasets respectively.

Evaluation of our online model compression framework
Results on CIFAR10 and CIFAR100. Tables 2,3 present our experimental results for CIFAR10 and CIFAR100 dataset respectively. Each compressed student's test set performance is on an average 1% better using our ensemble framework as compared to the simple baseline training for both the datasets. Our ensemble teacher also provides the best Test set accuracy when compared to the teacher accuracies of three other ensemble knowledge distillation techniques for ResNet32 and ResNet110 models as presented in Table 4. Our framework provides substantial training time benefits for all models tested with CIFAR10 and CIFAR100 datasets as presented in Fig 2 (b). For fair comparison the ensemble  and each of the baseline students are trained for the same number epochs on both datasets. Notably, training a five student ensemble of an EfficientNet-B4 architecture is roughly 7.5K GPU minutes quicker as compared to their combined individual baseline training.
Results on SVHN and ImageNet. Tables 5,6 present our experimental results for SVHN and ImageNet datasets respectively. Again, each compressed student test set performance is on an average 1% better using our ensemble framework as compared to the simple baseline training for both the datasets.
Notably for both datasets, the heavily compressed fourth and fifth students perform around 3% on average better than their baseline counterparts. This provide an excellent evidence of our framework's efficient knowledge transfer capabilities for the heavily compressed student cases. Similar to the aforementioned datasets, our ensemble teacher provides the best Test set accuracy when compared to the ensemble teacher accuracy of three other ensemble knowledge distillation based techniques for ResNet32 and ResNet110 models as presented in Table 4.

Ablation Studies
Loss Contribution Ratios. A selective grid search was conducted for the optimal values of loss contribution ratios, specifically α, β, γ referenced in Equation 7. The grid search was conducted with the constraint that the ratio should sum to one which would represent the overall loss factor. The study was carried out using ResNet110 [17] model on the CIFAR100 [23] dataset. Firstly, a grid search was conducted for α which is the normal loss contribution ratio. The other two contribution ratio namely β, γ were kept equal to half the fraction left from subtracting the grid search α from 1. This study is presented in Table 7. All accuracies are averaged over five runs to reduce any weight initialization effect. The value of 0.7 provided the best weighted average accuracy across all the students. Weights of 1 5 , 2 5 , 3 5 , 4 5 , 1 were assigned to the students, with higher importance given to accuracy achieved by more compressed student.
With the value of α set as 0.7, a grid search was then conducted for the value of β and γ. This study is presented in Table 8. Here also the same weighted average technique was used to find the effective student test accuracy. β = 0.15 and γ = 0.15 gave the optimal performance and were thus selected as the final contribution ratios for our framework. These final ratios seem to indicate the major importance of cross entropy loss with α = 0.7 in individual student's training and equal importance of intermediate and output distribution knowledge transfer with β = γ = 0.15 for the knowledge distillation process. Knowledge distillation Temperature. A temperature variable T is used to soften the student and ensemble teacher model logits before computing its respective softmax distribution as referenced in Equation 5. A grid search was conducted for its optimal value, which would facilitate optimum knowledge transfer from the ensemble teacher to each student model. Similar to the previous study,  we incorporate a ResNet110 [17] model to train on CIFAR100 [23] dataset. This study is presented in Table 9. The resulting optimal value of 2 is used for all of our conducted experiments. The study results provide evidence to the fact that higher temperature values tend to over-soften the output logits leading to sub optimal knowledge transfer and test accuracy gains.

Discussion
The performed experiments provide a strong evidence of the efficient compression and generalization capabilities of our framework over individual baseline training for every compressed student model. In most of the experiments the ensemble teacher's test accuracy is much better than any of its ensemble students and their baseline counterparts. This additional test accuracy gain can be attributed to the joint ensemble knowledge learnt by the framework. The intermediate knowledge transfer from the pseudo teacher onto each one of the compressed students helps guide every student compressed block to reproduce the same transformations its respective higher capacity pseudo teacher block is learning. Enabling the low capacity compressed block to try and imitate the higher capacity pseudo teacher block helps reduce any redundant (sub-optimal) transformations inside the student block that would generally be  [32] comparison of a EfficientNet-B4 based ensemble pseudo teacher and one of its compressed students with that of its respective individually trained student. The ensemble student's CAM is more accurate compared to that of baseline student. Also the former follows the pseudo teacher more closely as compared to the latter, which provides evidence of the effective knowledge distillation taking place in our ensemble framework. present during baseline training. This is substantiated by the fact that the test accuracy gains of heavily compressed students, specifically the fourth and fifth students in the ensemble are substantial over their baseline counterparts. Figure  3 presents a comparison of the gradient based class activation mapping (Grad-CAM) [32] of the last block of an EfficientNet-B4 framework pseudo teacher and one of its compressed students. These are compared to the Grad-CAM of the same compressed student with baseline training. The smaller differences between the Grad-CAMs of pseudo teacher and its ensemble student compared to those between the pseudo teacher and the baseline student provide evidence of how our efficient knowledge distillation helps the student imitate the pseudo teacher and learn better as compared to the baseline student.

Conclusion
We present a novel model compression technique using an ensemble knowledge distillation learning procedure without requiring the need of any pretrained weights. The framework manages to provide multiple compressed versions of a given base (pseudo teacher) model simultaneously, providing gains in each of the participating model's test performance and in overall framework's training time compared to each model's individual baseline training. Comprehensive experiments conducted using a variety of current state-of-the-art image classification based models and benchmarked academic datasets provide substantial evidence of the framework's effectiveness. It also provides an account of the highly modular nature of the framework which makes it easier to incorporate any existing classification model into the framework without any major modifications. It manages to provide multiple efficient versions of the same, compressed to varying degree without making any major manual architecture changes on the user's part.