Going deeper with Image Transformers
Hugo Touvron, Matthieu Cord, Alexandre Sablayrolles, Gabriel Synnaeve, Hervé Jégou
Introduction
Residual architectures are prominent in computer vision since the advent of ResNet . They are defined as a sequence of functions of the form
where the function and define how the network updates the input at layer . The function is typically identity, while is the main building block of the network: many variants in the literature essentially differ on how one defines this residual branch is constructed or parametrized . Residual architectures highlight the strong interplay between optimization and architecture design. As pointed out by He et al. , residual networks do not offer a better representational power. They achieve better performance because they are easier to train: shortly after their seminal work, He et al. discussed the importance of having a clear path both forward and backward, and advocate setting to the identity function.
where is the LayerNorm operator . This definition follows the original architecture of Vaswani et al. , except the LayerNorm is applied before the block (pre-norm) in the residual branch, as advocated by He et al. . Child et al. adopt this choice with LayerNorm for training deeper transformers for various media, including for image generation where they train transformers with 48 layers.
How to normalize, weigh, or initialize the residual blocks of a residual architecture has received significant attention both for convolutional neural networks and for transformers applied to NLP or speech tasks . In Section 2, we revisit this topic for transformer architectures solving image classification problems. Examples of approaches closely related to ours include Fixup , T-Fixup , ReZero and SkipInit .
Following our analysis of the interplay between different initialization, optimization and architectural design, we propose an approach that is effective to improve the training of deeper architecture compared to current methods for image transformers. Formally, we add a learnable diagonal matrix on output of each residual block, initialized close to (but not at) 0. Adding this simple layer after each residual block improves the training dynamic, allowing us to train deeper high-capacity image transformers that benefit from depth. We refer to this approach as LayerScale.
Section 3 introduces our second contribution, namely class-attention layers, that we present in Figure 2. It is akin to an encoder/decoder architecture, in which we explicitly separate the transformer layers involving self-attention between patches, from class-attention layers that are devoted to extract the content of the processed patches into a single vector so that it can be fed to a linear classifier. This explicit separation avoids the contradictory objective of guiding the attention process while processing the class embedding. We refer to this new architecture as CaiT (Class-Attention in Image Transformers).
In the experimental Section 4, we empirically show the effectiveness and complementary of our approaches:
LayerScale significantly facilitates the convergence and improves the accuracy of image transformers at larger depths. It adds a few thousands of parameters to the network at training time (negligible w.r.t. the total number of weights).
Our architecture with specific class-attention offers a more effective processing of the class embedding.
Our best CaiT models establish the new state of the art on Imagenet-Real and Imagenet V2 matched frequency with no additional training data. On ImageNet1k-val , our model is on par with the state of the art (86.5%) while requiring less FLOPs (329B vs 377B) and having less parameters than the best competing model (356M vs 438M).
We achieve competitive results on Transfer Learning.
We provide visualizations of the attention mechanisms in Section 5. We discuss related works along this paper and in the dedicated Section 6, before we conclude in Section 7. The appendices contain some variations we have tried during our exploration.
Deeper image transformers with LayerScale
Our goal is to increase the stability of the optimization when training transformers for image classification derived from the original architecture by Vaswani et al.. , and especially when we increase their depth. We consider more specifically the vision transformer (ViT) architecture proposed by Dosovitskiy et al. as the reference architecture and adopt the data-efficient image transformer (DeiT) optimization procedure of Touvron et al. . In both works, there is no evidence that depth can bring any benefit when training on Imagenet only: the deeper ViT architectures have a low performance, while DeiT only considers transformers with 12 blocks of layers. The experimental section 4 will confirm that DeiT does not train deeper models effectively.
Figure 1 depicts the main variants that we compare for helping the optimization. They cover recent choices from the literature: as discussed in the introduction, the architecture (a) of ViT and DeiT is a pre-norm architecture , in which the layer-normalisation occurs at the beginning of the residual branch. Note that the original architecture of Vaswani et al. applies the normalization after the block, but in our experiments the DeiT training does not converge with post-normalization.
Fixup , ReZero and SkipInit introduce learnable scalar weighting on the output of residual blocks, while removing the pre-normalization and the warmup, see Figure 1(b). This amounts to modifying Eqn. 2 as
ReZero simply initializes this parameter to . Fixup initializes this parameter to and makes other modifications: it adopts different policies for the initialization of the block weights, and adds several weights to the parametrization. In our experiments, these approaches do not converge even with some adjustment of the hyper-parameters.
Our empirical observation is that removing the warmup and the layer-normalization is what makes training unstable in Fixup and T-Fixup. Therefore we re-introduce these two ingredients so that Fixup and T-Fixup converge with DeiT models, see Figure 1(c). As we see in the experimental section, these amended variants of Fixup and T-Fixup are effective, mainly due to the learnable parameter . When initialized at a small value, this choice does help the convergence when we increase the depth.
is a per-channel multiplication of the vector produced by each residual block, as opposed to a single scalar, see Figure 1(d). Our objective is to group the updates of the weights associated with the same output channel. Formally, LayerScale is a multiplication by a diagonal matrix on output of each residual block. In other terms, we modify Eqn. 2 as
where the parameters and are learnable weights. The diagonal values are all initialized to a fixed small value : we set it to until depth 18, for depth 24 and for deeper networks. This formula is akin to other normalization strategies ActNorm or LayerNorm but executed on output of the residual block. Yet we seek a different effect: ActNorm is a data-dependent initialization that calibrates activations so that they have zero-mean and unit variance, like batchnorm . In contrast, we initialize the diagonal with small values so that the initial contribution of the residual branches to the function implemented by the transformer is small. In that respect our motivation is therefore closer to that of ReZero , SkipInit , Fixup and T-Fixup : to train closer to the identity function and let the network integrate the additional parameters progressively during the training. LayerScale offers more diversity in the optimization than just adjusting the whole layer by a single learnable scalar as in ReZero/SkipInit, Fixup and T-Fixup. As we will show empirically, offering the degrees of freedom to do so per channel is a decisive advantage of LayerScale over existing approaches.In Appendix A, we present other variants or intermediate choices that support our proposal, and a control experiment that aims at disentangling the specific weighting of the branches of LayerScale from its impact on optimization.
Specializing layers for class attention
In this section, we introduce the CaiT architecture, depicted in Figure 2 (right). This design aims at circumventing one of the problems of the ViT architecture: the learned weights are asked to optimize two contradictory objectives: (1) guiding the self-attention between patches while (2) summarizing the information useful to the linear classifier. Our proposal is to explicitly separate the two stages, in the spirit of an encoder-decoder architecture, see Section 6.
As an intermediate step towards our proposal, we insert the so-called class token, denoted by CLS, later in the transformer. This choice eliminates the discrepancy on the first layers of the transformer, which are therefore fully employed for performing self-attention between patches only. As a baseline that does not suffer from the contradictory objectives, we also consider average pooling of all the patches on output of the transformers, as typically employed in convolutional architectures.
Our CaiT network consists of two distinct processing stages visible in Figure 2:
The self-attention stage is identical to the ViT transformer, but with no class embedding (CLS).
The class-attention stage is a set of layers that compiles the set of patch embeddings into a class embedding CLS that is subsequently fed to a linear classifier.
This class-attention alternates in turn a layer that we refer to as a multi-head class-attention (CA), and a FFN layer. In this stage, only the class embedding is updated. Similar to the one fed in ViT and DeiT on input of the transformer, it is a learnable vector. The main difference is that, in our architecture, we do no copy information from the class embedding to the patch embeddings during the forward pass. Only the class embedding is updated by residual in the CA and FFN processing of the class-attention stage.
where . This attention is involved in the weighted sum to produce the residual output vector
The CA layers extract the useful information from the patches embedding to the class embedding. In preliminary experiments, we empirically observed that the first CA and FFN give the main boost, and a set of 2 blocks of layers (2 CA and 2 FFN) is sufficient to cap the performance. In the experimental section, we denote by 12+2 a transformer when it consists of 12 blocks of SA+FFN layers and 2 blocks of CA+FFN layers.
The layers contain the same number of parameters in the class-attention and self-attention stages: CA is identical to SA in that respect, and we use the same parametrization for the FFNs. However the processing of these layers is much faster: the FFN only processes matrix-vector multiplications.
The CA function is also less expensive than SA in term of memory and computation because it computes the attention between the class vector and the set of patch embeddings: means that . In contrast, in the “regular self-attention” layers SA, we have and therefore . In other words, the initially quadratic complexity in the number of patches becomes linear in our extra CaiT layers.
Experiments
In this section, we report our experimental results related to LayerScale and CaiT. We first study strategies to train at deeper scale in Section 4.1, including our LayerScale method. Section 4.2 shows the interest of our class-attention design. We present our models in Subsection 4.3. Section 4.4 details our results on Imagenet and Transfer learning. We provide an ablation of hyper-parameter and ingredients in Section 4.5. Note, in Appendix A and B, we provide variations on our methods and corresponding results.
Our implementation is based on the Timm library . Unless specified otherwise, for this analysis we make minimal changes to hyper-parameters compared to the DeiT training scheme . In order to speed up training and optimize memory consumption we have used a sharded training provided by the Fairscale libraryhttps://pypi.org/project/fairscale/ with fp16 precision.
1 Preliminary analysis with deeper architectures
In our early experiments, we observe that Vision Transformers become increasingly more difficult to train when we scale architectures. Depth is one of the main source of instability. For instance the DeiT procedure fails to properly converge above 18 layers without adjusting hyper-parameters. Large ViT models with 24 and 32 layers were trained with large training datasets, but when trained on Imagenet only the larger models are not competitive.
In the following, we analyse various ways to stabilize the training with different architectures. At this stage we consider a Deit-Small modelhttps://github.com/facebookresearch/deit during 300 epochs to allow a direct comparison with the results reports by Touvron et al. . We measure the performance on the Imagenet1k classification dataset as a function of the depth.
The first step to improve convergence is to adapt the hyper-parameters that interact the most with depth, in particular Stochastic depth . This method is already popular in NLP to train deeper architectures. For ViT, it was first proposed by Wightman et al. in the Timm implementation, and subsequently adopted in DeiT . The per-layer drop-rate depends linearly on the layer depth, but in our experiments this choice does not provide an advantage compared to the simpler choice of a uniform drop-rate . In Table 1 we show that the default stochastic depth of DeiT allows us to train up to 18 blocks of SA+FFN. After that the training becomes unstable. By increasing the drop-rate hyper-parameter , the performance increases until 24 layers. It saturates at 36 layers (we measured that it drops to 80.7% at 48 layers).
1.2 Comparison of normalization strategies
We carry out an empirical study of the normalization methods discussed in Section 2. As previously indicated, Rezero, Fixup and T-Fixup do not converge when training DeiT off-the-shelf. However, if we re-introduce LayerNormBachlechner et al. report that batchnorm is complementary to ReZero, while removing LayerNorm in the case of transformers. and warmup, Fixup and T-Fixup achieve congervence and even improve training compared to the baseline DeiT. We report the results for these “adaptations” of Fixup and T-Fixup in Table 1.
Fixup and T-Fixup are competitive with LayerScale in the regime of a relatively low number of blocks (12–18). However, they are more complex than LayerScale: they employ different initialization rules depending of the type of layers, and they require more changes to the transformer architecture. Therefore we only use LayerScale in subsequent experiments. It is much simpler and parametrized by a single hyper-parameter , and it offers a better performance for the deepest models that we consider, which are also the more accurate.
1.3 Analysis of Layerscale
We evaluate the impact of Layerscale for a 36-blocks transformer by measuring the ratio between the norm of the residual activations and the norm of the activations of the main branch . The results are shown in Figure 4. We can see that training a model with Layerscale makes this ratio more uniform across layers, and seems to prevent some layers from having a disproportionate impact on the activations. Similar to prior works we hypothetize that the benefit is mostly the impact on optimization. This hypothesis is supported by the control experiment that we detail in Appendix A.
2 Class-attention layers
In Table 2 we study the impact on performance of the design choices related to class embedding. We depict some of them in Figure 2. As a baseline, average pooling of patches embeddings with a vanilla DeiT-Small achieves a better performance than using a class token. This choice, which does not employ any class embedding, is typical in convolutional networks, but possibly weaker with transformers when transferring to other tasks .
The performance increases when we insert the class embedding later in the transformer. It is maximized two layers before the output. Our interpretation is that the attention process is less perturbed in the 10 first layers, yet it is best to keep 2 layers for compiling the patches embedding into the class embedding via class-attention, otherwise the processing gets closer to a weighted average.
are designed on the assumption that there is no benefit in copying information from the class embedding back to the patch embeddings in the forward pass. Table 2 supports that hypothesis: if we compare the performance for a total number of layers fixed to 12, the performance of CaiT with 10 SA and 2 CA layers is identical to average pooling and better than the DeiT-Small baseline with a lower number of FLOPs. If we set 12 layers in the self-attention stage, which dominates the complexity, we increase the performance significantly by adding two blocks of CA+FFN.
3 Our CaiT models
Our CaiT models are built upon ViT: the only difference is that we incorporate LayerScale in each residual block (see Section 2) and the two-stages architecture with class-attention layers described in Section 3. Table 3 describes our different models. The design parameters governing the capacity are the depth and the working dimensionality . In our case is related to the number of heads as , since we fix the number of components per head to 48. This choice is a bit smaller than the value used in DeiT. We also adopt the crop-ratio of 1.0 optimized for DeiT by Wightman . Table 9 and 10 in the ablation section 4.5 support these choices.
We incorporate talking-heads attention into our model. It increases the performance on Imagenet of DeiT-Small from 79.9% to 80.3%.
are identical to those provided in DeiT , except mentioned otherwise. We use a batch size of 1024 samples and train during 400 epochs with repeated augmentation . The learning rate of the AdamW optimizer is set to 0.001 and associated with a cosine training schedule, 5 epochs of warmup and a weight decay of 0.05. We report in Table 4 the two hyper-parameters that we modify depending on the model complexity, namely the drop rate associated with uniform stochastic depth, and the initialization value of LayerScale.
We train all our models at resolution 224, and optionally fine-tune them at a higher resolution to trade performance against accuracy : we denote the model by 384 models fine-tuned at resolution 384384. We also train models with distillation () as suggested by Touvron et al.. . We use a RegNet-16GF as teacher and adopt the “hard distillation” for its simplicity.
4 Results
Table 3 provides different complexity measures for our models. As a general observation, we observe a subtle interplay between the width and the depth, both contribute to the performance as reported by Dosovitskiy et al.. with longer training schedules. But if one parameter is too small the gain brought by increasing the other is not worth the additional complexity.
Fine-tuning to size 384 () systematically offers a large boost in performance without changing the number of parameters. It also comes with a higher computational cost. In contrast, leveraging a pre-trained convnet teacher with hard distillation as suggested by Touvron et al. provides a boost in accuracy without affecting the number of parameters nor the speed.
4.2 Comparison with the state of the art on Imagenet
Our main classification experiments are carried out on ImageNet , and also evaluated on two variations of this dataset: ImageNet-Real that corrects and give a more detailed annotation, and ImageNet-V2 (matched frequency) that provides a separate test set. In Table 5 we compare some of our models with the state of the art on Imagenet classification when training without external data. We focus on the models CaiT-S36 and CaiT-M36, at different resolutions and with or without distillation.
On Imagenet1k-val, CaiT-M48448 achieves 86.5% of top-1 accuracy, which is a significant improvement over DeiT (85.2%). It is the state of the art, on par with a recent concurrent work that has a significantly higher number of FLOPs. Our approach outperforms the state of the art on Imagenet with reassessed labels, and on Imagenet-V2, which has a distinct validation set which makes it harder to overfit.
4.3 Transfer learning
We evaluated our method on transfer learning tasks by fine-tuning on the datasets in Table 6.
For fine-tuning we use the same hyperparameters as for training. We only decrease the learning rates by a factor 10 (for CARS, Flowers, iNaturalist), 100 (for CIFAR-100, CIFAR-10) and adapt the number of epochs (1000 for CIFAR-100, CIFAR-10, Flowers-102 and Cars-196, 360 for iNaturalist 2018 and 2019). We have not used distillation for this finetuning.
Table 7 compares CaiT transfer learning results to those of EfficientNet , ViT and DeiT . These results show the excellent generalization of the transformers-based models in general. Our CaiT models achieve excellent results, as shown by the overall better performance than EfficientNet-B7 across datasets.
5 Ablation
In this section we provide different sets of ablation, in the form of a transition from DeiT to CaiT. Then we provide experiments that have guided our hyper-parameter optimization. As mentioned in the main paper, we use the same hyperparameters as in DeiT everywhere except stated otherwise. We have only changed the number of attention for a given working dimension (see Section 4.5.2), and changed the crop-ratio (see Section 4.5.3).
In Table 8 we present how to gradually transform the Deit-S architecture into CaiT-36, and measure at each step the performance/complexity changes. One can see that CaiT is complementary with LayerScale and offers an improvement without significantly increasing the FLOPs. As already reported in the literature, the resolution is another important step for improving the performance and fine-tuning instead of training the model from scratch saves a lot of computation at training time. Last but not least, our models benefit from longer training schedules.
5.2 Optimization of the number of heads
In Table 9 we study the impact of the number of heads for a fixed working dimensionality. This architectural parameter has an impact on both the accuracy, and the efficiency: while the number of FLOPs remain roughly the same, the compute is more fragmented when increasing this number of heads and on typical hardware this leads to a lower effective throughput. Choosing 8 heads in the self-attention offers a good compromise between accuracy and speed. In Deit-Small, this parameter was set to 6.
5.3 Adaptation of the crop-ratio
In the typical (“center-crop”) evaluation setting, most convolutional neural networks crop a subimage with a given ratio, typically extracting a center crop from a resized image, leading to the typical ratio of 0.875. Wightman et al. notice that setting this crop ratio to 1.0 for transformer models has a positive impact: the distilled DeiT-B reaches a top1-accuracy on Imagenet1k-val of in this setting, which is a gain of +0.2% compared to the accuracy of 85.2% reported by Touvron et al. .
Our measurements concur with this observation: We observe a gain for almost all our models and most of the evaluation benchmarks. For instance our model M36384 increases to 86.1% top-1 accuracy on Imagenet-val1k.
5.4 Longer training schedules
As shown in Table 8 , increasing the number of training epochs from 300 to 400 improves the performance of CaiT-S-36. However, increasing the number of training epochs from 400 to 500 does not change performance significantly (83.44 with 400 epochs 83.42 with 500 epochs). This is consistent with the observation of the DeiT paper, which notes a saturation of performance from 400 epochs for the models trained without distillation.
Visualizations
In Figure 6 we show the attention maps associated with the individual 4 heads of a XXS CaiT model, and for the two layers of class-attention. In CaiT and in contrast to ViT, the class-attention stage is the only one where there is some interaction between the class token and the patches, therefore it conveniently concentrates all the spatial-class relationship. We make two observations:
The first class-attention layer clearly focuses on the object of interest, corresponding to the main part of the image on which the classification decision is performed (either correct or incorrect). In this layer, the different heads focus either on the same or on complementary parts of the objects. This is especially visible for the waterfall image;
The second class-attention layer seems to focus more on the context, or at least the image more globally.
2 Illustration of saliency in class-attention
For each image we show this saliency map and provides all the class for which the model assigns a probability higher than 10%. These visualizations illustrate how the model can focus on two distinct regions (like racket and tennis ball on the top row/center). We can also observe some failure cases, like the top of the church classified as a flagpole.
Related work
Since AlexNet , convolutional neural networks (CNN) are the standard in image classification , and more generally in computer vision. While a deep CNN can theoretically model long range interaction between pixels across many layers, there has been research in increasing the range of interactions within a single layer. Some approaches adapt the receptive field of convolutions dynamically . At another end of the spectrum, attention can be viewed as a general form of non-local means, which was used in filtering (e.g. denoising ), and more recently in conjunction with convolutions . Various other attention mechanism have been used successfully to give a global view in conjunction with (local) convolutions , most mimic squeeze-and-excitate for leveraging global features. Lastly, LambdaNetworks decomposes attention into an approximated content attention and a batch-amortized positional attention component.
Hybrid architectures combining CNNs and transformers blocks have also been used on ImageNet and on COCO . Originally, transformers without convolutions were applied on pixels directly , even scaling to hundred of layers , but did not perform at CNNs levels. More recently, a transformer architecture working directly on small patches has obtained state of the art results on ImageNet . Nevertheless, the state of the art has since returned to CNNs . While some small improvements have been applied on the transformer architecture with encouraging results , their performance is below the one of DeiT , which uses a vanilla ViT architecture.
Transformers were originally introduced for machine translation with encoder-decoder models, and gained popularity as masked language model encoders (BERT) . They yielded impressive results as scaled up language models, e.g. GPT-2 and 3 . They became a staple in speech recognition too , being it in encoder and sequence criterion or encoder-decoder seq2seq conformations, and hold the state of the art to this day with models 36 blocks deep. Note, transforming only the class token with frozen trunk embeddings in CaiT is reminiscent of non-autoregressive encoder-decoders , where a whole sequence (we have only one prediction) is produced at once by iterative refinements.
usually lead to better performance , however this complicates their training process . One must adapt the architecture and the optimization procedure to train them correctly. Some approaches focus on the initialization schemes , others on multiple stages training , multiple loss at different depth , adding components in the architecture or regularization . As pointed in our paper, in that respect our LayerScale approach is more related to Rezero and Skipinit , Fixup , and T-Fixup .
Conclusion
In this paper, we have shown how train deeper transformer-based image classification neural networks when training on Imagenet only. We have also introduced the simple yet effective CaiT architecture designed in the spirit of encoder/decoder architectures. Our work further demonstrates that transformer models offer a competitive alternative to the best convolutional neural networks when considering trade-offs between accuracy and complexity.
Acknowledgments
Thanks to Jakob Verbeek for his detailled feedback on an earlier version of this paper, to Alaa El-Nouby for fruitful discussions, to Mathilde Caron for suggestions regarding the vizualizations, and to Ross Wightman for the Timm library and the insights that he shares with the community.
References
Appendix A Variations on LayerScale init
For the sake of simplicity and to avoid overfitting per model, we have chosen to do a constant initialization with small values depending on the model depth. In order to give additional insight on the importance of this initialization we compare in Table A.1 other possible choices.
We initialize all coefficients of LayerScale to 0. This resembles Rezero, but in this case we have distinct learnable parameters for each channel. We make two observations. First, this choice, which also starts with residual branches that output 0 the beginning of the training, gives a clear boost compared to the block-wise scaling done by our adapted ReZero. This confirms the advantage of introducing a learnable parameter per channel and not only per residual layer. Second, LayerScale is better: it is best to initialize to a small different from zero.
We have tested a version in which we try a different initial weight per channel, but with the same average contribution of each residual block as in LayerScale. For this purpose we initialize the channel-scaling values with the Uniform law (). This simple choice choice ensures that the expectation of the scaling factor is equal to the value of the classical initialization of LayerScale. This choice is overall comparable to the initialization to 0 of the diagonal, and inferior to LayerScale.
LayerScale makes it possible to get increased performance by training deeper models. At the end of training we obtain a specific set of scaling factors for each layer. Inspired by the lottery ticket hypothesis , one question that arises is whether what matters is to have the right scaling factors, or to include these learnable weights in the optimization procedure. In other terms, what happens if we re-train the network with the scaling factors obtained by a previous training?
In this experiment below, we try to empirically answer that question. We compare the performance (top-1 validation accuracy, %) on ImageNet-1k with DeiT-S architectures of differents depths. Everything being identical otherwise, in the first experiment we use LayerScale, i.e. we have learnable weights initialized at a small value . In the control experiment we use fixed scaling factors initialised at values obtained by the LayerScale training.
We can see that the control training with fixed weights also converges, but it is only slightly better than the baseline with adjusted stochastic depth drop-rate . Nevertheless, the results are lower than those obtained with the learnable weighting factors. This suggests that the evolution of the parameters during training has a beneficial effect on the deepest models.
Appendix B Design of the class-attention stage
In this subsection we report some results obtained when considering alternative choices for the class-attention stage.
In our approach we chose to insert the class embedding in the class-attention: By defining
If we remove LayerScale in the Class-Attention blocks in the CaiT-S-36 model, we obtain a top-1 accuracy of 83.36% on ImageNet1k-val, versus 83.44% with LayerScale. The difference of +0.08% is not significant enough to conclude on a clear advantage. For the sake of consistency we have used LayerScale after all residual blocks of the network.
In the main paper we report results with the hard distillation proposed by Touvron et al. , which in essence replaces the label by the average of the label and the prediction of the teacher output. This is the choice we adopted in our main paper, since it provides better performance than traditional distillation.
The DeiT authors also show the advantage of considering an additional “distillation token”. In their case, employed with the ViT/DeiT architecture, this choice improves the performance compared to hard distillation. Noticeably it accelerates convergence.
In Table B.1 we report the results obtained when inserting a distillation token at the same layer as the class token, i.e., on input of the class-attention stage. In our case we do not observe an advantage of this choice over hard distillation when using class-attention layers. Therefore in our paper we have only considered the hard distillation also employed by Touvron et al. .