Chasing Sparsity in Vision Transformers: An End-to-End Exploration

Abstract:
Vision transformers (ViTs) have recently received explosive popularity, but their enormous model sizes and training costs remain daunting. Conventional posttraining pruning often incurs higher training budgets. In contrast, this paper aims to trim down both the training memory overhead and the inference complexity, without sacrificing the achievable accuracy. We carry out the first-of-its-kind comprehensive exploration, on taking a unified approach of integrating sparsity in ViTs “from end to end”. Specifically, instead of training full ViTs, we dynamically extract and train sparse subnetworks, while sticking to a fixed small parameter budget. Our approach jointly optimizes model parameters and explores connectivity throughout training, ending up with one sparse network as the final output. The approach is seamlessly extended from unstructured to structured sparsity, the latter by considering to guide the prune-and-grow of self-attention heads inside ViTs. We further co-explore data and architecture sparsity for additional efficiency gains by plugging in a novel learnable token selector to adaptively determine the currently most vital patches. Extensive results on ImageNet with diverse ViT backbones validate the effectiveness of our proposals which obtain significantly reduced computational cost and almost unimpaired generalization. Perhaps most surprisingly, we find that the proposed sparse (co-)training can sometimes improve the ViT accuracy rather than compromising it, making sparsity a tantalizing “free lunch”. For example, our sparsified DeiT-Small at (5%, 50%) sparsity for (data, architecture), improves 0.28% top-1 accuracy, and meanwhile enjoys 49.32% FLOPs and 4.40% running time savings. Our codes are available at https: //github.com/VITA-Group/SViTE.

text: Vision transformers (ViTs) have recently received explosive popularity, but their enormous model sizes and training costs remain daunting. Conventional posttraining pruning often incurs higher training budgets. In contrast, this paper aims to trim down both the training memory overhead and the inference complexity, without sacrificing the achievable accuracy. We carry out the first-of-its-kind comprehensive exploration, on taking a unified approach of integrating sparsity in ViTs “from end to end”. Specifically, instead of training full ViTs, we dynamically extract and train sparse subnetworks, while sticking to a fixed small parameter budget. Our approach jointly optimizes model parameters and explores connectivity throughout training, ending up with one sparse network as the final output. The approach is seamlessly extended from unstructured to structured sparsity, the latter by considering to guide the prune-and-grow of self-attention heads inside ViTs. We further co-explore data and architecture sparsity for additional efficiency gains by plugging in a novel learnable token selector to adaptively determine the currently most vital patches. Extensive results on ImageNet with diverse ViT backbones validate the effectiveness of our proposals which obtain significantly reduced computational cost and almost unimpaired generalization. Perhaps most surprisingly, we find that the proposed sparse (co-)training can sometimes improve the ViT accuracy rather than compromising it, making sparsity a tantalizing “free lunch”. For example, our sparsified DeiT-Small at (5%, 50%) sparsity for (data, architecture), improves 0.28% top-1 accuracy, and meanwhile enjoys 49.32% FLOPs and 4.40% running time savings. Our codes are available at https: //github.com/VITA-Group/SViTE.

