Sparse Attention
Sparse attention is an attention mechanism that computes only part of the elements in the attention matrix rather than all pairwise interactions, lowering the computation of standard attention, which grows quadratically with sequence length. With large models now routinely carrying long-context demands, it is one of the fundamental retrofits that make attention affordable on long sequences.
Core Principles
Standard self-attention computes the relevance of every position in the sequence against every other position, so a sequence of length n requires n times n scores, and both time and memory grow with the square of the length. Once sequences reach tens or even hundreds of thousands of tokens, this step often becomes the bottleneck of the whole model. The basic idea of sparse attention is to accept the empirical fact that the attention matrix itself is highly sparse, that is, most positions contribute very little to the current position, and therefore to keep only a few "important" connections, rewriting the dense matrix as a sparse graph.
In implementation there are usually two routes. One is patterned sparsity, where connections are selected by human-designed rules, for example a sliding window that attends only to a few nearby words, global nodes that attend only to a few special positions, or block partitioning that keeps interactions only between certain blocks. The second is
From the standpoint of information pathways, dense attention is like building a direct expressway from every position, whereas sparse attention keeps only the necessary trunks and branches: nearby words travel on branches to preserve semantic coherence, a few global nodes act as hubs carrying cross-segment information, and a small number of random connections can be added when a wider receptive field is needed. Whether the pattern is well designed, and, if the inference side reuses the pattern structure set during training, the match among cache size, memory access patterns and kernel implementation must also be considered together, otherwise the theoretical gain is easily offset, or even turned negative, on real hardware.
Key Points
Complexity gain: dropping from quadratic to linear or near-linear is why it is widely used in long-text, code and multi-document retrieval scenarios.
Accuracy cost: the connections removed are information pathways that are given up, and a poorly designed pattern will lose points on tasks that need accurate long-distance alignment, such as multi-hop retrieval and strict copying.
Hardware friendliness: random sparsity saves compute on paper, but its memory access is irregular and it may not be fast on a GPU; block sparsity and window patterns are the ones that actually deliver speedups, and engineering implementations must take this into account.
Coordination with position encoding: a sliding window naturally carries a distance bias,
Binding with tiled computation: many implementations organize attention around fixed block sizes in exchange for a uniform kernel and stable memory usage, and the match between block size and head dimension must also be planned in advance.
Common Misconceptions
A common misunderstanding is that sparse attention is a form of "compression" that can replace full attention losslessly, when in fact it is a trade between accuracy and cost, and whether it suffices depends on how much the task relies on fine-grained long-distance dependencies. Another misunderstanding is to look only at theoretical complexity and ignore memory access and kernel implementation on real hardware, so that the claimed efficiency advantage disappears in practice.
Application Scenarios
Long-document understanding, book-level summarization, code repository analysis, long multi-turn dialogue, retrieval-augmented long-context concatenation, and production systems whose contexts often run to tens of thousands of words while cost must stay under control, where sparse attention is often used together with chunking, caching and position extrapolation.