Summary
Linear attention avoids materializing the softmax matrix by projecting the sequence axis or approximating the softmax kernel with a low-dimensional feature map. The per-layer cost drops from to or for .
Sparse attention (see sparse attention) keeps the softmax exact but on fewer pairs. Linformer instead uses a learned low-rank projection along the sequence dimension; Performer approximates the softmax kernel with random features and changes the order of multiplication.
In practice, modern decoder LLMs do not use linear attention. Quality drops are non-trivial at scale and FlashAttention has made dense attention competitive in wall-clock. Linear attention is most relevant in domains with extreme (genomics, time series of millions of steps) or in research on sub-quadratic alternatives.
Two main families
Project the sequence axis (Linformer, Wang et al., 2020)
Learn fixed projection matrices with . Replace with :
The softmax is now . Cost: , linear in . Caveat: is fixed at training time, so you cannot extrapolate to longer sequences without re-training.
Replace softmax with a kernel (Performer, Choromanski et al., 2020)
Softmax can be written as a kernel . Approximate this kernel with random features such that .
Write and . Because softmax attention is row-normalized, the approximation needs both a value summary and a normalizer. For query row ,
Compute the right-hand contractions first: is and is . Each transformed query reads these summaries, so no matrix is formed. Cost: , linear in , and the feature map works for arbitrary at inference (no fixed sequence-length projection).
Learning objective
Where does each method remove the n × n matrix?
When to use linear attention in 2026
- Sequence length where FlashAttention is still too slow or doesn’t fit memory.
- Encoder-only models on very long inputs.
- Real-time inference with strict latency budgets and tolerable quality loss.
For chat-style decoder LLMs, dense attention with FlashAttention + GQA + KV cache remains the production default.
Common pitfalls
- Comparing FLOPs without measuring wall-clock. Linear attention’s scaling only beats FlashAttention at large ; the crossover is implementation-dependent and often higher than naive analysis suggests.
- Forgetting the constants. Linformer’s and Performer’s may need to be hundreds for good quality, so the linear scaling has a large constant.
- Assuming all softmax-replacement schemes preserve the autoregressive mask trivially. Kernelized attention requires careful handling for causal masking (recursive cumulative sums).