heading: 1 Introduction
text: Recent years have seen substantial efforts devoted to scaling deep networks to enormous sizes. Parameter counts are frequently measured in billions rather than millions, with the time and financial outlay necessary to train these models growing in concert. The trend undoubtedly continues with the recent forefront of transformers [1–3] for computer vision tasks. By leveraging self-attention, reducing weight sharing such as convolutions, and feeding massive training data, vision transformers have established many new state-of-the-art (SOTA) records in image classification [1, 2], object detection [4–7], image enhancement [8, 9], and image generation [10–12]. Existing vision transformers and variants, despite the impressive empirical performance, have in general suffered from gigantic parameter-counts, heavy run-time memory usages, and tedious training. That naturally calls for the next step research of slimming their inference and training, without compromising the performance.
Model compression and efficient learning are no strangers to deep learning researchers, although their exploration in the emerging vision transformer field remains scarce [13]. Among the large variety of compression means [14], sparsity has been one of the central themes since the beginning [15].
35th Conference on Neural Information Processing Systems (NeurIPS 2021).
Conventional approaches first train dense networks, and then prune a large portion of parameters in the trained networks to zero. Those methods significantly reduce the inference complexity. However, the price is to cost even more significant computational resources and memory footprints at training, since they commonly require (multiple rounds of) re-training to restore the accuracy loss [15–17]. That price becomes particularly prohibitive for vision transformers, whose vanilla one-pass training is already much more tedious, slow, and unstable compared to training standard convolutional networks.
An emerging subfield has explored the prospect of directly training smaller, sparse subnetworks in place of the full networks without sacrificing performance. The key idea is to reuse the sparsity pattern found through pruning and train a sparse network from scratch. The seminal work of lottery ticket hypothesis (LTH) [18] demonstrated that standard dense networks contain sparse matching subnetworks (sometimes called “winning tickets”) capable of training in isolation to full accuracy. In other words, we could have trained smaller networks from the start if only we had known which subnetworks to choose. Unfortunately, LTH requires to empirically find these intriguing subnetworks by an iterative pruning procedure [18–27] , which still cannot get rid of the expensiveness of posttraining pruning. In view of that, follow-up works reveal that sparsity patterns might emerge at the initialization [28, 29], the early stage of training [30, 31], or in dynamic forms throughout training [32–34] by updating model parameters and architecture typologies simultaneously. These efforts shed light on the appealing prospect of “end to end” efficiency from training to inference, by involving sparsity throughout the full learning lifecycle.
This paper presents the first-of-its-kind comprehensive exploration of integrating sparsity in vision transformers (ViTs) “from end to end”. With (dynamic) sparsity as the unified tool, we can improve the inference efficiency from both model and data perspectives, while also saving training memory costs. Our innovative efforts are unfolded along with the following three thrusts:
• From Dense to (Dynamic) Sparse: Our primary quest is to find sparse ViTs without sacrificing the achievable accuracy, and meanwhile trimming down the training memory overhead. To meet this challenging demand, we draw inspirations from the latest sparse training works [34, 35] that dynamically extract and train sparse subnetworks instead of training the full models. Sticking to a fixed small parameter budget, our technique jointly optimizes model parameters and explores connectivity throughout the entire training process. We term our first basic approach as Sparse Vision Transformer Exploration (SViTE).
• From Unstructured to Structured: Most sparse training works [32, 33, 36–39, 38, 34, 40, 41, 35] restricted discussion to unstructured sparsity. To attain structured sparsity which is more hardware-friendly, unlike classical channel pruning available for convolutional networks, we customize a first-order importance approximation [16, 42] to guide the pruneand-grow of self-attention heads inside ViTs. This seamlessly extends SViTE to its second variant of Structured Sparse Vision Transformer Exploration (S2ViTE).
• From Model to Data: We further conduct a unified co-exploration towards joint data and architecture sparsity. That is by plugging in a novel learnable token selector to determine the most vital patch embeddings in the current input sample. The resultant framework of Sparse Vision Transformer Co-Exploration (SViTE+) remains to be end-to-end trainable and can gain additional efficiency.
Extensive experiments are conducted on ImageNet with DeiT-Tiny/Small/Base. Results of substantial computation savings and nearly undamaged accuracies consistently endorse our proposals’ effectiveness. Perhaps most impressively, we find that the sparse (co-)training can even improve the ViT accuracy rather than compromising it, making sparsity a tantalizing “free lunch”. For example, applying SViTE+ on DeiT-Small produces superior compressed ViTs at 50% model sparsity plus 5% data sparsity, saving 49.32% FLOPs and 4.40% running time, while attaining a surprising improvement of 0.28% accuracy; even when the data sparsity increases to 10% (the model sparsity unchanged), there is still no accuracy degradation, meanwhile saving 52.38% FLOPs and 7.63% running time.

