Sparse Attention at 10M Tokens: The Key Breakthrough Behind a 22x Prefill Speedup
As language models push context windows from 1M to 10M tokens, the real bottleneck is no longer attention computation but the indexer that decides which tokens to attend to. This article explains Latent Sparse Attention (LSA), a method that moves top-k retrieval into a learned latent space, reducing selection cost from quadratic to near-linear. It covers why selection becomes more expensive than computation, how the two-stage coarse-locate and fine-fetch design preserves accuracy, a production checklist, and guidance on where this approach pays off. Reported results include roughly 22.7x and 72.4x single-layer prefill speedups at 10M tokens with comparable accuracy.
1. Ultra-Long Context Enters the 10M-Token Era, and the Cost Structure Flips
Over the past year, mainstream large models have turned 1M-token context from an optional feature into a default specification. Both general-purpose chat services and code- and document-oriented AI coding tools now use long context to ingest an entire repository, a full contract, or a long multi-turn meeting transcript in a single pass. In the second half of 2025, the industry began pushing toward the 10M-token range, commonly adopting a hybrid architecture of global attention plus sparse/linear layers: global layers handle precise cross-segment retrieval, while sparse or linear layers handle low-cost global information compression and propagation.
This approach has been repeatedly validated at the 1M scale. But as it scales to 10M, an overhead that once seemed negligible starts to spiral. Consider one global attention layer in an open-source large model with hybrid attention: during prefill at 10M tokens, roughly 98% of the time is not spent on the attention matrix multiplications but on the indexer that decides which tokens to look at.
This changes the nature of the problem. Sparse attention has already shown that attending to only a small subset is enough to preserve accuracy. What actually blocks ultra-long context is that the process of finding that small subset still grows quadratically with context length. A new line of thinking has emerged in response: move retrieval into latent space, an approach called Latent Sparse Attention (LSA). Published papers report that at 10M tokens, one hybrid attention model achieves roughly 22.7x prefill speedup for a single attention layer, and a general-purpose model achieves roughly 72.4x, while maintaining accuracy close to the original models across multiple tasks. The rest of this article breaks down how the approach works.
2. Locating the Bottleneck: Why “Selection” Costs More Than “Computation”
To understand the value of LSA, first break long-context prefill time into three parts:
- Indexing/selection overhead: finding the top-k relevant tokens for each query. The naive approach requires scoring the query against all historical tokens, with complexity O(N²·d).
- Attention computation overhead: running attention only over the selected k tokens, with complexity O(N·k·d), where k is usually far smaller than N.
- Memory access and scheduling overhead: reading and writing the KV cache, chunked scheduling, and cross-device communication.
At the 1M scale, parts 2 and 3 still account for a meaningful share. But as N grows from 1M to 10M, the N² term in part 1 quickly consumes all the gains—which is where the “98% of time spent in the indexer” comes from. Put differently, sparse attention optimizes “compute less,” while LSA optimizes “find faster.”
3. How It Works: Moving Top-k Retrieval into Latent Space
The core observation behind LSA is that relevance retrieval does not need to happen in the original token dimension. It introduces a set of learnable low-dimensional latent vectors (latent tokens / compression slots) that compress a long sequence into a fixed-length “summary memory.” A query only needs to compute similarity against this fixed-length set of latent vectors to locate relevant regions, then return to the original sequence to fetch the top-k details.
Illustrative pseudocode (expressing the flow only, not any specific product interface):
# 1) Precompute stage: compress the long sequence into fixed-length latent memorylatent = compress_to_latents(K, V, m) # shape: [m, d_lat], m << N# 2) Retrieval per query: score against only m latent vectorsscores = q @ latent.T # [1, m], independent of Nregion = topk_regions(scores, r) # select r relevant regions# 3) Return to the original sequence to fetch details and run sparse attentionidx = gather_detail(region, k) # fetch k tokens from Nout = sparse_attention(q, K[idx], V[idx])
The key point: step 2’s complexity drops from O(N) to O(m), where m is constant-sized (for example, a few hundred to a few thousand), so the overall cost goes from quadratic to near-linear. The latent vectors learn “how to summarize” through end-to-end training, with no hand-crafted rules required.
4. Why Accuracy Holds Up: Three Design Points
- Two-stage structure of coarse filtering plus fine fetching: the latent space only performs coarse localization, while the final attention still runs on the original tokens, avoiding irreversible information loss from compression.
- Fixed-length memory decoupled from sequence length: m does not grow with N, so memory and bandwidth usage stay stable, making it easier to deploy long-context serving.
- Natural compatibility with hybrid architectures: global layers use LSA for cross-segment retrieval, while sparse/linear layers handle local and global compression. The division of labor is clear, and layers can be replaced incrementally with gradual rollout.
5. Production Checklist: From Prototype to Deployment
- Profile before optimizing: confirm the bottleneck is truly the indexer rather than attention or memory access, to avoid optimizing the wrong stage.
- Chunking and streaming prefill: split the 10M sequence into chunks and update latent memory incrementally to reduce peak memory usage.
- Cache reuse: latent memory can be persisted alongside the KV cache to object storage or a distributed cache, avoiding repeated compression across multi-turn conversations.
- Accuracy regression: run A/B tests on three task types—long-document QA, cross-file code retrieval, and multi-turn summarization—monitoring top-k hit rate and answer consistency.
- Observability: set up monitoring and alerts for indexing time, selection rate, and compression ratio to prevent long-tail requests from degrading P99.
6. Limitations and Selection Guidance
The gains from LSA-style methods depend heavily on the scenario: retrieval-oriented tasks (long-document QA, code retrieval) benefit most, while purely generative tasks with strong local dependencies benefit less. For deployment: below 1M tokens, prefer mature sparse approaches; in the 1M–10M range, evaluate latent-space retrieval; and keep a switch to disable the optimization for rollback. Overall, reducing “selection” from quadratic to near-linear is a key step in taking ultra-long context from “it runs” to “usable and affordable.”
