ThinkingViT: Matryoshka Thinking Vision Transformer for Elastic Inference

Ali Hojjat, Janek Haberer, Sören Pirk, Olaf Landsiedel

TL;DR

ThinkingViT introduces an input-adaptive, nested Vision Transformer (ViT) that dynamically scales its computational width based on image difficulty. By combining early-exit confidence checks with a novel "Token Recycling" mechanism, it skips redundant computation for simple images while activating more attention heads for complex ones, outperforming static nested baselines by up to 2.9 percentage points in accuracy at equal GMACs.

What Problem Does This Paper Address?

Vision Transformers (ViTs) deliver state-of-the-art performance but suffer from rigid computational pipelines: they spend the exact same amount of compute processing a clear, simple image of an object as they do a highly cluttered, ambiguous, or occluded scene. This lack of elasticity makes deployment across heterogeneous hardware (from edge devices to high-throughput servers) highly inefficient.

While recent "Matryoshka-style" nested models embed multiple subnetworks within a single backbone to scale to different hardware constraints at runtime, they still treat all inputs uniformly during a given inference pass. Previous attempts at input-dependent routing rely on separate, lightweight networks to predict image difficulty. However, these routers add computational overhead and often lack the representational capacity to accurately judge global image complexity. ThinkingViT solves this by enabling input-aware, dynamic compute allocation within a single backbone without relying on an external router.

Methods

ThinkingViT achieves elastic inference through two core mechanisms: Progressive Thinking Stages and Token Recycling.

  1. Progressive Thinking Stages: The authors slice a standard ViT backbone into nested subnetworks with sorted attention heads and embedding dimensions. Inference begins by activating only a small subset of the most important attention heads (e.g., 50%).
  2. The "Aha!" Moment: After this initial pass, the model calculates the Shannon entropy of its softmax output. If the entropy is below a predefined threshold (indicating high prediction certainty), inference terminates early to save compute. If the model is uncertain, it triggers the next thinking stage.
  3. Token Recycling: Instead of restarting from scratch in subsequent rounds, ThinkingViT recycles the processed token embeddings from the previous pass. It projects and fuses them back into the original input embeddings using a learnable scaling factor $\alpha$, allowing the wider subnetwork (e.g., 100% heads) to build directly upon prior knowledge.
ThinkingViT architecture and Token Recycling mechanism

Datasets

The model was trained and evaluated across several standard computer vision benchmarks:

  • Classification & Robustness: ImageNet-1K (core training/validation), ImageNet-V2, ImageNet-ReaL, ImageNet-R, ImageNet-A, and ImageNet-Sketch.
  • Downstream Tasks: ADE20K and Cityscapes for semantic segmentation.

Key Insights and Ideas

  • Naïve Recursion Fails in Vision: Simply looping an image through the exact same network repeatedly (a common strategy in reasoning-focused Large Language Models) quickly plateaus and fails to yield consistent accuracy gains in vision. True "thinking" in vision requires progressively scaling up representational capacity (width and attention heads).
  • Entropy as a Natural Difficulty Signal: Simple Shannon entropy serves as an excellent proxy for image complexity. Clear, single-object images naturally yield low entropy (left-skewed distribution), while complex or occluded images yield high entropy (right-skewed distribution), automatically prompting deeper inference.
  • Efficiency via Recycling: Reusing prior embeddings prevents the model from wasting compute re-learning low-level features. This allows a 22.1M parameter model to achieve accuracy competitive with models nearly four times its size (DeiT-Base at 86.6M parameters).

Key Results

  • ImageNet-1K Performance: ThinkingViT surpasses state-of-the-art nested baselines (such as MatFormer and HydraViT) by up to 2.0 percentage points (p.p.) in accuracy at the same throughput, and by up to 2.9 p.p. at equal GMACs.
Performance comparison on ImageNet-1K
  • Robustness to Distribution Shifts: On out-of-distribution datasets like ImageNet-ReaL, -Sketch, and -R, ThinkingViT exceeds the accuracy of DeiT-Base while utilizing significantly fewer parameters and lower GMACs.
  • Broad Adaptability: The backbone-preserving design allows ThinkingViT to act as a seamless plug-in upgrade. When integrated into hierarchical architectures like Swin Transformers, it matches Swin-B accuracy with far fewer GMACs. For semantic segmentation (using the Segmenter framework), additional thinking rounds visibly refine object boundaries and improve segmentation quality.

Limitations and Future Work

  • Downstream Task Expansion: While the authors successfully demonstrate ThinkingViT on classification and semantic segmentation, extending this progressive thinking mechanism to other complex vision tasks, such as DETR-style object detection, is left for future work.
  • Hyperparameter Tuning: The number of thinking stages and the step size for attention head expansion are currently hyperparameters that must be manually configured based on specific dataset characteristics and target efficiency objectives.

Summary updated

BibTeX
@inproceedings{hojjat2026thinkingvit,
  author = {Ali Hojjat and Janek Haberer and Sören Pirk and Olaf Landsiedel},
  title = {{ThinkingViT: Matryoshka Thinking Vision Transformer for Elastic Inference}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=x56YwcwU7U},
}
Figure