heading: 2 Related Work
text: Vision Transformer. Transformer [43] stems from natural language processing (NLP) applications. The Vision Transformer (ViT) [1] pioneered to leverage a pure transformer, to encode an image by splitting it into a sequence of patches, projecting them into token embeddings, and feeding them to
transformer encoders. With sufficient training data, ViT is able to outperform convolution neural networks on various image classification benchmarks [1, 44]. Many ViT variants have been proposed since then. For example, DeiT [2] and T2T-ViT [45] are proposed to enhance ViT’s training data efficiency, by leveraging teacher-student and better crafted architectures respectively. In addition to image classification, ViT has attracted wide attention in diverse computer vision tasks, including object detection [4–7], segmentation [46, 47], enhancement [8, 9], image generation [10–12], video understanding [48, 49], vision-language [50–57] and 3D point cloud [58].
Despite the impressive empirical performance, ViTs are generally heavy to train, and the trained models remain massive. That naturally motivates the study to reduce ViT inference and training costs, by considering model compression means. Model compression has been well studied in both computer vision and NLP applications [59–61, 42, 62, 21]. Two concurrent works [13, 63] made initial attempts towards ViT post-training compression by pruning the intermediate features and tokens respectively, but did not jointly consider weight pruning nor efficient training. Another loosely related field is the study of efficient attention mechanisms [64, 10, 52, 65–75]. They mainly reduce the calculation complexity for self-attention modules via various approximations such as low-rank decomposition. Our proposed techniques represent an orthogonal direction and can be potentially combined with them, which we leave as future work. Another latest concurrent work [76] introduced an interpretable module to dynamically and gracefully drop the redundant patches, gaining not only inference efficiency but also interpretability. Being a unique and orthogonal effort from ours, their method did not consider the training efficiency yet.
Pruning and Sparse Training. Pruning is well-known to effectively reduce deep network inference costs [77, 15]. It can be roughly categorized into two groups: (i) unstructured pruning by removing insignificant weight elements per certain criterion, such as weight magnitude [78, 15], gradient [16] and hessian [79]; (ii) structured pruning [80–82] by remove model sub-structures, e.g., channels [80, 81] and attention heads [42], which are often more aligned with hardware efficiency. All above require training the full dense model first, usually for several train-prune-retrain rounds.
The recent surge of sparse training seeks to adaptively identify high-quality sparse subnetworks and train only them. Starting from scratch, those methods learn to optimize the model weights together with sparse connectivity simultaneously. [32, 33] first introduced the Sparse Evolutionary Training (SET) technique [32], reaching superior performance compared to training with fixed sparse connectivity [83, 36]. [37–39] leverages “weight reallocation" to improve performance of obtained sparse subnetworks. Furthermore, gradient information from the backward pass is utilized to guide the update of the dynamic sparse connectivity [38, 34], which produces substantial performance gains. The latest investigations [40, 41, 35] demonstrate that more exhaustive exploration in the connectivity space plays a crucial role in the quality of found sparse subnetworks. Current sparse training methods mostly focus on convolutional networks. Most of them discuss unstructured sparsity, except a handful [84, 30] considering training convolutional networks with structured sparsity.

heading: 3 Methodology
text: Our SViTE method (and its variants S2ViTE and SViTE+) is inspired from state-of-the-art sparse training approaches [34, 35] in CNNs. This section presents the sparse exploration of ViT architectures, then shows the detailed procedure of input token selection for extra efficiency gains.

