Sparse Attention at 22x Speedup: Key Techniques for 10-Million-Token Contexts
As context windows scale toward 10 million tokens, the bottleneck in sparse attention shifts from compute to indexing. This article explains Latent Sparse Attention, which moves retrieval into a low-dimensional latent space and uses a two-stage coarse-filter and refine design to achieve reported speedups of roughly 22x and 72x on single-layer prefill. It covers the architecture, why the gains are so large, engineering questions around index construction, memory budget, decode consistency, and kernel support, plus accuracy safeguards and evaluation advice.
1. Ultra-Long Context Is Rewriting the Cost Structure
Over the past two years, long-context capability has shifted from an optional feature to a default specification. Million-token context windows are now standard in many general-purpose services, and a model can ingest an entire codebase, hours of meeting transcripts, or hundreds of pages of contracts in a single request. Attention has accordingly moved from “can we fit it in?” to “is it worth fitting in?”
The real turning point appears as contexts push toward 10 million tokens. At that scale, an otherwise unremarkable cost spirals out of control: in a global attention layer during prefill, most of the time is not spent on the matrix multiplications of attention itself, but on the indexing step that decides which tokens to look at. Put differently, compute is not consumed by the model “thinking”; it is consumed by “finding things.”
This is worth dwelling on, because it defies intuition. We tend to assume long-context cost comes from the quadratic complexity of attention, so we keep compressing, approximating, and chunking. But once indexing dominates, further optimizing the compute is effort spent in the wrong place.
2. The Bottleneck Moves: From “Slow Compute” to “Slow Lookup”
The basic premise of sparse attention is that each query does not need to traverse all historical tokens; it only needs to select a few of the most relevant positions to participate in the computation. This premise has been repeatedly validated at the million-token scale, with controllable accuracy loss and significant throughput gains.
The problem is that “selection” itself requires a scoring pass. The naive approach is to compute a lightweight similarity between the query and every historical key, then take the Top-K. That scoring is still a full scan, and its cost rises quickly with context length. The result is an awkward situation: sparsification saves the expensive attention computation but introduces a selection cost that grows with length in the same way. Combined, total overhead still grows superlinearly.
Think of it as library retrieval. If the shelves expand from ten thousand books to ten million, making “reading” faster does nothing for the experience if “finding the book” still means flipping through them one by one. Real acceleration has to happen at the retrieval layer, not the reading layer.
3. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Space
A recent paper from a startup research team working with a university lab proposes Latent Sparse Attention. The core idea is not a smarter scoring function, but changing the space in which scoring happens.
The design breaks down into three parts:
- Compressed representation: Project the lengthy key/value sequence into a low-dimensional latent space to form compact “summary vectors.” Each summary vector carries the aggregated semantics of a contiguous span of tokens rather than the raw representation of a single token.
- Latent-space retrieval: The query is projected into the same latent space and dotted with the summary vectors for coarse filtering. Because the dimensionality is much lower and the number of candidates is reduced by an order of magnitude, this step degrades from a linear scan to a small dense operation.
- Two-stage refinement: After coarse filtering yields a small set of candidate blocks, the method returns to the original resolution, performs exact Top-K selection within those blocks, and runs attention. Coarse filtering handles recall; refinement handles precision. The responsibilities are separated.
Illustrative pseudocode (logic only, not a specific implementation):
# 1. Precompute stage: build the latent-space indexlatent = project_to_latent(keys) # [L, d_latent], d_latent << d_headblocks = pool(latent, block_size) # [L/B, d_latent] block-level summaries# 2. Query stage: two-stage retrievalq_latent = project_to_latent(query)coarse = blocks @ q_latent # block-level coarse scoringcand = topk(coarse, k_blocks) # a few candidate blocks# 3. Intra-block refinement + attentionidx = topk_within_blocks(keys, query, cand, k=TopK)out = attention(query, keys[idx], values[idx])
The key benefit is that the expensive full comparison is replaced by a small dense operation in low dimensions, which can fully utilize tensor cores and contiguous memory access. Hardware utilization is far higher than with scattered gathers and irregular memory access.
4. Why the Speedup Reaches Dozens of Times
Public results show that at the 10-million-token scale, on single-layer prefill, this approach achieves roughly 22x and 72x speedups over sparse-attention baselines, with accuracy close to the original model across a range of tasks. Such a large gap in the multipliers usually comes from three factors:
- Inefficient baseline indexing. When indexing is the bottleneck, its implementation is often memory-access-bound and fragmented across operators, with very low hardware utilization, leaving naturally large room for optimization.
- A double reduction in dimension and candidates. The retrieval space is compressed on both axes, so the complexity reduction is multiplicative rather than additive.
- Prefill’s parallel friendliness. Prefill can build the index in one pass and batch the retrieval, whereas decode processes a single query per step, giving a completely different benefit structure.
It is worth stressing that these multipliers are single-layer measurements under specific conditions and cannot be equated directly with end-to-end throughput gains. Engineering evaluation should rely on measured data for the full model and full request.
5. Engineering Deployment: Four Questions You Must Answer
- When to build the index. Latent summaries can be built once during prefill and cached for reuse across conversation turns. If you use a sliding-window or chunked-cache strategy, you need to maintain invalidation and incremental updates of the summaries accordingly.
- Memory and bandwidth budget. The summary vectors themselves occupy memory, but still represent an order-of-magnitude reduction versus the raw KV cache. Budget separately for “raw KV + latent index + intra-block window” rather than looking only at peak usage.
- Consistency with the decode stage. The sparse selection in prefill must stay semantically consistent with the incremental selection in decode, or the model will “forget” the later parts of long text. A common practice is to keep lossless full attention over the most recent window.
- Operator and kernel support. Low-dimensional batched dot products, block-level Top-K, and irregular gathers need fused implementations, or scheduling overhead will eat the theoretical gains. If you deploy on a container platform, connect custom operators with monitoring, alerting, and logging services so long-tail latency is easier to diagnose.
6. Accuracy Safeguards and Evaluation Advice
The risk of sparsification concentrates on missed recall: once a key token is not selected, subsequent generation will drift irreversibly. In practice, three safeguards help:
- A mandatory local window: the most recent tokens always participate in attention, preserving local coherence;
- Hierarchical summaries: build multi-level summaries for extremely long histories, drilling down level by level when coarse filtering fails;
- Task-tiered evaluation: cover single-point retrieval, multi-hop reasoning, global aggregation, and long-document summarization separately, so a single metric does not mask structural weaknesses.
When evaluating, record three kinds of metrics: retrieval recall, end-to-end task accuracy, and the latency breakdown by stage (indexing / attention / sampling). Only by breaking latency apart can you tell whether an optimization landed on the real bottleneck.
7. Conclusion
In the 10-million-token era, the core tension has shifted from “attention cannot be computed” to “relevant tokens cannot be found.” Moving retrieval into a low-dimensional latent space and replacing full scoring with a two-stage coarse-filter-and-refine structure is currently the most cost-effective path. The takeaway for developers is direct: when optimizing long context, measure the latency breakdown first, then decide what to optimize; the gains at the indexing layer are often an order of magnitude higher than at the compute layer. In model-serving practice on platforms such as Baidu AI Cloud, this methodology of “locate the bottleneck first, then choose a sparsification strategy” applies as well, and can be validated continuously against real business workloads using monitoring, alerting, and logging services.
