LearnQuestion bank

Compare Native Sparse Attention, DeepSeek Sparse Attention and DeepSeek-V4’s compressed attention. What does each select or compress, what does it cost, how is it trained, and why do these methods train sparsity in rather than applying it to a finished dense model?

ResearchTechnicalHard

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • NSA: three sigmoid-gated branches (compressed coarse blocks, top-n selected fine blocks, sliding window), block granularity matched to GPU memory access, pretrained sparse; up to 9.0x forward and 6.0x backward speed-ups at 64k (the 11.6x decoding figure is an expected value).
  • DSA (V3.2): a light FP8-capable indexer scores earlier tokens and each query attends to the top 2,048, so core attention is O(L*k) while the indexer stays O(L^2); added by continued training, with a KL-trained indexer warm-up before sparse training.
  • DeepSeek-V4: Compressed Sparse Attention (4x compression, top-k compressed entries, 512 Flash / 1,024 Pro, plus a sliding window) interleaved with Heavily Compressed Attention (128x, dense); V4-Pro needs about 27% of V3.2’s single-token FLOPs and 10% of its KV cache at 1M tokens.
  • V4 trains sparsity in during pre-training: dense warm-up (first 1T tokens for Flash), indexer warm-up, then sparse attention for most of the run.
  • Post-hoc sparsity fails because dense attention never learned to work with missing keys (pruning can break retrieval heads), and token-level sparsity without hardware-aligned blocks rarely gives wall-clock speed-ups.
  • Evaluation must cover long-range recall at the target length, since compression and selection can drop exactly the token needed.

In full

The three methods all reduce attention cost, but they select or compress at different granularities and are trained in different ways. NSA uses three branches combined by learned sigmoid gates—compressed coarse-grained blocks, the top-n fine-grained blocks chosen by importance score, and a sliding window over recent tokens—with block granularity matched to GPU memory access. It is pretrained sparse from the start, and the paper reports up to 9.0x forward and 6.0x backward speed-ups over a FlashAttention-2 kernel at 64k tokens (its 11.6x decoding figure is an expected speed-up derived from memory access, not a measured wall-clock number). DSA, introduced with DeepSeek-V3.2, adds a light ‘lightning indexer’ that can run in FP8 and scores earlier tokens; each query then attends to the top 2,048, so core attention is O(L*k) while the cheap indexer remains O(L^2). It is added to an existing dense model by continued training: a short warm-up trains only the indexer with a KL loss towards the dense attention distribution, then a sparse stage updates all parameters. DeepSeek-V4 (April 2026) interleaves Compressed Sparse Attention—4x compression along the sequence, an indexer that picks the top-k compressed entries (512 for V4-Flash, 1,024 for V4-Pro) and a sliding window of recent uncompressed tokens—with Heavily Compressed Attention, which compresses 128x and then attends densely. At 1M tokens V4-Pro needs about 27% of V3.2’s single-token inference FLOPs and 10% of its KV cache. V4 also trains the sparsity in during pre-training: it starts with dense attention (the first 1T tokens for V4-Flash), warms up the indexer, then trains with sparse attention for most of the run. The common reason to train sparsity in rather than bolt it onto a finished dense model is that a dense model’s attention was never trained to work with missing keys—post-hoc pruning pushes it off its optimisation trajectory and can break structures such as retrieval heads—and token-level sparsity without hardware-aligned blocks rarely gives real wall-clock speed-ups. Evaluation must therefore include long-range recall at the target length, because compression and selection can drop exactly the token needed.

Corrected by an independent AI reviewer.

What a strong answer covers

  • NSA: three gated branches (compressed coarse blocks, top-n selected fine-grained blocks, a sliding window), block granularity matched to GPU memory access, trained sparse from scratch; up to 9× forward and 6× backward speedups at 64k.
  • DSA: a light FP8 indexer scores earlier tokens and each query attends to the top 2,048, so core attention is O(L·k) while the cheap indexer remains O(L²); added by continued training, warming up the indexer with a KL loss to the dense attention.
  • DeepSeek-V4: Compressed Sparse Attention (4× sequence compression, top-k blocks, sliding window) interleaved with Heavily Compressed Attention (128×, dense), giving about 10% of V3.2’s KV cache at 1M tokens.
  • Post-hoc sparsity fails because a dense model’s attention was never trained to work with missing keys, and token-level sparsity without hardware-aligned blocks rarely gives real wall-clock speedups.
  • Evaluation must cover long-range recall at the target length, since compression and selection can drop exactly the token needed.

Common mistakes

  • Calling sparse attention free: indexers, compression and selection add compute and can miss needed tokens.

Follow-ups

  • How would you debug a sparse-attention model that fails one specific multi-hop retrieval task?