TL;DR
DynamicViT introduces an input-dependent token pruning framework that progressively removes redundant image patches across Vision Transformer (ViT) layers. By dropping up to 66% of tokens hierarchically, it cuts computational complexity (FLOPs) by 31–37% and increases real-world inference throughput by over 40% with less than a 0.5% drop in ImageNet accuracy.
What Problem Does This Paper Address?
Vision Transformers represent images as sequences of non-overlapping patch tokens. While effective, they treat every patch equally throughout the entire network depth, spending identical computational budgets on uninformative background patches (e.g., empty sky or plain backgrounds) as they do on primary objects.
Unlike Convolutional Neural Networks (CNNs)—where spatial pruning is constrained by fixed neighborhood sliding windows—transformers process permutation-invariant token sets, making variable-length sequence inputs feasible. However, realizing dynamic token pruning comes with two major challenges:
- Differentiability: Selecting discrete subsets of tokens to drop is fundamentally non-differentiable.
- Hardware/Batch Parallelism: Removing different numbers of tokens per image within a mini-batch results in jagged tensors, breaking GPU parallelization during training. Merely zeroing out pruned vectors also fails because zeroed tokens still affect attention weights via the Softmax denominator.
Methods
DynamicViT introduces a lightweight, end-to-end trainable framework consisting of:
- Lightweight Prediction Module: Inserted before chosen transformer layers (e.g., stages before blocks 4, 7, and 10 in a 12-layer backbone). It fuses local token projections with a globally pooled context feature to predict binary drop/keep probabilities via an MLP. Once dropped, a token is permanently excluded from downstream computation.
- Differentiable Sampling via Gumbel-Softmax: Uses the Gumbel-Softmax trick during training to sample discrete keep/drop decisions differentiably.
-
Attention Masking (Training without Token Removal): To maintain uniform tensor dimensions across batches during training, all tokens remain in memory. To completely block pruned tokens from interacting with surviving tokens without distorting the Softmax normalization, the self-attention affinity matrix is explicitly masked: $$\tilde{A}_{ij} = \frac{\exp(P_{ij}) G_{ij}}{\sum_{k=1}^N \exp(P_{ik}) G_{ik}}$$ where $G_{ij} = \hat{D}_j$ for $i \neq j$ and $G_{ii} = 1$ (retaining numerical stability via self-loops).
-
Multi-Task Training Loss: Combines standard cross-entropy with:
- Token-level self-distillation: Minimizing the MSE between the surviving tokens of DynamicViT and an unpruned teacher model.
- Prediction KL-divergence: Aligning logits with the teacher model.
- Ratio MSE constraint: Enforcing a target token retention ratio $\rho$ at each stage.
- Fast Inference: During runtime inference, attention masking is omitted. The network simply computes token keep probabilities, selects the top-$m_s$ tokens, and physically drops the rest, directly shrinking sequence lengths.
Input Tokens ──► [Transformer Blocks] ──► [Prediction Module] ──► Top-k Tokens Kept ──► [Next Blocks]
Datasets
- ImageNet-1K (ILSVRC-2012): Used for both pre-training backbones and fine-tuning/evaluating DynamicViT variants across standard $224 \times 224$ and high-resolution $384 \times 384$ inputs. No new datasets were introduced.
Key Insights and Ideas
- Unstructured Spatial Sparsity Suits Transformers: In CNNs, dropping arbitrary pixels destroys grid regularity. In self-attention, sequences of arbitrary lengths are natively supported, turning unstructured spatial sparsity into concrete GPU speedups.
- Hierarchical Over Single-Stage Pruning: Progressively pruning tokens across multiple stages preserves more context early on and outperforms aggressive single-stage pruning (79.3% vs. 77.4% top-1 on DeiT-S).
- Token Sparsification vs. Width Scaling: Pruning uninformative tokens is significantly more parameter- and FLOP-efficient than shrinking embedding width. For instance, applying DynamicViT to DeiT-256 achieves the computational budget of DeiT-Tiny but delivers +4.3% higher top-1 accuracy.
- Emergent Object Localization: Without explicit bounding-box supervision, statistical visualizations show the model learns spatial priors (preserving center patches) and gradually isolates foreground objects.
Key Results
Evaluated on DeiT-S, LV-ViT-S, and LV-ViT-M on ImageNet:
- DeiT-S ($\rho=0.7$): FLOPs drop by 37% (4.6G to 2.9G), GPU throughput jumps by +54% (1337.7 to 2062.1 img/s on an RTX 3090), with only a 0.5% accuracy drop (79.8% to 79.3%).
- LV-ViT-S ($\rho=0.7$): Reduces FLOPs by 31% (6.6G to 4.6G) with a throughput boost of +43% (993.3 to 1417.6 img/s) and a negligible 0.3% drop (83.3% to 83.0%).
- LV-ViT-M ($\rho=0.7$): At 8.5 GFLOPs, it achieves 83.8% top-1 accuracy, outperforming competitive CNN architectures like EfficientNet-B5 (83.6% @ 9.9G) and NFNet-F0 (83.6% @ 12.4G).
- Higher Resolutions ($384 \times 384$): On DeiT-S, DynamicViT slashes FLOPs by over 50% (15.5G to 7.0G) with only a 1.3% drop in top-1 accuracy.
Limitations and Future Work
- Task Scope: The study focuses strictly on image classification.
- Dense Predictions and Video: The authors note that adapting dynamic token pruning to structured dense-prediction tasks (object detection, semantic segmentation) and spatio-temporal video classification represents an important next step, where discarded spatial tokens may need reconstruction or multiscale handling.
Summary updated