DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification

Attention is sparse in vision transformers. We observe the final prediction in vision transformers is only based on a subset of most informative tokens, which is sufficient for accurate image recognition. Based on this observation, we propose a dynamic token sparsification framework to prune redundant tokens progressively and dynamically based on the input. Specifically, we devise a lightweight prediction module to estimate the importance score of each token given the current features. The module is added to different layers to prune redundant tokens hierarchically. To optimize the prediction module in an end-to-end manner, we propose an attention masking strategy to differentiably prune a token by blocking its interactions with other tokens. Benefiting from the nature of self-attention, the unstructured sparse tokens are still hardware friendly, which makes our framework easy to achieve actual speed-up. By hierarchically pruning 66% of the input tokens, our method greatly reduces 31%~37% FLOPs and improves the throughput by over 40% while the drop of accuracy is within 0.5% for various vision transformers. Equipped with the dynamic token sparsification framework, DynamicViT models can achieve very competitive complexity/accuracy trade-offs compared to state-of-the-art CNNs and vision transformers on ImageNet. Code is available at https://github.com/raoyongming/DynamicViT

PDF Abstract NeurIPS 2021 PDF NeurIPS 2021 Abstract

Datasets


Task Dataset Model Metric Name Metric Value Global Rank Benchmark
Image Classification ImageNet DynamicViT-LV-M/0.8 Top 1 Accuracy 83.9 # 347
Number of params 57.1M # 759
Hardware Burden None # 1
Operations per network pass None # 1
Efficient ViTs ImageNet-1K (with DeiT-S) DynamicViT (80%) Top 1 Accuracy 79.8 # 4
GFLOPs 3.4 # 33
Efficient ViTs ImageNet-1K (with DeiT-S) DynamicViT (90%) Top 1 Accuracy 79.8 # 4
GFLOPs 4.0 # 39
Efficient ViTs ImageNet-1K (with DeiT-S) DynamicViT (70%) Top 1 Accuracy 79.3 # 25
GFLOPs 2.9 # 19
Efficient ViTs ImageNet-1K (With LV-ViT-S) DynamicViT (70%) Top 1 Accuracy 83.0 # 10
GFLOPs 4.6 # 8
Efficient ViTs ImageNet-1K (With LV-ViT-S) DynamicViT (80%) Top 1 Accuracy 83.2 # 5
GFLOPs 5.1 # 3
Efficient ViTs ImageNet-1K (With LV-ViT-S) DynamicViT (90%) Top 1 Accuracy 83.3 # 3
GFLOPs 5.8 # 2

Methods