Sparse attention is a method that computes only a predefined subset of the attention matrix. It was proposed in 2019 by Child et al. at OpenAI in the paper "Generating Long Sequences with Sparse Transformers", and the model built on it is called the Sparse Transformer.
Standard multi-head attention computes a weight for every pair of positions in the sequence, so its computation and memory grow with the square of the sequence length . When sequences reach tens of thousands of elements, as with an image flattened pixel by pixel (12,288 for a image with 3 color channels) or a raw audio waveform, this exceeds what can be computed.
Sparse attention limits the positions each position attends to to roughly of the whole sequence.
- Head 1: attends to nearby positions (the few preceding positions, or the same block).
- Head 2: attends to distant positions, skipping through them at a fixed interval.
The patterns are designed so that any position a single head cannot see is reachable by passing through the two heads in turn, which lets information flow even between positions far apart. It works like combining a local train (which stops at every nearby station) with an express (which stops only at certain stations): any station can be reached with few transfers.
The right side of the figure at the top of the article shows the positions that are computed. Multi-head attention computes every cell, whereas sparse attention computes only the colored cells.