heading: 3.1 Sparse ViT Exploration
text: Revisiting sparse training. Sparse training starts from a randomly sparsified model; after optimizing several iterations, it shrinks a portion of parameters based on pre-defined pruning criterion, and activates new connections w.r.t. grow indicators. After upgrading the sparse topology, it trains the new subnetwork until the next update of the connectivity. An illustration of the overall procedure is shown in Figure 1. The key factors of sparse training are ¶ sparsity distribution, · update schedule, ¸ pruning and ¹ grow criterion.
Notations. For a consistent description, we follow the standard notations in [34, 35]. Let D be the training dataset. bt ∼ D is a randomly sampled data batch for iteration t. fW (·) represents the model with parameters W = (W (1), · · · ,W (L)), where W (l) ∈ RNl , 1 ≤ l ≤ L, Nl is the
number of prunable parameters in the lth layer, and L denotes the number of transformer layers. Note that the first linear projection layer and the classifier of ViT [1, 2] are not sparsified in our framework. As illustrated in Figure 1(bottom-left), W (l)Q = {W (l,h) Q }Hh=1, W (l) K = {W (l,h) K }Hh=1, W (l) V = {W (l,h) V }Hh=1 are the weights of the self-attention module in the lth layer, W (l,1), W (l,2), W (l,3) are the weights of the multilayer perceptron (MLP) module in the lth layer, and W (l) = (W
(l) Q ,W (l) K ,W (l) V ,W (l,1),W (l,2),W (l,3)) collectively represent all the parameters in the lth layer, where H denotes the number of attention heads, and 1 ≤ h ≤ H . X(l), Q(l), K(l), and V (l) are the corresponding input and intermediate features, respectively. Each sparse layer only maintains a fraction sl ∈ (0, 1) of its connections, and the overall sparsity of a sparse subnetwork is calculated as the ratio of pruned elements to the total parameter counts, i.e., ∑ l sl×Nl∑
lNl .
Sparse Vision Transformer Exploration (SViTE). SViTE explores the unstructured sparse topology in vision transformers. To be specific, we adopt Erdös-Rényi [32] as our ¶ sparsity distribution. The number of parameters in the sparse layer is scaled by 1 − nl−1+nlnl−1×nl , where nl is the number of neurons at layer l. This distribution allocates higher sparsities to the layers with more parameters by scaling the portion of remaining weights with the sum of the number of output and input neurons/channels. For the · update schedule, it contains: (i) the update interval ∆T, which is the number of training iterations between two sparse topology updates; (ii) the end iteration Tend, indicating when to stop updating the sparsity connectivity, and we set Tend to 80% of total training iterations in our experiments; (iii) the initial fraction α of connections that can be pruned or grow, which is 50% in our case; (iv) a decay schedule of the fraction of changeable connections fdecay(t, α,Tend) = α 2 (1+cos( t×π Tend
)), where a cosine annealing is used, following [34, 35]. During each connectivity update, we choose the weight magnitude as ¸ the pruning indicator, and gradient magnitude as ¹ the grow indicator. Specifically, we eliminate the parameters with the layer-wise smallest weight values by applying a binary mask mprune, then grow new connections with the highest magnitude gradients by generating a new binary mask mgrow. Both masks are employed to W (l) via the element-wise dot product, and note that the number of non-zero elements in mprune and mgrow are equal and fixed across the overall procedure. Newly added connections are not activated in the last sparse topology, and are initialized to zero since it produces better performance as demonstrated in [34, 35].
Infrequent gradient calculation [34] is adopted in our case, which computes the gradients in an online manner and only stores the top gradient values. As illustrated in [34], such fashion amortizes the extra effort of gradient calculation, and makes it still proportional to 1 − s as long as ∆T ≥ 11−s , where s is the overall sparsity.
Structured Sparse Vision Transformer Exploration (S2ViTE). Although models with unstructured sparsity achieve superior performance, structured sparsity [80–82] is much more hardware friendly and brings practical efficiency on realistic platforms, which motivates us to propose Structured Sparse ViT Exploration (S2ViTE). We inherit the design of ¶ sparsity distribution and · update schedule from the unstructured SViTE, and a round-up function is used to eliminate decimals in the parameter counting. The key differences lie in the new ¸ pruning and ¹ grow strategies.
Algorithm 1 Sparse ViT Co-Exploration (SViTE+). Initialize: ViT model fW , Dataset D, Sparsity dis-
tribution S = {s1, · · · , sL}, Update schedule {∆T,Tend, α, fdecay}, Learning rate η 1: Initialize fW with random sparsity S . Highly reduced parameter count. 2: for each training iteration t do 3: Sampling a batch bt ∼ D 4: Scoring the input token embeddings and selecting the top-k informative tokens . Token selection 5: if (t mod ∆T == 0) and t < Tend then 6: for each layer l do 7: ρ = fdecay(t, α,Tend) · (1− sl) ·Nl 8: Performing prune-and-grow with portion ρ
w.r.t. certain criterion, generating masks mprune and mgrow to update fW ’s sparsity patterns . Connectivity exploration
9: end for 10: else 11: W = W − η · ∇WLt . Updating Weights 12: end if 13: end for 14: return a sparse ViT with a trained token selector
Pruning criterion: LetA(l,h) denote features computed from the self-attention head {W (l,h)Q , W (l,h) K , W (l,h) V } and input embeddings X(l), as shown in Figure 1. We perform the Taylor expansion to the loss function [16, 42], and derive a proxy score for head importance blow:
I(l,h)p = ∣∣∣∣AT(l,h) · ∂L(X(l))∂A(l,h) ∣∣∣∣, (1) where L(·) is the cross-entropy loss as used in ViT. During each topology update, we remove attention heads with the smallest I(l,h)p . For MLPs, we score neurons with `1-norm of their associated weight vectors [85], and drop insignificant neurons. For example, the jth neuron of W (l,1) in Figure 1 has an importance score ‖W (l,1)j,· ‖`1 , where W
(l,1) j,· is the jth row of W (l,1).
Grow criterion: Similar to [34, 35], we active the new units with the highest magnitude gradients, such as ‖∂L(X
(l)) ∂A(l,h) ‖`1 and ‖ ∂L(X(l)) ∂W (l,1) j,· ‖`1 for the hth attention head and the jth
neuron of the MLP (W (l,1)), respectively. The gradients are calculated in the same manner as the one in unstructured SViTE, and newly added units are also initialized to zero.

