Axial Attention in Multidimensional Transformers

Jonathan Ho, Nal Kalchbrenner, Dirk Weissenborn, Tim SalimansarXiv 2019

Abstract

We propose Axial Transformers, a self-attention-based autoregressive model for images and other data organized as high dimensional tensors. Existing autoregressive models either suffer from excessively large computational resource requirements for high dimensional data, or make compromises in terms of distribution expressiveness or ease of implementation in order to decrease resource requirements. Our architecture, by contrast, maintains both full expressiveness over joint distributions over data and ease of implementation with standard deep learning frameworks, while requiring reasonable memory and computation and achieving state-of-the-art results on standard generative modeling benchmarks. Our models are based on axial attention, a simple generalization of self-attention that naturally aligns with the multiple dimensions of the tensors in both the encoding and the decoding settings. Notably the proposed structure of the layers allows for the vast majority of the context to be computed in parallel during decoding without introducing any independence assumptions. This semi-parallel structure goes a long way to making decoding from even a very large Axial Transformer broadly applicable. We demonstrate state-of-the-art results for the Axial Transformer on the ImageNet-32 and ImageNet-64 image benchmarks as well as on the BAIR Robotic Pushing video benchmark. We open source the implementation of Axial Transformers.

Introduction: The Quadratic Bottleneck

Self-attention is the engine behind the Transformer revolution, but it has a glaring weakness: computational cost grows quadratically ($O(N^2)$) with sequence length. While manageable for text, a $1024 \times 1024$ image results in over a trillion connections, making standard Transformers impractical for high-resolution vision tasks.

In "Axial Attention in Multidimensional Transformers," researchers introduce a factorization method that bypasses this "quadratic explosion," allowing Transformers to handle high-dimensional data like images and videos efficiently. This approach addresses the "trilemma" of autoregressive modeling: maintaining expressiveness and efficiency while improving sampling speed.

Methods: Factorizing Attention

The core innovation is Axial Attention. Instead of flattening a 2D image into a 1D sequence, the model treats it as a multi-dimensional tensor and applies attention along a single axis at a time.

Axial attention patterns: full and masked versions for rows and columns.

By alternating between Row Attention and Column Attention, the model reduces complexity from $O(N^2)$ to $O(N\sqrt{N})$. For a $64 \times 64$ image, this is roughly 64 times more efficient. To maintain autoregressive properties (ensuring pixels only attend to "past" information), the authors utilize masked attention and a "Shift" operation to align the receptive field with standard raster-scan order. This ensures that any pixel can reach any other pixel in just two steps while respecting causality.

Key Insights: Semi-Parallel Sampling

A major practical advantage of this architecture is Semi-Parallel Sampling. Traditional autoregressive models generate images pixel-by-pixel, which is extremely slow for high-resolution data.

The semi-parallel sampling procedure in Axial Transformers.

Because the architecture is split into an Outer Decoder (capturing context from previous rows) and an Inner Decoder (handling the current row), the model can sample an entire row of pixels in parallel. This makes generation $\sqrt{N}$ times faster than traditional models without sacrificing the expressiveness of the joint distribution. Furthermore, because it uses standard matrix operations, it is hardware-agnostic and runs at peak performance on both GPUs and TPUs.

Results and Performance

The Axial Transformer achieved state-of-the-art (SOTA) results across several benchmarks at the time of publication:

  • ImageNet-32/64: Achieved 3.76 and 3.44 bits/dim respectively, outperforming or matching previous bests like the Image Transformer and Strided Sparse Transformer.
  • BAIR Robotic Pushing: In video modeling, it reached 1.29 bits/dim, significantly outperforming VideoFlow and Video Transformers.

Qualitatively, the generated samples show remarkable global coherence, producing recognizable objects rather than disjointed textures.

Conclusion

Axial Transformers provide a scalable, expressive, and easy-to-implement solution for high-dimensional generative modeling. By factorizing attention along axes and enabling semi-parallel sampling, they bridge the gap between the power of Transformers and the computational realities of image and video data. While fundamentally autoregressive, the efficiency gains make them broadly applicable for large-scale tensor data.

Summary updated

BibTeX
@misc{ho2019axial,
  author = {Jonathan Ho and Nal Kalchbrenner and Dirk Weissenborn and Tim Salimans},
  title = {{Axial Attention in Multidimensional Transformers}},
  year = {2019},
  eprint = {1912.12180},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1912.12180},
}
Figure