R198 · Infrastructure for agents at scale › Inference providers and serving reliability

Sparse attention that pays off: eight hardware co-design guidelines for the indexer

Read the original

Authors NVIDIA, NVIDIA AI (shared)

inference-costattentionlong-contextgpu

Sources: NVIDIA Technical Blog, Co-Designing Sparse Attention for Efficient Long-Context Inference, 2026-11-17, by Liu, Bhatia, Jain, Chandran, Darvish Rouhani and colleagues. Surfaced by NVIDIA AI's post.

The problem

Agent sessions, long documents and large codebases push context into the hundreds of thousands of tokens. Dense attention scores every query against every key, so at 128K tokens attention dominates prefill time. Sparse attention has each query attend only to the top k keys, typically a few thousand. Core attention then stops growing with context, but the cost does not disappear. A component called the indexer still scores all N keys to find the top k. In DeepSeek V3.2's sparse attention, the indexer plus top-k selection take 47% of the prefill layer time at 128K tokens.

Three stages

  1. Indexer: a cheap scoring pass over all keys, producing one logit per key.

  2. Top-k: keep the k highest-scoring keys or key blocks.

  3. Core attention: ordinary softmax attention over those k keys and values.

Stages 2 and 3 scale with k. Stage 1 scales with N, so it becomes the bottleneck to engineer.

Design space

The post compares how recent designs fill in the indexer: DeepSeek DSA, GLM 5.2 and 5.3 Flash, LongCat LSA-Flash, CSA, Qwen QSA, MiniMax MSA, NSA, MoBA and others. They vary in query heads, key heads, head dimension, post-processing (ReLU plus weighted sum, max-pool or softmax), compression ratio and selection granularity (single tokens or blocks of 4 to 128). It then sweeps each knob with a production FP8 kernel. The scope is sparsity trained into the model, not add-on methods applied after training.

The eight guidelines

  1. Size query-head grouping to the Tensor Core tile. Keep the grouped query rows within one tile (about 200 rows, or 256 with an FP16 epilogue) so the indexer stays compute-efficient.

  2. Run the indexer epilogue in FP16, and accumulate in FP16 too if the QK scaling keeps values in range.

  3. Use one key head, with a reduction across query heads, so the indexer writes one logit per key.

  4. Use a head dimension of 128 or 256. At 64 the Tensor Cores wait on the epilogue; most designs pick 128 to keep decode bytes down.

  5. Score fewer keys using compression, hierarchical indexing and sharing the index across layers. These reduce work but do not change arithmetic intensity, so use them alongside guidelines 1 to 4.

  6. Budget top-k as part of the indexer. Its cost follows the number of keys scored, not k. Fuse it with the indexer, and in decode reuse the previous step's result.

  7. Prefer block-level selection with large blocks. Blocks let core attention fetch keys in bulk and share them across queries.

  8. Use a large core-attention group size, so many query heads share each KV head.

Why it matters beyond kernel teams

Tradeoffs and failure modes

Review checklist for a long-context model or serving stack

Cited in field guides

Connections

See R198 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.