heading: 3.2 Data and Architecture Sparsity Co-Exploration for Higher Efficiency
text: Algorithm 2 The top-k selector in a PyTorch-like style. def topk_selector(logits, k, tau, dim=-1): # Maintain tokens with the top-$k$ highest scores
gumbels = -torch.empty_like(logits).exponential_().log() gumbels = (logits + gumbels) / tau # tau is the temperature y_soft = gumbels.softmax(dim) # Straight through index = y_soft.topk(k, dim=dim)[1] y_hard = scatter(logits, index, k) ret = y_hard - y_soft.detach() + y_soft return ret Besides exploring sparse transformer architectures, we further slim the dimension of input token embeddings for extra efficiency bonus by leveraging a learnable token selector, as presented in Figure 1. Meanwhile, the introduced data sparsity also serves as an implicit regularization for ViT training, which potentially leads to improved generalization ability, as evidenced in Table 6. Note that, due to skip connections, the number of input tokens actually determines the dimension of intermediate features, which substantially contributes to the overall computation
cost. In other words, the slimmed input token embeddings directly result in compressed intermediate features, and bring substantial efficiency gains.
For the input tokens X(1) ∈ Rn×d, where n denotes the number of tokens to be shrunk, and d is the dimension of each token embedding that keeps unchanged. As shown in Figure 1, all token embeddings are passed through a learnable scorer function which is parameterized by an MLP in our experiments. Then, a selection of the top-k importance scores (1 ≤ k ≤ d) is applied on top of it, aiming to preserve the significant tokens and remove the useless ones. To optimize parameters of the scorer function, we introduce the popular Gumbel-Softmax [86, 87] and straight-through tricks [88] to enable gradient back-propagation through the top-k selection, which provides an efficient solution to draw samples from a discrete probability distribution. A detailed implementation is in Algorithm 2.
The full pipeline of data and architecture co-exploration is summarized in Algorithm 1. We term this approach SViTE+. We first feed the randomly sampled data batch to the token selector and pick the top-k informative token embeddings. Then, we alternatively train the sparse ViT for ∆T iterations and perform prune-and-grow to explore the sparse connectivity in ViTs dynamically. In the end, a sparse ViT model with a trained token selector is returned and ready for evaluation.

heading: 4 Experiments
text: Baseline pruning methods. We extend several effective pruning methods from CNN compression as our strong baselines. Unstructured pruning: (i) One-shot weight Magnitude Pruning (OMP) [15], which removes insignificant parameters with the globally smallest weight values; (ii) Gradually Magnitude Pruning (GMP) [17], which seamlessly incorporates gradual pruning techniques within the training process by eliminating a few small magnitude weights per iteration; and (iii) Taylor Pruning (TP) [16], which utilizes the first-order approximation of the training loss to estimate units’ importance for model sparsification. Structured pruning: Salience-based Structured Pruning (SSP). We draw inspiration from [42, 85], and remove sub-modules in ViT (e.g., self-attention heads) by leveraging their weight, activation, and gradient information. Moreover, due to the repetitive architecture of ViT, we can easily reduce the number of transformer layers to create a smaller dense ViT (Small-Dense) baseline that has similar parameter counts to the pruned ViT model.
Implementation details. Our experiments are conducted on ImageNet with DeiTTiny/Small/Base backbones. The detailed training configurations are listed in Table 1, which mainly follows the default setups in [2]. All involved customized hyperparameters are tuned via grid search (later shown in Figure 3). For a better exploration of sparsity connectivities, we increase training epochs to 600 for all experiments. GMP [17] has an additional hyperparameter, i.e., the pruning schedule, which starts from 16 and ends at 1 2 of the training epochs with 20 times pruning in total. More details are referred to Appendix A1.
Training time measuring protocol. We strictly measure the running time saving of
(sparse) vision transformers on the ImageNet-1K task using CUDA benchmark mode. To be specific, we separately calculate the time elapsed during each iteration, to eliminate the impact of the hardware environment as much as possible. Note that the time for the data I/O is excluded.
Highlight of our findings. The overall performance of SViTE, S2ViTE, and SViTE+ on DeiT backbones are summarized in Figure 2. We highlight some takeaways below.
Takeaways: ¶ SViTE produces sparse DeiTs with enhanced generalization and substantial reduced FLOPs, compared to its dense counterpart (?). SViTE+ further improves the performance of SViTE by selecting the most vital patches. · S2ViTE achieves matched accuracy on DeiT-Small, and significantly enhances performance on DeiT-Base. Meanwhile, its structural sparsity brings considerable running time savings. ¸ Appropriate data and architecture sparsities can effectively regularize ViT training, leading to a new SOTA win-win between ViT accuracy and efficiency.

