Attention Mechanisms · December 2025
DeepSeek Sparse Attention
intermediate
long-contextefficiency
Push attention compute below MLA's already-low cache floor by routing each query to a small top-K subset of historical keys, selected by a lightweight learned indexer.
§ 1 · Premise
MLA shrank the cache; compute is the next wall
MLA (DeepSeek-V2, 2024) compressed the KV cache 5–7× below MHA by representing K, V as a per-token latent of dimension . The cache is now small enough — DeepSeek-V3 at 128K context stores KB per layer per token of cache, vs MHA’s KB per token at width — that pure cache memory is no longer the binding constraint. The remaining wall is attention compute: at , each new query still does work against the full cache, which translates to multi-second per-token latency in single-batch decode even with FlashAttention-3-class kernels.
DSA’s framing (DeepSeek-V3.2 tech report, 2025, §2.2): empirically, most queries in long context do not need to attend to most history. A query at position is meaningfully driven by perhaps a few hundred to a few thousand prior positions — the recently-generated suffix, the system prompt, a handful of retrieval anchors. The full softmax over keys assigns near-zero mass to the rest. Token-level sparse attention restricts each query’s key budget to a learned subset with , saving the work that would have been wasted on near-zero softmax mass.
The hard part is choosing the -subset without paying to score it. DSA’s solution is to spend a small budget on a cheap indexer that approximates the relevance score, then spend the full attention budget only on the indexer’s top-K picks. The indexer is itself an attention-shaped operator, but at a small inner dimension — fast to compute, not expressive enough to replace the main attention, just expressive enough to predict which keys the main attention would have weighted most.
Lineage. DSA sits in the long-context-sparse-attention track that runs from Sparse Transformer (Child et al. 2019), Reformer (Kitaev et al. 2020, LSH-based), Routing Transformer (Roy et al. 2021, k-means clustering), through Native Sparse Attention (Yuan et al. 2025) and MoBA (Lu et al. 2025). All of these face the same chicken-and-egg problem: how to choose the sparse subset without paying for the dense scoring. DSA’s specific contribution is the distilled indexer trained against MLA’s own attention pattern — see §2.
The preview: DSA changes the operator’s per-token cost from to , with and at deployment.
§ 2 · Derivation
Two-stage attention with a distilled indexer
Setup. The layer holds MLA’s compressed cache for tokens , each . The current query token at position has hidden state . Standard MLA would compute attention over all cached entries. DSA replaces this with two stages.
Stage 1 — Lightning Indexer. A separate, narrower attention computes a relevance score per historical position. Let be the indexer’s query and key projections (the indexer hidden dim is much smaller than the main — the V3.2 report uses , vs for the latent). For each query at the indexer scores
This costs per query — linear in context, but with a constant smaller than full MLA’s per-key cost.
Stage 2 — Selected attention over top-K keys. Sort the indexer scores; gather the top historical positions:
Run the full MLA attention restricted to the selected positions: project the cached latents to per-head K, V on the fly (the MLA absorption trick — see MLA), compute the softmax-weighted output:
This stage costs — the same per-key cost as full MLA, but over the small selected set instead of all positions.
Total per-token cost.
For : Stage 1 contributes ops; Stage 2 contributes ops; total ops. Full MLA at the same context: ops — a reduction. The dominant term shifts from “attend to everything” to “score everything cheaply, attend to a few things expensively.”
Training the indexer. The indexer is useless if its top-K subset is poorly chosen. DSA trains the indexer with a distillation loss against the full-attention pattern from a frozen MLA teacher. Let be the teacher’s softmax-attention weights (taken from a checkpoint where attention is computed densely):
with temperature tuned so the indexer’s softmax is calibrated to the teacher’s. The full model trains end-to-end with this loss as an auxiliary term alongside the language-modeling loss. The teacher attention is recomputed periodically; once the student indexer matches the teacher’s top-K reliably (the V3.2 report cites a top-K recall of at ), the dense teacher computation can be retired and training proceeds with only the sparse student.
Why MLA, not GQA, as the base operator. Stage 2 has to materialize per-head K, V from the cached representation of the selected positions. With MLA’s narrow latent , the gather is cheap: M floats fetched per query per layer. With GQA’s per-group K, V cache at per token at typical group count , the same fetch would be M floats — twice the bandwidth, and without the late absorption trick that lets MLA reconstruct per-head K, V on chip. MLA’s compressed cache is what makes DSA’s gather bandwidth-efficient enough to be worth the indexer overhead.
Parameter overhead. The indexer adds per layer at params, K per layer. Across DeepSeek-V3’s 61 layers: M parameters, of total model size. The cost is negligible.
§ 3 · Reference implementation
Sketch
# Per decoder layer, per query token at position t.
# h_t: [d_model] — current hidden state
# cKV: [t, d_c] — MLA-compressed cache for tokens 1..t
# W_Q_I, W_K_I: [d_model, d_I], [d_c, d_I] — indexer projections (d_I << d_c)
# K (top-K budget): a constant — e.g. 2048.
def dsa_layer(h_t, cKV, W_Q_I, W_K_I, mla_module, K):
# Stage 1 — Lightning Indexer. O(t · d_I) per query.
q_I = h_t @ W_Q_I # [d_I]
k_I = cKV @ W_K_I # [t, d_I]
scores = (k_I @ q_I) / d_I**0.5 # [t] — indexer relevance per past pos
# Stage 2 — top-K gather, then full MLA attention over only K positions.
top_idx = scores.topk(K).indices # [K]
cKV_sel = cKV[top_idx] # [K, d_c]
out = mla_module(h_t, cKV_sel) # [d_model] — full per-head K, V on chip
return out
The cache itself (cKV) is unchanged from MLA — DSA piggybacks on the same compressed
latent. The new structure is the indexer projections W_Q_I, W_K_I and the top-K gather. The
load-bearing mechanical difference: MLA’s softmax runs over keys, DSA’s runs over keys, with the indexer deciding which .
§ 4 · Empirical evidence
What the V3.2 report measures
DeepSeek-V3.2 tech report (2025, arXiv 2512.02556, Table 5) compares V3 (dense MLA, same weights) against V3.2 (sparse MLA + DSA) at 128K context. End-to-end benchmarks: V3.2 within 0.3 points of V3 on MMLU, within 0.1 points on HumanEval, within 0.5 points on GSM8K. On the long-context “Ruler” benchmark at : V3.2 at 84.1% vs V3 at 86.3% — a 2.2-point regression, the largest gap in the eval suite and the cost of using a learned subset instead of all keys. On retrieval-heavy “needle in a haystack” probes specifically, the gap is larger ( points) — confirming the expected weakness of any top-K scheme on tasks where the relevant position is sparse and adversarial.
Latency / throughput (Table 7 of the V3.2 report). At , batch 1 decode: V3 at tokens/sec, V3.2 at tokens/sec — a speedup. The speedup compounds with batch size: batch 8 at shows V3.2 at V3’s throughput. The headline V3.2 efficiency claim — “production-grade 128K context at a fraction of V3’s serving cost” — comes from this lever.
The Native Sparse Attention paper (Yuan et al. 2025, arXiv 2502.11089, Table 4) is the only public side-by-side of a comparable sparse-attention scheme at frontier scale. NSA’s block-level selection at 14B parameters reports wall-clock speedup at 64K context with perplexity-equivalent loss — different mechanism (block-sparse vs token-top-K), different scale, but a consistent picture of “few × speedup at point quality cost for tasks that exercise full-context retrieval.” MoBA (Lu et al. 2025, arXiv 2502.13189, §4) reports similar tradeoffs with a mixture-of-block-attention scheme.
The indexer-distillation training cost is reported in V3.2 report §3.4: additional FLOPs over standard MLA training, recovered after B tokens of fine-tuning from a dense-MLA checkpoint. The full V3-to-V3.2 conversion ran on roughly 800B tokens, well below the trillions used for V3’s pre-training — DSA is a relatively cheap retrofit on an existing MLA checkpoint, which is part of why it shipped as an experimental V3 derivative rather than as a from-scratch V4.
The longer-context regime is where DSA’s behavior is least studied. The V3.2 report sticks to ; behavior at or beyond — and the question of whether a fixed budget is adequate as grows — is not addressed publicly. I do not know of an independent reproduction of DSA at this scale. The technique is novel enough (the V3.2 paper is labeled “experimental” by DeepSeek themselves) that long-term behavior on adversarial long-context tasks remains an open question.
A related open question: the indexer is itself a softmax-attention-shaped operator, so it inherits a quadratic-in- memory pattern for its own scores at prefill time. The V3.2 report notes (§3.6) that the indexer pass uses a FlashAttention-style tiled kernel to avoid materializing the full score matrix, but the per-token-prefill compute is still linear in context — so DSA’s savings are decode-side, not prefill-side. For workloads dominated by very long prefills (extended chain-of-thought, large retrieval contexts) this may matter; for chat-style streaming decode at long context it does not.
Adopted by
- DeepSeek V3.2-Exp · DeepSeek-AI — First DSA-enabled DeepSeek release; experimental V3 derivative that ships sparse attention as the long-context efficiency lever. [source]
Lineage
- Predecessors
- Multi-Head Latent AttentionMLA
Cite
BibTeX entry for the original paper
@article{arxiv2512_02556,
title = {DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models},
author = {DeepSeek-AI},
year = {2025},
eprint = {2512.02556},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2512.02556}
} Or cite the paper directly: arXiv:2512.02556.
Export
BibTeX
@article{arxiv_2512_02556,
title = {DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models},
author = {DeepSeek-AI},
year = {2025},
eprint = {2512.02556},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2512.02556}
} CSL JSON
{
"id": "arxiv_2512_02556",
"type": "article-journal",
"title": "DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models",
"author": [
{
"literal": "DeepSeek-AI"
}
],
"issued": {
"date-parts": [
[
2025
]
]
},
"URL": "https://arxiv.org/abs/2512.02556",
"number": "2512.02556",
"source": "arXiv"
} RIS
TY - JOUR
TI - DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models
AU - DeepSeek-AI
PY - 2025
JO - arXiv
AN - arXiv:2512.02556
UR - https://arxiv.org/abs/2512.02556
ER -