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

The ubiquitous and demonstrably suboptimal choice of resizing images to a fixed resolution before processing them with computer vision models has not yet been successfully challenged. However, models such as the Vision Transformer (ViT) offer flexible sequence-based modeling, and hence varying input sequence lengths. We take advantage of this with NaViT (Native Resolution ViT) which uses sequence packing during training to process inputs of arbitrary resolutions and aspect ratios. Alongside flexible model usage, we demonstrate improved training efficiency for large-scale supervised and contrastive image-text pretraining. NaViT can be efficiently transferred to standard tasks such as image and video classification, object detection, and semantic segmentation and leads to improved results on robustness and fairness benchmarks. At inference time, the input resolution flexibility can be used to smoothly navigate the test-time cost-performance trade-off. We believe that NaViT marks a departure from the standard, CNN-designed, input and modelling pipeline used by most computer vision models, and represents a promising direction for ViTs.

Paper

References (61)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer SsJZ6/10 · confidence 4/52023-06-28

Summary

This paper proposed an efficien training technique for Vision Transformers, called Patch n’ Pack. Specifically, it packs multiple images of various input resolutions into a single sequence as a batch exmaple. Furthermore, based on the modified architecture, the authors proposed NaViT. By combining Patch n’ Pack and NaViT, the authors conducted extensive experiments on JFT-4B datasets as well as a few downstream tasks. Overall, the method achieves great effciency for pretraining, and the model achieves better accuracy for differnet image resolutions at inference time.

Strengths

1. Adapting general-purpose Transformers into different input image resolutions is a fundamental research problem. Therefore, the technique that proposed in this paper is important to the community. And it works pretty well on both pretraining and downstream tasks. 2. The experiments are comprehensive. The efficiency gain during pretraining is impressive. 3. This paper is easy to follow. The overall presentation is of great quality.

Weaknesses

1. Packing examples into a single sequence during training is not new in the literature. However, it's technically new for ViT training. 2. Despite the performance, pretraining on JFT-4B is very expensive, making it difficult for the subsequent works to follow up and compare with. It would be better for the authors to include experiments of pretraining on ImageNet-1K. 3. It is not clear how the memory cost would be under the proposed Patch n’ Pack.

Questions

It would be better for authors to add additional experiments for pretraining on ImageNet-1K and compare with FlexViT. Please also include memory consumption report during pretraining.

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

3 good

Presentation

3 good

Contribution

3 good

Limitations

Yes

Reviewer z6Gn6/10 · confidence 4/52023-07-03

Summary

This paper focuses on adapting the computer vision model to flexible usage. The authors stand from the ViT architecture and exploit its flexible sequence-based modeling to enable arbitrary resolutions and aspect ratios. The proposed NaViT could benefit the downstream tasks of object detection, image, and video classification. Evaluations on typical ViT tasks show the performance on different downstream tasks.

Strengths

Exploiting the flexible sequence-based modeling of ViT models is interesting. This paper uses a simple but effective idea to make the image preprocessing match arbitrary resolutions and aspect ratios. The idea is motivated by convincing preliminary experiments. The performance evaluation also presents useful insights into utilizing NaViT’s property.

Weaknesses

The architecture design of NaViT and its essential components to extract visual features could be introduced to help the readers better understand the techniques. Although the authors claim the proposed NaViT can be applied to different downstream tasks, the experiments are mainly based on high-level tasks of classification and detection. I am interested in NaViT’s generalization to more low-level tasks, such as super-resolution with arbitrary scales and pixel-level segmentation. The additional overhead of introducing NaViT as the image preprocessing could be reported.

Questions

Please see the suggestions in the weakness part.

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

3 good

Presentation

3 good

Contribution

2 fair

Limitations

None.

Reviewer CXkP5/10 · confidence 4/52023-07-03

Summary

This passage discusses the common practice of resizing images to a fixed resolution before processing them with computer vision models, which is not optimal. The author introduces a new model called NaViT (Native Resolution ViT) that takes advantage of flexible sequence-based modeling and allows for processing inputs of arbitrary resolutions and aspect ratios with adaptive positional embeddings. NaViT uses sequence packing and token drop which improves training efficiency for large-scale supervised and contrastive image-text pretraining. The author believes that NaViT represents a promising direction for ViTs and offers a departure from the standard input and modeling pipeline used by most computer vision models, which rely on CNN-designed approaches.

