Sparse attention and the lightning indexer
DeepSeek Sparse Attention (DSA) uses a lightning indexer to choose which cached entries to read. Must every query inspect the whole history?
A new token has a question. Behind it, on a very long shelf, sit 100,000 cached entries.
To answer, it reads every one.
Two ways to cut the bill
What one token pays has two parts: how big each entry is, and how many entries it reads.
So far we have only attacked the first.
We stopped recomputing old entries with the KV cache. Then we made each entry smaller by sharing heads, compressing them and using fewer bits.
None of that changed how many entries the token reads. That is a different direction: not a cheaper entry, but fewer entries.
We tried reading fewer
The first attempt was a sliding window: read only the most recent entries.
But a window reads the recent entries whatever the question. The detail we need may be far back, and only a few full-attention layers, with a growing cache, can reach it.
What we want is the empty corner: reach far back, yet read only what matters for this question.
Does it really need them all?
To read fewer entries we need to know which ones matter. Look at a real attention row. Keep fewer entries and watch how much of the weight they hold.
A few entries carry almost all the weight. The rest are close to nothing. If the token could find those few, it would lose very little.
But how do we find them?
To choose the best entries we need their scores. Scoring every entry is the work we hoped to skip. We would pay the full price just to decide what to throw away.
Ask someone who skims
Does the score have to be exact? We only need a ranking good enough to spot the few that matter.
So give the token a helper: a second, much smaller attention. Its only job is to hand every entry one rough score. It is the attention we already know, made smaller.
This helper is the lightning indexer. Follow the two passes below.
The skimmer scores the whole shelf cheaply. The main attention then reads only the top few. The skipped entries stay on the shelf, because the next question may need them.
Teaching the skimmer
How does the indexer know what matters? It watches full attention.
Back to the weight chart, now choosing the entries with a cheap indexer. A rough ranking forces us to keep more entries to catch the same weight.
Does the bill shrink?
Give the main attention a budget of entries. The example keeps 2,048, however long the context grows.
The indexer still scans the whole shelf, but each look is small. Below the budget nothing is skipped, so the indexer is pure overhead.
It can be combined with the other optimisations, such as latent attention, for greater gains.
Reading is now cheaper. The other half of each layer has its own cost: holding many learned weights without using all of them for every token. Follow that into mixture of experts.
Sources and assumptions
DeepSeek introduced this as DeepSeek Sparse Attention in DeepSeek-V3.2, and GLM-5 uses it too.
- DeepSeek-V3.2 report, section 2, for DSA, the indexer and its training objective.
- DeepSeek-V3.2 config and GLM-5 config, for head counts and selection size.
- Sparse Transformer and Longformer, for earlier fixed-pattern designs.
The sizes in the indexer figure are DeepSeek-V3.2’s: a 512-number latent plus a 64-number rotary key for the main attention, and a 128-number key with 64 heads for the indexer. The selection widgets use one fixed row of 300 made-up scores (a strong pull to the first token, to the latest few, and to seven relevant tokens far back). The weights are a real softmax of those scores, and the cheap indexer adds a fixed random error to each score. Operation curves count the content dot products and weighted sums, with two operations per multiply/add pair. They omit the rotary score, projections, softmax, top-k, precision metadata, memory traffic and GPU communication; they are not latency benchmarks.
The dense-attention warm-up aligns the indexer with attention distributions aggregated across heads, using KL divergence. Sparse training continues alignment on selected positions alongside the model’s language-modelling loss.