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

Patch n’ Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution

Mostafa Dehghani, Basil Mustafa, Josip Djolonga, Jonathan Heek, Matthias Minderer, Mathilde Caron, Andreas Peter Steiner, Joan Puigcerver, Robert Geirhos, Ibrahim Alabdulmohsin, Avital Oliver, Piotr Padlewski, Alexey A. Gritsenko, Mario Lucic, Neil Houlsby

Introduction

For over a decade, the standard pipeline in computer vision has been tethered to a rigid preprocessing constraint: resizing or cropping images into fixed square resolutions (e.g., 224x224). While this simplifies batching on modern hardware, it is fundamentally suboptimal. Resizing distorts the natural aspect ratio of objects, while cropping can discard critical information.

NaViT (Native Resolution ViT) breaks this paradigm by introducing "Patch n’ Pack," a technique that allows Vision Transformers to process images at their native aspect ratios and resolutions. By treating images as variable-length sequences of patches, NaViT significantly boosts training efficiency and enables a single model to flexibly navigate the cost-performance trade-off at inference time.

The Patch n' Pack Method

Vision Transformers (ViTs) are inherently sequence-based, yet they have historically inherited CNN-style spatial constraints. NaViT leverages the flexibility of sequences by treating images as variable-length collections of patches. The core innovation lies in several technical components:

  • Packing & Masking: Inspired by "example packing" in Natural Language Processing, NaViT packs patches from multiple different images into a single fixed-length sequence. To ensure images do not "talk" to each other, the model employs masked self-attention and masked pooling, restricting each token's receptive field to its own parent image.
  • Factorized Positional Embeddings: Standard ViTs use 1D or 2D learned embeddings that do not scale well to new resolutions. NaViT uses factorized embeddings, decomposing coordinates into separate $x$ and $y$ components that are summed. This allows the model to generalize to aspect ratios and resolutions never seen during training.
  • Resolution Sampling: During training, NaViT samples from a distribution of resolutions while always preserving the original aspect ratio, ensuring the model is exposed to a wide variety of scales.
  • Continuous Token Dropping: The model can randomly omit patches during training. Because of the packing mechanism, this does not leave "holes" in a batch; it simply allows more images to be packed into the same sequence, further increasing throughput.

Efficiency and Performance

The primary advantage of NaViT is its "efficiency dividend." By avoiding the information loss of cropping and the distortion of resizing, NaViT achieves a massive jump in performance-per-FLOP.

Experimental results using large-scale datasets like JFT-4B and WebLI demonstrate that NaViT-L/16 can process up to five times more images than a standard ViT within the same compute budget. Overall, NaViT matches the performance of the best-performing standard ViT models while using four times less compute.

Furthermore, NaViT introduces "Inference on a Slider." Because the model is trained on many resolutions, a single checkpoint can be used at any resolution at test time. This creates a smooth Pareto frontier, allowing users to choose between high-speed/low-accuracy or low-speed/high-accuracy without the need for retraining.

Robustness and Downstream Applications

NaViT’s ability to maintain native aspect ratios translates to tangible gains across various vision tasks:

  • Object Detection & Segmentation: On the LVIS and ADE20k datasets, NaViT-based models performed significantly better, proving that native resolution helps with fine-grained understanding and identifying rare classes.
  • Robustness: On ImageNet-A (a dataset of "hard" images), NaViT significantly outperforms standard ViTs because it avoids the "center-crop" bias that often misses the primary object in non-centered photos.
  • Fairness: Preserving original proportions improved the accuracy of fairness-related signal annotations (such as gender or ethnicity) compared to square-resized baselines, where distortion can lead to classification errors.

Conclusion

NaViT demonstrates that the square-crop constraint is an unnecessary vestige of the CNN era. By embracing the sequence-based nature of Transformers, the Patch n' Pack approach enables more efficient training, more flexible inference, and more robust computer vision models. Future research may extend these principles to adaptive computation—dynamically choosing token counts based on image complexity—and native video processing across varying frame rates.

Summary updated

BibTeX
@inproceedings{dehghani2023patch,
  author = {Mostafa Dehghani and Basil Mustafa and Josip Djolonga and Jonathan Heek and Matthias Minderer and Mathilde Caron and Andreas Peter Steiner and Joan Puigcerver and Robert Geirhos and Ibrahim Alabdulmohsin and Avital Oliver and Piotr Padlewski and Alexey A. Gritsenko and Mario Lucic and Neil Houlsby},
  title = {{Patch n’ Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=VpGFHmI7e5},
}
Figure