Latent Sparse Attention: A New Path to Faster Inference at 10M-Token Contexts
Sparse attention is a proven way to keep long-context models accurate, but at tens of millions of tokens the indexer—not the attention kernel itself—becomes the dominant cost. This article explains why the indexing stage scales quadratically, how Latent Sparse Attention moves candidate selection into a low-dimensional latent space, and what this means for prefill speedup, precision guarantees, and practical deployment.
1. From Millions to Tens of Millions: The Bottleneck Has Moved
A common design in long-context models is this: instead of computing attention between every query and all historical tokens, the model first selects a small set of the most relevant tokens, then runs exact attention only on those candidates. This approach has been repeatedly validated at million-token context lengths: the attention kernel only computes over candidate tokens, so compute grows roughly linearly with the candidate budget rather than quadratically with context length. But as contexts push toward ten million tokens, an overhead that once seemed negligible starts to spiral out of control.
Take a class of hybrid attention models that support million-token contexts. At the ten-million-token scale, a time breakdown of prefill for a single global attention layer shows the indexer accounting for as much as 98% of the time. In other words, only a small fraction of time goes to the attention computation itself—most of it is spent deciding which tokens to look at. The nature of the problem has therefore changed: sparse attention has already proven that “looking at only a small subset” is enough to preserve accuracy. What actually blocks ultra-long contexts is that “finding that small subset” still scales quadratically with context length.
A joint research effort has proposed Latent Sparse Attention. Its published results claim that, at the ten-million-token scale, prefill of a single attention layer in a certain class of hybrid attention models can be accelerated by 22.7x, and a 27B-parameter model can achieve a 72.4x speedup, while maintaining accuracy close to the original model across a range of tasks. It is important to emphasize that these numbers describe single-layer prefill scenarios; end-to-end gains still depend on the number of layers, batch size, hardware, implementation quality, and decode-phase behavior.
2. Why the Indexer Becomes the Dominant Cost
Let the context length be L, with L queries processed in parallel during prefill. Let the indexer’s hidden dimension be d_i, the candidate budget be k, and the attention hidden dimension be d. Explicit sparse attention typically involves two cost components:
- Indexing stage: each query scores or routes against all historical tokens, costing roughly O(L²·d_i);
- Attention stage: each query runs exact attention over only k candidate tokens, costing roughly O(L·k·d).
When L = 10⁷ and k is in the hundreds to thousands, the L² term vastly exceeds the L·k term. Reducing d_i yields only constant-factor improvements, and shrinking the candidate budget k mainly affects the second cost component—it cannot change the structural fact that in the indexing stage, every query still scans the entire history. So at ten-million-token scales, further optimizing the attention kernel offers limited returns; what must change is how the indexer interacts with the context.
3. The Core Idea of Latent Sparse Attention
The core of Latent Sparse Attention is not to eliminate sparse selection, but to replace “pairwise scoring over the explicit token sequence” with “coarse filtering and fine ranking in a low-dimensional latent space.” Its design goals can be summarized in three points:
- A compressible, reusable history representation: historical tokens are projected block-wise or cluster-wise into a low-dimensional latent space, forming a cacheable index structure that avoids repeatedly scanning the raw high-dimensional representations for every query;
- Coarse filtering first, fine ranking second: the query is projected into the same latent space, first retrieving a small number of candidate blocks or clusters, then performing token-level fine ranking within the candidates, and finally running exact attention only on a small set of tokens;
- An accuracy safety net: selected tokens still go through the original exact attention. The indexer is only responsible for recalling candidates—it does not replace the attention computation itself.
Illustrative pseudocode:
def latent_sparse_attention(query, history_tokens, top_k):# History side: project blocks into a low-dimensional latent space;# the index can be cached and updated incrementallyhistory_latent = project_blocks(history_tokens)index = build_block_index(history_latent)# Online side: project the query, coarsely filter candidate blocks,# then fine-rank tokens within those blocksquery_latent = project_query(query)candidate_blocks = index.search(query_latent, top_k_blocks)candidates = refine(query, history_tokens[candidate_blocks], top_k)# Exact attention applies only to a small set of candidate tokensreturn exact_attention(query, history_tokens[candidates])
From a complexity standpoint, if the history is compressed into m blocks or clusters where m is far smaller than L, the indexing stage no longer requires L² pairwise token interactions. Instead, it approaches near-linear or sub-quadratic cost: “history projection + block-level retrieval + within-block fine ranking.” History projection can be done offline or incrementally, so the online cost mainly falls on query projection, candidate block search, and a small amount of fine ranking. For ten-million-token prefill, this is precisely the key shift: moving the dominant cost from “full pairwise scoring” to “low-dimensional retrieval.”
4. Where the Speedup Comes From, and How Accuracy Is Protected
The speedup comes from three sources. First, the indexer operates in a lower dimension, making distance computations cheaper. Second, the history index is reusable—during prefill, a large number of queries share the same historical structure. Third, after block-level coarse filtering, the scope of token-level fine ranking and exact attention shrinks dramatically. It is important to distinguish “single-layer prefill speedup” from “end-to-end speedup”: the former is direct evidence of the method’s effectiveness, while the latter is also affected by decode, memory bandwidth, index construction, and batch scheduling.
Accuracy protection typically hinges on candidate recall. The risk with sparse attention is not “computing attention wrong” but “failing to recall the tokens that should have been looked at.” Engineering effort should therefore focus on: whether block-level coarse filtering preserves sufficient recall; whether token-level fine ranking can push the truly relevant tokens into the top-k; whether local windows, global summary tokens, or a few full-attention layers are retained as a fallback; and whether the indexer and attention need to be jointly trained or distilled. Evaluation should not rely on perplexity alone—it should also cover long-document retrieval, multi-hop question answering, code completion, and multi-turn conversation memory, while monitoring accuracy degradation curves across different context lengths.
5. Engineering Considerations for Deployment
First, decouple the indexer from attention. The index structure should support incremental updates, avoiding a full rebuild every time new history is added; latent history representations can be cached, but memory and bandwidth overheads must be watched. Second, make the candidate budget adaptive. Retrieval difficulty varies across layers and queries, and a fixed top-k may either waste compute or hurt recall, so adjust it dynamically per layer or per query. Third, pipeline in parallel. History projection, index search, token fine ranking, and exact attention can be staged into a pipeline to reduce idle waiting during prefill. Fourth, build in fallback strategies. When indexer time share becomes abnormally high, recall drops, or task accuracy fluctuates, fall back to a more conservative candidate budget or full-attention layers. Fifth, end-to-end benchmarks must include time-to-first-token, throughput, memory footprint, and long-document task accuracy—not just single-layer operator speedups.
6. Applicability and Conclusion
Latent Sparse Attention suits scenarios where “the history is very long but each step needs only a small amount of evidence”—such as ultra-long document retrieval, codebase-scale contexts, log analysis, and multi-turn conversation memory. Its limitations are equally clear: latent-space compression may lose fine-grained information; frequently updated dynamic histories increase index maintenance costs; insufficient candidate recall directly hurts accuracy; and single-layer speedup does not equal system-level gains. In practice, teams should first profile the indexer’s time share, then validate candidate recall and downstream accuracy, and finally tune end to end.
Overall, the focus of ultra-long-context optimization is shifting from “how to compute less attention” to “how to cheaply find where attention should be computed.” Latent Sparse Attention moves the indexer from full pairwise interaction over explicit tokens to low-dimensional latent retrieval, offering an interpretable, engineering-friendly path to cost reduction for ten-million-token prefill. For developers, the key is not chasing a single speedup number, but understanding the trade-offs among the indexer bottleneck, candidate recall, and end-to-end gains—and using that understanding to design long-context inference systems that are monitorable and recoverable.
