Abstract
The Transformer architecture has revolutionized sequence modeling but remains constrained by a quadratic computational bottleneck. As sequence length $n$ increases, the memory and time required for self-attention scale at $O(n^2)$, making high-resolution data like images and audio prohibitively expensive to process. This paper introduces Sparse Transformers, which employ factorized versions of the attention matrix to reduce complexity to $O(n\sqrt{n})$. By integrating these algorithmic improvements with specialized GPU kernels and gradient checkpointing, the model scales to sequences of up to 1 million steps, achieving state-of-the-art results across multiple modalities.
The Quadratic Bottleneck
In a standard Transformer, every element in a sequence attends to every other element. While this allows for global context, it creates a massive attention matrix. For a $256 \times 256$ image (65,536 pixels), a single layer would require an attention matrix with over 4 billion entries. To overcome this, Sparse Transformers seek to maintain global connectivity while significantly reducing the number of active connections.
Methodology: Factorized Self-Attention
The core innovation lies in decomposing the dense attention matrix into several sparse kernels. Instead of a single $O(n^2)$ operation, the model uses two steps of attention that, when combined, allow every position to eventually integrate information from all others.
Two primary patterns are introduced:
- Strided Attention: Designed for data with periodic structure (like images or music), one head attends to a local neighborhood while another attends to periodic intervals (e.g., every $\sqrt{n}$ steps).
- Fixed Attention: A more general pattern where specific "summary" tokens aggregate information from previous parts of the sequence and propagate it forward, suitable for data without a clear 2D structure.
Beyond algorithmic sparsity, the authors utilize a pre-activation residual block and specific weight initializations to stabilize training for networks as deep as 128 layers. To manage memory, gradient checkpointing is used to recompute the attention matrix during the backward pass, and custom block-sparse GPU kernels ensure that the theoretical $O(n\sqrt{n})$ complexity translates into actual wall-clock speedups.
Experimental Results
The Sparse Transformer was evaluated on image, text, and audio datasets, consistently outperforming previous benchmarks.
- Image Modeling: On CIFAR-10, the model achieved 2.80 bits per dim, surpassing the previous state-of-the-art (PixelSNAIL). On ImageNet-64, it reached 3.44 bits per dim.
- Text Modeling: Using the Enwik8 dataset, the model achieved 0.99 bits per byte, matching top-tier performance while handling a context window of 12,288 tokens—significantly longer than standard Transformers.
- Audio Modeling: The model successfully processed raw audio sequences of 1,048,576 steps, demonstrating unprecedented scaling for self-attention mechanisms.
Conclusion
Sparse Transformers demonstrate that the quadratic bottleneck of self-attention is not an insurmountable barrier. By combining sparse factorizations with rigorous engineering, it is possible to model extremely long-range dependencies in raw data. This work paves the way for deeper, more efficient models capable of processing high-resolution sensory input directly.
Summary updated