Strengths

- The authors present a simple method that significantly enhances the training efficiency of the vanilla ViT model, as evidenced by the results displayed in Figure 1. The observed improvements are noteworthy and suggest potential for practical application. - The authors also make a compelling argument, supported by Figure 3, that the conventional practice of resizing or padding images to a fixed size, which has been historically associated with convolutional neural networks, is flawed. Specifically, the authors demonstrate that both resizing and padding can lead to suboptimal performance and inefficiency, respectively. - While the overall algorithms are relatively straightforward, they are clearly depicted in Figure 2.

Weaknesses

- The authors have presented a comprehensive set of experiments to demonstrate their results. However, I would like to raise a concern regarding the absence of comparison with the related works discussed in Section 4. This omission makes it challenging to evaluate the actual improvements over the baseline methods in a fair manner. - To address this issue, I strongly encourage the authors to provide a detailed discussion on the primary contributions of their proposed methods. It appears that the example packing technique has already been thoroughly discussed in Efficient Sequence Packing [1], and one could simply replace the word tokens with image patches to form the proposed method. Moreover, apart from the example packing, the main difference between "Patch n'Pack" and Pix2struct [2] seems to rely solely on the construction of positional embedding. Additionally, it is worth noting that the most recent work [3] also aims at mix-resolution tokenization. While the proposed method may have some differences from existing works, the current manuscript fails to clearly establish the novelty of this paper. ### Reference: - [1] Efficient sequence packing without cross-contamination: Accelerating large language models without impacting performance. Submitted to ICLR2022 - [2] Pix2struct: Screenshot parsing as pretraining for visual language understanding. Submitted to ICLR2023 - [3] Vision Transformers with Mixed-Resolution Tokenization. CVPR2023w

Questions

- The authors have made an attempt to demonstrate the relative improvements over competitive counterparts in Figure 10. However, the differences between factorized position embeddings and NeRF appear to be marginal, with a range of less than $\pm 0.2\\%$. - I would appreciate further clarification on the statement "This enables variable aspect ratios, with resolutions of up to $R=P\cdot \text{maxLen}$". Given that Pix2struct only introduces positional embeddings with the size of $[\text{maxLen},\text{maxLen}]$, and "indexed with (x,y) coordinates of each patch", I am curious how the resolution can be enlarged to $P\cdot \text{maxLen}$ without patch embedding in the size of $P\times P$. - The authors have discussed several position encoding methods, but I remain unconvinced that any specific formulation significantly contributes to the performance improvements over the others. - Could the authors provide additional details on the settings of "the total number of pixels can be resampled while preserving the aspect ratio"? While I agree that "for NaViT a resolution of “128” has the same area of a square 128 x 128 image, but could be 64 x 256, or 170 x 96", I am curious as to why the "effective resolution" of $64 \times 256$ is larger than $128 \times 128$. - The authors have thoroughly discussed the benefits of the variable resolution, sampling strategies, and token dropping. However, none of these concepts are first proposed in this work. While the details may differ from existing works, such as the resolution sampling strategy, the fundamental idea remains the same. Therefore, the novelty of this paper appears to be limited. - The relationship between "Pack n'Patch" and "Self-attention cost" appears to be weak, as the packing of multiple patches from different images into a single sequence does not increase the cost compared to the original single sequence scheme. We kindly request the authors to provide further clarification on why the attention overhead should vary with the number of patches packed.

Rating

5: Borderline accept: Technically solid paper where reasons to accept outweigh reasons to reject, e.g., limited evaluation. Please use sparingly.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

2 fair

Presentation

3 good

Contribution

2 fair

Limitations

I found no potential negative societal impact of their work.

Reviewer WGZP6/10 · confidence 3/52023-07-04

Summary

The authors propose to use example packing to train ViTs, where training examples of various lengths are packed into a single sequence. This requires a few straightforward architecture changes, including modified attention masking, pooling, and positional embeddings. This scheme allows for some interesting ideas, such as variable image resolutions during training, variable token drop rates, and adaptive inference time computation. Extensive experiments in the paper show that NaViT results in more efficient training and finetuning (in terms of TPU hours) and a better compute-performance tradeoff at inference time. Further analysis shows that mixed resolution training is beneficial to model performance, that the time-varying token drop ratio allowed by the model can improve results when the correct schedule is used, and that the proposed factorized positional embeddings can offer very good generalization to aspect ratios and resolutions unseen during training. Finally, additional experiments show promising behavior with respect to calibration, fairness, object detection, and video classification.