heading: 4.1 SViTE with Unstructured Sparsity
text: We perform SViTE to mine vital unstructured sparsity in DeiTs [2]. Solid lines in Figure 2 record the top-1 test-set accuracy over FLOPs on ImageNet-1K of SViTE-Small and SViTE-Base with a range of sparsity from 30% to 70%. In general, we observe that SViTE generates superior sparse ViTs with both accuracy and efficiency gains. Table 2, 3, and 5 present the comparison between SViTE and various pruning baselines. From these extensive results, we draw several consistent observations. First, compared to the dense baselines, SViTE-Tiny, -Small, and -Base obtain 25.56% ∼ 34.16%, 46.26% ∼ 55.44%, and 47.95% ∼ 57.50% FLOPs reduction, respectively, at 30% ∼ 60% sparsity levels with only a negligible accuracy drop within 0.5%. It verifies the effectiveness of our proposal, and indicates severe parameter redundancy in ViT. Second, our SViTE models from dynamic explorations consistently surpass other competitive baseline methods, including OMP, GMP, TP, and Small-Dense by a substantial performance margin. Among all the baseline approaches, GMP that advocates a gradual pruning schedule achieves the best accuracy with all three DeiT backbones. Third, in Figure 2, both SViTE-Small (blue solid line) and SViTE-Base (green solid line) show an improved trade-off between accuracy and efficiency, compared to their dense DeiT counterparts. Interestingly, we also observe that with similar parameter counts, a large sparse ViT consistently outperforms the corresponding smaller dense ViT. A possible explanation is those appropriate sparse typologies regularize network training and lead to enhanced generalization, which coincides with recent findings of critical subnetworks (i.e., winning tickets) in dense CNNs [89, 22] and NLP transformer [21, 90] models.
4.2 S2ViTE with Structured Sparsity
For more practical benefits, we investigate sparse DeiTs with structured sparsity. Results are summarized in Table 4. Besides the obtained 23.79% ∼ 33.63% FLOPs savings, S2ViTE-Tiny, S2ViTE-
Small, and S2ViTE-Base enjoy an extra 10.57%, 22.65%, and 24.70% running time reduction, respectively, from 30% ∼ 40% structured sparsity with competitive top-1 accuracies. Furthermore, S2ViTE consistently outperforms the baseline structured pruning method (SSP), which again demonstrates the superior sparse connectivity learned from dynamic sparse training.
The most impressive results come from S2ViTE-Base at 40% structured sparsity. It even surpasses the dense DeiT base model by 0.42% ∼ 1.24% accuracy with 34.41% parameter counts, 33.13% FLOPs, and 24.70% running time reductions. We conclude that (i) an adequate sparsity from S2ViTE boosts ViT’s generalization ability, which can be regarded as an implicit regularization; (ii) larger ViTs (e.g., DeiT-Base) tend to have more superfluous self-attention heads, and are more amenable to structural sparsification from S2ViTE, based on Figure 2 where dash lines denote the overall performance of S2ViTE-Small and S2ViTE-Base with a range of sparsity from 30% to 70%.
Table 5: Results of SViTE-Base on ImageNet-1K. Accuracies (%) within/out of parenthesis are the reproduced/reported [2] performance.
Models Sparsity (#Para.) FLOPs Saving Accuracy (%)
DeiT-Base 0% (86.6M) 0% 81.80 (80.98)
SViTE-Base 50% (43.4M) 47.95% 81.51 OMP 50% (43.4M) 47.94% 80.26 GMP 50% (43.4M) 47.95% 80.79 TP 50% (43.4M) 47.94% 80.55
SViTE-Base 60% (34.8M) 57.50% 81.28 OMP 60% (34.8M) 57.50% 80.25 GMP 60% (34.8M) 57.50% 80.44 TP 60% (34.8M) 57.49% 80.37
Small-Dense 0% (44.0M) 49.46% 78.59
Table 6: Results of SViTE+-Small on ImageNet-1K. Accuracies (%) within/out of parenthesis are the reproduced/reported [2] performance.
#Tokens (%) Time Reduced FLOPs Saving Accuracy (%)
SViTE+-Small 50% Unstructured Sparsity
100% 0% 46.26% 79.72 95% 4.40% 49.32% 80.18 90% 7.63% 52.38% 79.91 70% 19.77% 63.95% 77.90
S2ViTE+-Small 40% Structured Sparsity
100% 22.65% 31.63% 79.22 95% 27.17% 37.76% 78.44 90% 29.21% 41.50% 78.16 70% 39.10% 54.96% 74.77

heading: 4.3 SViTE+ with Data and Architecture Sparsity Co-Exploration
text: In this section, we study data and architecture sparsity co-exploration for ViTs, i.e., SViTE+. Blessed by the reduced input token embeddings, even ViTs with unstructured sparsity can have running time savings. The benefits are mainly from the shrunk input and intermediate feature dimensions. Without loss of generality, we consider SViTE+-Small with 50% unstructured sparsity and S2ViTE+-Small with 40% structured sparsity as examples. As shown in Table 6 and Figure 2, SViTE+-Small at 50% unstructured sparsity is capable of abandoning 5% ∼ 10% tokens while achieving 4.40% ∼ 7.63% running time and 49.32% ∼ 52.38% FLOPs savings, with even improved top-1 testing accuracy. It again demonstrates that data sparsity as an implicit regularizer plays a beneficial role in ViT training. However, slimming input and intermediate embedding is less effective when incorporated with S2ViTE, suggesting that aggressively removing structural sub-modules hurts ViT’s generalization.

heading: 4.4 Ablation and Generalization Study of SViTEs
text: Update interval in SViTE. The length of the update interval ∆T controls one of the essential tradeoffs in our proposed dynamic sparse exploration, since ∆T multiplying the number of updates is the pre-defined Tend. On the one hand, a larger updated interval (i.e., smaller update frequency) produces a more well-trained model for improved estimation of units’ importance. On the other hand, a larger update frequency (i.e., smaller ∆T) allows more sufficient exploration of sparse connectivities, which potentially generates higher-quality sparse subnetworks, as demonstrated in [35]. We evaluate this factor in our SViTE context, and collect the results in Figure 3 (Left). We observe that ∆T = 20000 works the best for SViTE-Tiny, and both larger and smaller ∆T degrade the performance.
65 .8
4
66 .7
7 68 .4
5
69 .0
9
69 .3
0
69 .6 0
68 .8
4
1 000 2000 5000 10000 15000 20000 25000
ACCURACY
68 .8
4
69 .6 0
67 .8
5
65 .7
2
1 024 512 256 128
ACCURACY
(∆T) ($)Update Interval Batch Size
Figure 3: Accuracy of SViTE-Tiny with 50% unstructured sparsity. Left: ablation studies of the update interval (∆T); Right: ablations studies of the adopted batch size (b).
indicates removed inessential patches.
Batch size in SViTE. Besides the update interval ∆T, batch size (b) also affects the aforementioned trade-off, especially for the data-hungry ViT training. We investigate different batch sizes in Figure 3 (Right), and find that b = 512 outperforms other common options for SViTE-Tiny.
Generalization study of SViTE and its variants. It is worth mentioning that our proposed frameworks (SViTE, S2ViTE, SViTE+) are independent of the backbone architectures, and can be easily plugged in other vision transformer models [91, 45, 92, 93]. We implemented both SViTE and S2ViTE on TNT-S [91]. SViTE-TNT-S gains 0.13 accuracy improvements (Ours: 81.63 v.s. TNT-S: 81.50) and 37.54% FLOPs savings at 40% unstructured sparsity; S2ViTE-TNT-S obtains 32.96% FLOPs and 23.71% running time reductions at 40% structured sparsity with almost unimpaired accuracy (Ours: 81.34 v.s. TNT-S:81.50).

heading: 4.5 Visualization
text: Sparse connectivity patterns. We provide unit-wise and element-wise heatmap visualizations for SViTE-Base with 40% structured sparsity in Figure A7 (in Appendix). Similarly, element-wise heatmap visualizations of SViTE-Base with 50% unstructured sparsity are displayed in Figure A6. We find that even unstructured sparsity exploration can develop obvious structural patterns (i.e., “vertical lines” in mask heatmaps), which implies a stronger potential for hardware speedup [95].
Self-attention heatmaps. As shown in Figure 4, we utilize tools in [94] to visualize attention maps of (sparse) ViTs. Multiple attention heads show similar behaviors, which implies the structural redundancy. Fortunately, S2ViTE eliminates unnecessary heads to some extent. With regard to SViTE-Base’s visual results, it seems to activate fewer attention heads for predictions (darker colors mean larger values), compared to the ones of dense DeiT-Base. We also observe that in the bottom layers, the attention probabilities are more centered at several heads; while in the top layers, the attention probabilities are more uniformly distributed. This kind of tendency is well preserved by our sparse ViT (SViTE) from Dense ViTs.
Learned patch selection patterns. Figure 5 presents the learned behaviors of our token selector in SViTE+. We observe that the useless removed patches are typically distributed around the main object
or in the background. Meanwhile, the patches within the objects of interest are largely persevered, which evidences the effectiveness of our learned patch token selector.

heading: 5 Conclusion and Discussion of Broader Impact
text: In this work, we introduce sparse ViT exploration algorithms, SViTE, and its variants S2ViTE and SViTE+, to explore high-quality sparse patterns in both ViT’s architecture and input token embeddings, alleviating training memory bottleneck and pursuing inference ultra-efficiency (e.g., running time and FLOPs). Comprehensive experiments on ImageNet validate the effectiveness of our proposal. Our informative visualizations further demonstrate that SViTE+ is capable of mining crucial connections and input tokens by eliminating redundant units and dropping useless token embeddings. Future work includes examining the performance of our sparse ViTs on incoming hardware accelerators [96–100], which will provide better supports for sparsity.
This work is scientific in nature, and we do not believe it has immediate negative societal impacts. Our findings of sparse vision transformers are highly likely to reduce both memory and energy costs substantially, leading to economic deployment in real-world applications (e.g., on smartphones).

heading: Acknowledgment
text: Z.W. is in part supported by an NSF RTML project (#2053279).

Review summaries:
This work proposes sparse ViT algorithms, named as SViTE and its variants S^2ViTE, and SViTE+, to explore high-quality sparse patterns in both ViT’s architecture and input token embeddings. The proposed methods can jointly optimize model parameters and explore connectivity throughout training. Experiments are conducted on ImageNet to validate the effectiveness of the proposed methods and find that SViTE+ can mine crucial connections and input tokens.

The author proposes three methods for achieving sparse vision transformers to reduce the number of parameters and FLOP. By using a dynamic structured sparsity injecting method, the authors are able to achieve promising speedup without loss of accuracy. For an example, the author claims to achieve 14.7% run time reduction with 0.42% accuracy improvement. However, the training settings of the author's experiments and the DeiT baseline are different. Thus, there are some ambiguities exits.

Vision Transformers (ViT) have attracted much attention recently; however their large model sizes and high training cost pose practical problems for computer vision tasks. This paper introduces sparse ViT exploration algorithms ($SViTE$, $S^2ViTE$, $SViTE+$) to explore sparse patterns in the ViT architectures. The goal is to alleviate the training memory bottleneck and achieving high inference efficiency. The authors conducted comprehensive experiments on ImageNet dataset to validate their approach.

This work pioneered to study of various sparse training and pruning techniques to the recently proposed vision transformers (ViT). It shows the effectiveness of pruning/sparse training/data selection in such settings. This is a  interesting work for both ViT and sparse learning communities.