Curated summary
Generative modeling with sparse transformers
Deep LearningTransformerGenerative ModelsImage GenerationPytorchGpu KernelsAudio GenerationSparse Attention
Generative Modeling with Sparse Transformers
OpenAI's Sparse Transformer is a deep neural network that sets new benchmarks for predicting the next element in a sequence, whether text, images, or audio. By replacing standard self-attention with a sparse variant that scales as O(N√N) instead of O(N²), the model handles sequences roughly 30 times longer than previously feasible, reaching tens of thousands of elements across hundreds of layers. The authors position this as a step toward modeling the long-range, subtle dependencies that complex data like images and audio demand.
Why Dense Attention Becomes a Bottleneck
- In Transformers, every output element attends to every input element, requiring an N×N attention matrix for each layer and attention head.
- For high-dimensional data, this memory cost grows quickly. A deep 64-layer, 4-head Transformer needs about 9.6 GB to store attention matrices for a 32×32 CIFAR-10 image, and about 154 GB for a 64×64 ImageNet image. Typical deep learning GPUs have 12–32 GB.
- Recomputing attention matrices from checkpoints during backpropagation keeps the dominant memory cost independent of depth, which allows training networks up to 128 layers deep. These deeper models outperformed shallower ones on benchmarks like CIFAR-10.
- Training at this depth required changes to the order of operations within the Transformer block and a modified initialization scheme.
Sparse Attention Patterns
- Each output position attends only to a subset of input positions, ideally about √N elements instead of N, reducing complexity to O(N√N).
- Visualizing learned attention in deep image models showed many heads with structured, sparse patterns, though some layers attended across the whole image.
- To preserve global reach, the authors use a two-dimensional factorization in which any position can reach any other in two sparse steps:
- Strided attention has each position attend to its row and column, suited to images.
- Fixed attention attends to a fixed set of column positions and all later elements, suited to data without a 2D structure, such as text.
Results
- CIFAR-10 (bits per dim): The 59M-parameter Sparse Transformer reached 2.80, beating PixelCNN++ (2.92), Image Transformer (2.90), and PixelSNAIL (2.85).
- Enwik8 (bits per byte): The 95M-parameter model reached 0.99, matching the 277M-parameter Transformer-XL and outperforming the 88M version (1.03).
- ImageNet 64×64 (bits per dim): The 152M-parameter model reached 3.44, improving on SPN 150M (3.52) and Gated PixelCNN (3.57).
- Sparse attention also achieved lower loss than full attention while running significantly faster, which the authors suggest may reflect a useful inductive bias or an optimization issue with dense attention.
Generation Capabilities
- Images: Models trained on 64×64 ImageNet produce completions that show coherent global structure. Unconditional samples at temperature 1.0 reflect the full learned distribution, so some look unusual.
- Raw audio: By changing the position embeddings, the same architecture generates raw waveforms. The model produced 65,000-sample sequences, about 5 seconds of classical music.
- Open-source kernels: The team released block-sparse GPU kernels and example sparse attention functions, since implementing sparse attention by slicing query and key matrices is otherwise cumbersome.
Limitations and Future Directions
- The attention patterns introduced are preliminary. The authors see learned sparsity patterns as a promising direction for future architectures.
- Autoregressive generation remains impractical for very high-resolution images or video. The optimized attention primitives may still be useful when combined with multi-scale approaches.
Related reading
Continue with another curated summary.