REOrdering Patches Improves Vision Models

Declan Kutscher, David M. Chan, Yutong Bai, Trevor Darrell, Ritwik Gupta

TL;DR

While standard Vision Transformers are indifferent to the order of image patches, modern long-sequence models (like Mamba or Longformer) break this permutation invariance to achieve efficiency. This paper introduces REOrder, a reinforcement learning framework that discovers optimal, model-specific patch orderings, unlocking hidden performance gains of up to 13.35% without altering the underlying model architecture.

What Problem Does This Paper Address?

When processing images with sequence models, the standard practice is to chop the 2D image into a grid of patches and flatten them into a 1D sequence using a simple row-by-row (row-major) raster scan. For vanilla Vision Transformers (ViTs), this arbitrary choice doesn't matter because full self-attention is permutation-equivariant—the model processes all tokens simultaneously regardless of order.

However, full self-attention scales quadratically ($O(n^2)$), making it too expensive for long sequences or high-resolution images. To fix this, modern architectures introduce approximations: sliding windows (Longformer), segment recurrence (Transformer-XL), or structured state-space updates (Mamba).

The catch? These efficiency tricks break permutation equivariance. Suddenly, the order in which the model encounters patches matters immensely, yet the field has blindly stuck with the default row-major scan. This paper investigates how patch ordering affects these modern backbones and how to find the optimal sequence for a given model and dataset.

Figure 1: Visualizations of alternate patch sequence orderings. Six different patch orders—row-major, column-major, Hilbert curve, spiral, diagonal, and snake—are shown as trajectories over a 14 × 14 grid of patches. Each trajectory begins at the red dot and progresses to the black dot, illustrating the 1-D ordering imposed on the 2-D patch grid.

Methods

The authors propose REOrder, a two-stage framework designed to navigate the massive combinatorial space of patch permutations ($196!$ options for a standard $14 \times 14$ grid).

  1. Information-Theoretic Initialization: To avoid starting from scratch, they evaluate the compressibility of different fixed patch sequences (e.g., Hilbert curves, spirals) using a VQ-VAE tokenizer combined with LZMA compression. Sequences with lower compressibility indicate less local redundancy, serving as a weak prior to warm-start the search.
  2. Reinforcement Learning Policy: REOrder parameterizes the permutation distribution using a Plackett-Luce model, assigning a learnable logit to each patch location. To make training efficient and parallelizable across batches, they utilize the Gumbel-top-$k$ trick to sample permutations.
  3. Curriculum Training: The policy is optimized via REINFORCE, using the negative downstream classification loss as the reward signal. Training follows a three-stage curriculum: start with standard row-major ordering, activate the RL policy with a fluctuating temperature schedule to encourage exploration, and finally freeze the policy to its maximum-likelihood permutation so the backbone can stabilize.
The REOrder policy optimization algorithm using a Plackett-Luce distribution.

Datasets

The authors evaluated their approach on two distinct image classification benchmarks:

  • ImageNet-1K: The standard benchmark for natural images, characterized by high diversity and a strong center bias.
  • Functional Map of the World (FMoW): A satellite imagery dataset. Satellite images are highly structured and homogeneous compared to natural scenes, presenting different spatial biases.

Key Insights and Ideas

  • No Universal Best Static Order: Swapping row-major for column-major or diagonal scans yields immediate performance shifts, but no single static ordering wins everywhere. For instance, column-major ordering boosts Transformer-XL on ImageNet but harms Longformer on FMoW.
  • Mamba is Highly Sensitive: Mamba models suffer severe drops when forced into non-grid-aligned trajectories (like spirals or Hilbert curves) because their fixed internal causal scan directions conflict with the patch sequence.
  • Model-Specific Reordering Strategies: Interestingly, REOrder doesn't converge to a single "ideal" spatial layout. Instead, it adapts to the model's specific inductive biases:
  • Mamba learns to front-load central, salient patches. This allows its recurrent state-space mechanism to build a strong initial hidden state early in the sequence.
  • Transformer-XL and Longformer learn to back-loading central patches, allowing these tokens to leverage accumulated context from the rest of the image.
Figure 2: Patch order affects the performance of long-sequence models. This figure compares the top-1 accuracy of Vision Transformer (ViT), Longformer, Mamba, and Transformer-XL (T-XL) on ImageNet-1K and Functional Map of the World when using alternate patch orderings, relative to their standard row-major performance. As expected, ViT remains equivariant to patch sequence permutations. In contrast, long-sequence models exhibit substantial performance variability depending on the patch ordering. No single ordering consistently outperforms others across models or datasets, necessitating dynamic patch ordering strategies.

Key Results

  • Mamba Boosts: On the FMoW satellite dataset, applying REOrder to a Mamba backbone with a diagonal initialization yielded a massive 13.35% top-1 accuracy improvement over the standard row-major baseline. On ImageNet-1K, REOrder improved Mamba's accuracy by 3.01% using a Hilbert curve initialization.
  • Transformer-XL Gains: Transformer-XL saw a 1.92% static improvement simply by switching to column-major ordering on ImageNet, with REOrder providing further robust gains under extended training.
  • ViT Sanity Check: As predicted by theory, the vanilla Vision Transformer showed virtually zero performance variance across all permutations, confirming its inherent permutation equivariance.

Limitations and Future Work

  • Global vs. Dynamic Policies: Currently, REOrder learns a single global patch ordering shared across the entire dataset. It cannot adapt dynamically to the unique semantic layout of an individual image (e.g., adjusting the scan order if the subject is in the top-left corner vs. the center).
  • Compute Constraints: Due to the high cost of RL training, the policy exploration phase was brief (active for only 30 epochs, with peak exploration lasting just one epoch). The authors note that performance gains were likely left "on the table" due to limited hyperparameter tuning.
  • Co-optimizing Internal Scans: For models like Mamba/ARM that utilize multi-directional internal scans, future work could explore jointly optimizing the internal scan directions alongside the input patch permutation.

Summary updated

BibTeX
@inproceedings{kutscher2025reordering,
  author = {Declan Kutscher and David M. Chan and Yutong Bai and Trevor Darrell and Ritwik Gupta},
  title = {{REOrdering Patches Improves Vision Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=g56WiaXKGF},
}
Figure