↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Layer 1 of 12 Formula demo on GPT-2's recorded Q, K, V · top-8 tokens per query · stand-in indexer · 12 heads × 64D · causal
Loading the DSA demo…

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.

Top-k tokens, shared by every head

Each query keeps the tokens with the highest index scores and attends over them with an ordinary softmax:

One set serves every head. DeepSeek-V3.2's attention is MLA (the MLA tab) run in its multi-query mode, where each token has one compressed key-value entry shared by all query heads, so one selection per query fetches one set of entries for all of them. DeepSeek keeps ; the demo keeps 8 of the prompt's 32 tokens. A query with 8 or fewer tokens so far keeps them all, so the first eight rows of the Sparse (top-8) view equal the GPT-2 dense view.

Selection is per token, not per block as in NSA (the NSA tab), so the kept set can be scattered anywhere in the context: a name near the start, a number in the middle, the last few words.

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

  1. DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models DeepSeek-AI · arXiv 2025 DeepSeek Sparse Attention: the lightning indexer, top-k token selection under MLA, and the warm-up and sparse training stages.
  2. DeepSeek-V3.2-Exp: Boosting Long-Context Efficiency with DeepSeek Sparse Attention DeepSeek-AI · 2025 The technical report that first described DSA; its equation 3, the indexer's training target, is the stand-in this page uses.
  3. Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention Jingyang Yuan et al. · ACL 2025 DeepSeek's earlier trainable sparse attention, selecting blocks rather than tokens (the NSA tab).
  4. DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model DeepSeek-AI · arXiv 2024 Multi-head latent attention, the attention DSA is built on (the MLA tab).
  5. Memory-efficient Transformers via Top-k Attention Ankit Gupta, Guy Dar, Shaya Goodman, David Ciprut, Jonathan Berant · arXiv 2021 Exact top-k attention per query, computed in chunks to save memory: token selection without a learned scorer.
  6. Language Models are Unsupervised Multitask Learners Alec Radford et al. · 2019 GPT-2, whose recorded queries, keys and values this demo selects from.

See also