Strengths

Overall, this is a very comprehensive paper. The number of experiments and the aspects of the proposed models performance evaluated is impressive. The authors touch on a large number of relevant properties of the model, including calibration stability, positional embedding ablations, and out of distribution performance. Additionally, results are quite positive, showing promising results on image classification, object detection, video classification, and training efficiency. Finally, the appendix is thorough, and gives enough details to accurately reproduce all experiments from what I can see.

Weaknesses

According to appendix section B.1, classification experiments seem to be "compute-matched." Are there any experiments analyzing the asymptotic performance between ViT and NaViT, or can the authors discuss this? The experiments in the paper seem inconclusive on this point. The question of compute matching also applies to downstream experiments. For example, in the fairness analysis, are compute matched ViT and NaViT being compared? If so then the conclusion from Appendix H that "native image resolution improves the performance of fairness signal annotation" may not hold. NaViT seems to benefit from training at the original aspect ratio, and at variable resolutions. However, could either of these benefits be achieved through scale and crop data augmentation? What data augmentation is used for ViT? Additionally, I was under the impression that image stretching or shearing could be useful as a data augmentation. Could the authors please discuss this? Where are the contrastive results? I might have overlooked something, but I can't find zero-shot imagenet or COCO image-text retrieval results as discussed on line 154. Minor typos: - Figure 2 typo: "image 2" is repeated twice in the "data processing" part - Figure 9 is before Figure 7 and 8 - It seems that a lot of (if not all) appendix section references are incorrect. Examples of these typos occur in line 152, line 158, line 339, and line 120.

Questions

See weaknesses section, thank you.

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

3: You are fairly confident in your assessment. It is possible that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

4 excellent

Presentation

3 good

Contribution

3 good

Limitations

I think the "limitations" section from the appendix could be more forthcoming and candid. It mostly just says "NaViT" is a great idea, but we didn't get to apply it to all the tasks we wanted to. It could benefit from a more honest discussion of the method's limitations, such as compute overhead from packing or additional architectural changes needed to support example packing.

Reviewer WGZP2023-08-19

Thank you for answering my questions and updating the manuscript where appropriate. The response has cleared up some of my confusion and has resolved all of my concerns satisfactorily. In addition, I have read the other reviews and corresponding rebuttals, and I am of the opinion that the author has given reasonable responses to points brought up by the other reviewers. In particular, two reviewers are concerned about the novelty of the work. On the contrary, I agree with the authors that while sequence packing, variable aspect ratio, and token dropping have been proposed before, their combined use in this work is novel (i.e. the fact that sequence packing can quite naturally enable variable resolution or aspect ratio training and dynamic token dropping). Overall, I still think the paper is a good submission and I want to keep my rating as is. I would be happy to discuss additional questions or points that the authors or other reviewers may have.

Reviewer CXkP2023-08-20

Re: Rebuttal by Authors

Thank you for the detailed feedback. After carefully considering the comments from the other reviewers, I still have some reservations about the novelty of the proposed technique. While "explore variable resolution to speed up training" may be new in the literature on vision transformers, I am not fully convinced that combining sequence packing, variable aspect ratio, and token dropping should be considered a significant contribution to the field. However, I must acknowledge that the authors have addressed all of the concerns raised in the rebuttal, and there are no apparent flaws in the proposed method. Therefore, I raise my previous rating to borderline. I would like to note that the authors claim that "Introducing variable resolution as a way to speed up training" is one of the major contributions of this paper, and that this technique has been discussed on CNN-backbone as a group of Resolution-level Dynamic Networks. Finally, I would encourage the authors to provide further reflection on the response to the last question in the final version of the paper. Without this clarification, it may be difficult for readers to fully understand the trade-offs involved in using the proposed method, and the paper may not be as impactful as it could be.

Reviewer z6Gn2023-08-20

Post-rebuttal comments

Thanks for answering the questions. My concerns have been addressed. I think it is a good paper and I have increased my rating.

Program Chairsdecision2023-09-21

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC