What DeepSeek sparse attention is
DeepSeek Sparse Attention (DSA) lets each query attend to a fixed number of earlier tokens instead of all of them, chosen per query by a small, fast scorer called the lightning indexer. DeepSeek introduced it in DeepSeek-V3.2-Exp and kept it in DeepSeek-V3.2, continuing training from DeepSeek-V3.1-Terminus with a 128K-token context. The main attention then costs instead of . The indexer still scores every pair of tokens, but with a few small heads, a ReLU instead of a softmax, and arithmetic that can run in FP8, so its share of the cost is small.
This tab is a formula demo on GPT-2 small, which has no indexer. It takes GPT-2's recorded queries, keys and values at layers 1, 3, 6, 9 and 12, scores the earlier tokens with a stand-in for the indexer, keeps the top 8 per query, and attends over those only. It shows which tokens the selection keeps and how much of GPT-2's own attention they carry. It does not show the saving: the stand-in needs the dense attention DSA avoids.
The lightning indexer
For query token and earlier token , the indexer computes an index score from its own small query heads , one indexer key per token shared by those heads, and a weight per head, all derived from the hidden states:
DeepSeek chose the ReLU for throughput. In DeepSeek-V3.2 the indexer has 64 heads of 128 dimensions, against up to 128K tokens of context. The page's Indexer panel draws for every query (rows) and earlier token (columns) and rings the tokens each query keeps; below it, the selected query's scores are sorted with a line at the cut.
Training the indexer
The indexer is trained to predict where the main attention goes. In a dense warm-up, with the rest of the model frozen, DeepSeek sums the main attention over its heads for each query, L1-normalises it along the sequence to get a distribution , and trains the indexer by the KL divergence to it:
Then the top-k selection is switched on and the whole model trains sparse; the indexer's loss is taken only over the selected tokens, and its input is detached so that it learns separately from the main model. The page's stand-in is exactly the warm-up target: GPT-2's attention summed over the layer's 12 heads and L1-normalised. A trained indexer approximates this target; the stand-in is what it would be if the approximation were perfect.
Reading the page
The caption gives two shares for the selected query: how much of the chosen head's dense attention the kept tokens hold, and the same averaged over the 12 heads. Because the stand-in sums all heads, a token that one head attends to strongly can still be dropped if the other heads ignore it: that is the price of one shared selection. Stepping through the layers shows how concentrated GPT-2's attention is at each depth; where a few tokens take most of the weight, keeping 8 of 32 loses little. Clicking a row opens its index scores, the kept tokens marked ✓, and the softmax over them.
Where it came from
Top-k attention is older: Gupta et al. (2021) kept each query's top-k exact scores to save memory, though every score still had to be computed. NSA (2025) made the selection cheap and trainable by scoring whole blocks through compressed keys. DSA keeps the idea of a trained selection but scores single tokens with a separate light indexer, and it sits on the multi-head latent attention DeepSeek introduced with DeepSeek-V2. The Sparse and Window tabs show fixed patterns that need no scorer at all.
Papers
- DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models DeepSeek Sparse Attention: the lightning indexer, top-k token selection under MLA, and the warm-up and sparse training stages.
- DeepSeek-V3.2-Exp: Boosting Long-Context Efficiency with DeepSeek Sparse Attention The technical report that first described DSA; its equation 3, the indexer's training target, is the stand-in this page uses.
- Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention DeepSeek's earlier trainable sparse attention, selecting blocks rather than tokens (the NSA tab).
- DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model Multi-head latent attention, the attention DSA is built on (the MLA tab).
- Memory-efficient Transformers via Top-k Attention Exact top-k attention per query, computed in chunks to save memory: token selection without a learned scorer.
- Language Models are Unsupervised Multitask Learners GPT-2, whose recorded queries, keys and values this demo selects from.