NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Not All Images are Worth 16x16 Words: Dynamic Transformers for Efficient Image Recognition

Yulin Wang, Rui Huang, Shiji Song, Zeyi Huang, Gao Huang

TL;DR

Vision Transformers typically process images using a fixed number of patches (tokens), which wastes computation on "easy" images that require less detail. This paper introduces the Dynamic Vision Transformer (DVT), a framework that cascades models with increasing token counts and halts inference early for confident predictions. By cleverly reusing features and attention relationships across stages, DVT significantly cuts computational costs (up to 3.6x) and accelerates real-world inference without sacrificing accuracy.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have achieved state-of-the-art performance in image recognition by splitting images into sequences of patches (tokens) and applying self-attention. Because the computational cost of self-attention scales quadratically with the number of tokens, researchers typically settle on a fixed, one-size-fits-all resolution (like 14x14 or 16x16 tokens) to balance accuracy and speed.

However, the authors observe that not all images are equally difficult. A clear, well-framed picture of an apple might be easily classified using a coarse 4x4 token grid, while a cluttered scene with a small bird or a complex palace might require a fine-grained 14x14 grid.

Motivation for Dynamic Vision Transformers: "Easy" images like the apple can be recognized with a coarse grid, while "hard" images require finer resolution.

By forcing all images through a high-resolution grid, standard ViTs waste massive amounts of compute on "easy" images. The challenge is how to dynamically adjust the token count on a per-image basis to optimize efficiency without losing the ability to recognize "hard" images.

Methods

The authors propose the Dynamic Vision Transformer (DVT), which cascades multiple Transformer models trained with increasing numbers of tokens (e.g., 7x7, then 10x10, then 14x14).

Architecture of the Dynamic Vision Transformer (DVT), featuring cascaded models, early exits, and mechanisms for feature and relationship reuse.

During inference, an image is first processed by the lightweight, low-token Transformer. If the model's prediction confidence (the maximum softmax probability) exceeds a learned threshold, inference terminates early. If the model is uncertain, the image is passed to the next Transformer with a higher token count.

To prevent the computation from the early stages from being wasted, the authors introduce two novel reuse mechanisms:

  1. Feature Reuse: The downstream model doesn't start from scratch. The final token representations from the upstream model are transformed into a "context embedding" and injected directly into the Multi-Layer Perceptron (MLP) blocks of the downstream model.
  2. Relationship Reuse: ViTs learn rich self-attention maps that capture how different parts of an image relate to one another. DVT takes the attention logits from all layers of the upstream model, processes them through a small transformation network (which carefully reshapes and upsamples them spatially), and adds them to the attention logits of the downstream model.

Datasets

  • ImageNet (ILSVRC2012): The primary benchmark used for training and evaluation (1.2M training images, 1,000 classes).
  • CIFAR-10 & CIFAR-100: Used to demonstrate the transferability and robustness of the DVT framework on smaller-scale datasets.

Key Insights and Ideas

  • The 8.5x Compute Gap: The authors found that a baseline model using 14x14 tokens only recognized ~15.9% more test samples than a model using 4x4 tokens, but required 8.5x more computational FLOPs. This massive disparity is the core motivation for adaptive token scaling.
  • Cascading > Adaptive Depth for ViTs: In Convolutional Neural Networks (CNNs), dynamic efficiency is often achieved by exiting early from intermediate layers (adaptive depth). The authors found that for ViTs, this layer-adaptive approach performs poorly. Cascading entirely separate models with varying token resolutions yields much better accuracy-efficiency trade-offs.
  • Attention maps are highly reusable: Reusing the upstream attention maps provides a significant accuracy boost to the downstream model with almost zero computational overhead. However, because attention maps are $N \times N$ matrices, they cannot be naively upsampled; they must be reshaped back into their spatial $H \times W$ dimensions before scaling.

Key Results

  • Massive FLOP Reduction: On ImageNet, DVT reduces the computational cost of the T2T-ViT backbone by 1.6x to 3.6x while maintaining the exact same accuracy.
  • Real-World Speedup: Theoretical FLOP reductions translate well to actual hardware. On an NVIDIA 2080Ti GPU, DVT accelerated the inference of large models (like T2T-ViT-14) by 1.4x to 1.7x. For smaller models, it boosted accuracy by up to 6.8% without slowing down throughput.
  • SOTA Efficiency: DVT outperforms existing dynamic inference networks (like MSDNet and RANet) and other ViT-specific efficiency methods (like DynamicViT and Patch Slimming). For example, a DVT based on DeiT-small achieved 81.2% accuracy at 3.61 GFLOPs, compared to the baseline's 79.8% at 4.61 GFLOPs.
  • On-the-fly Flexibility: The computational budget of a deployed DVT can be adjusted instantly just by tweaking the confidence thresholds, requiring no model retraining.

Limitations and Future Work

While the paper does not explicitly detail a dedicated limitations section, a few constraints are apparent. Training a DVT requires training multiple cascaded Transformers simultaneously, which increases the memory footprint and training time compared to a single standard model.

For future work, the authors note that DVT is a highly flexible, general framework. It is entirely orthogonal to other efficiency techniques, meaning it could be combined with knowledge distillation or intra-model patch pruning to push the boundaries of Vision Transformer efficiency even further.

Summary updated

BibTeX
@inproceedings{wang2021not,
  author = {Yulin Wang and Rui Huang and Shiji Song and Zeyi Huang and Gao Huang},
  title = {{Not All Images are Worth 16x16 Words: Dynamic Transformers for Efficient Image Recognition}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=M0J1c3PqwKZ},
}
Figure