Latent Sparse Attention: Speeding Up Indexing at 10M-Token Contexts
As context windows push from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from attention computation itself to the indexing stage that decides which tokens to attend to. This article explains why indexing cost grows quadratically, how latent sparse attention reduces scoring cost by operating in a low-dimensional latent space, reported single-layer prefill speedups of up to 72.4x at 10M tokens, and the practical engineering considerations for adopting such an approach.
Latent Sparse Attention: Speeding Up Indexing at 10M-Token Contexts
1. The Evolution of Long Context
Over the past year, mainstream large model services have expanded context windows from hundreds of thousands to millions of tokens. A million-token context has gone from an experimental feature to a default specification across multiple providers. One of the key techniques behind this expansion is sparse attention.
Standard attention computes relevance between every query and all historical tokens, so compute grows quadratically with context length n. Sparse attention instead lets each query select only a small set of the most relevant tokens. This reduces the core attention computation from O(n²) to a scale tied to the number of selected tokens. Extensive practice over the past year has shown that as long as the right small subset is chosen, model accuracy is largely preserved.
Million-token scale is now well understood, but as context pushes toward ten million tokens, a previously negligible cost starts to spiral out of control.
2. The Bottleneck Shifts from Computation to Indexing
Sparse attention must solve two sub-problems:
- Indexing (selection): deciding which tokens the current query should attend to;
- Computation: running standard attention over the selected tokens.
Within the million-token range, indexing overhead is usually acceptable. But at ten million tokens, indexing cost escalates rapidly. For a global attention layer at 10M tokens during prefill, more than 98% of the time is spent not on attention computation itself, but on the indexer that decides “which tokens to look at.”
This shows the nature of the problem has changed. Sparse attention long ago proved that “looking at only a small part” is enough to preserve accuracy. What truly constrains ultra-long context is the act of finding that small part. If indexing still grows quadratically with context length, then even heavily compressed attention computation will be dragged down by the indexer.
Why Indexing Becomes the Bottleneck
A common indexing approach scores every query against all historical tokens, then takes the Top-K. The scoring cost can be roughly expressed as:
- Number of queries × number of historical tokens × scoring vector dimension
During prefill, the number of queries is also close to the context length, so total cost approaches O(n² × d). With dimension d fixed, this term still grows quadratically in n. Even if Top-K selection itself is fast, the preceding full scoring pass dominates runtime.
3. The Core Idea of Latent Sparse Attention
A team of European startup researchers and university academics recently proposed Latent Sparse Attention, targeting exactly the indexing bottleneck described above.
Based on the scheme’s name and public abstract, its core idea is to move relevance scoring in the indexing stage into a low-dimensional latent space, thereby reducing the per query-token scoring cost. For the specific mapping method, training procedure, and implementation details, refer to the original paper. This article only discusses general principles and does not speculate on details the paper does not disclose.
From an engineering perspective, such schemes typically need to answer three questions:
- Where does scoring happen: in the original high-dimensional space or a compressed latent space;
- How is the candidate set generated: is a coarse filter needed before fine selection;
- How is accuracy guaranteed: does compression-induced ranking distortion affect the final Top-K results.
These three questions determine the scheme’s applicable scope. The illustrative code below shows the general sparse attention pipeline, where the indexer’s internals can be swapped for any scoring method, including latent-space scoring.
import numpy as npdef sparse_attention(q, K, V, indexer, k_top=2048):"""Illustrative code: the three stages of generic sparse attention.q: current query vector, shape [d]K, V: historical key/value matrices, shape [n, d]indexer: any scoring function returning relevance scores of shape [n]k_top: number of tokens retained per query (example parameter)"""# Stage 1: index scoring (where most of the cost concentrates)scores = indexer.score(q, K)# Stage 2: select the k_top highest-scoring positionsidx = np.argpartition(-scores, k_top)[:k_top]# Stage 3: run standard attention over the selected tokensk_sel, v_sel = K[idx], V[idx]logits = q @ k_sel.T / np.sqrt(q.shape[-1])w = np.exp(logits - logits.max())w /= w.sum()return w @ v_sel
The key point of this code: stages 1 and 3 have completely different cost structures. When stage 1 becomes the dominant cost, optimizing the scoring method is more effective than optimizing the attention computation.
4. Performance Data and Interpretation
According to the original research report, at the 10M-token scale, latent sparse attention achieved the following single-layer prefill speedups on two models:
| Subject | Context Size | Single Attention Layer Prefill Speedup |
|---|---|---|
| Model A (global attention layer) | 10M tokens | ~22.7x |
| Model B (~27B-parameter dense model) | 10M tokens | ~72.4x |
The report also states that accuracy after the modification remains close to the original model across a range of tasks.
When interpreting these numbers, keep three boundaries in mind:
- The measurement scope is a single layer, prefill stage only. End-to-end decoding speed, overall throughput, and time-to-first-token require separate evaluation.
- The speedup ratio is directly tied to the original bottleneck share. The larger speedup on Model B suggests indexing accounted for a higher share of its original cost. The speedup multiplier cannot be directly transferred to other models.
- “Similar” accuracy needs task-specific validation. The report’s accuracy conclusions apply to its test sets and cannot substitute for evaluation on your own business data.
5. Engineering Considerations for Adoption
Teams considering a similar scheme in their own systems should plan around the following areas.
1. Memory and KV Cache
The KV cache for ten million tokens can itself exceed single-machine GPU memory. If the indexing scheme requires storing additional latent representations, it adds to GPU or host memory usage. Before rollout, estimate the added per-token storage cost and multiply it by the target context length.
2. Incremental Index Updates
During decoding, historical tokens grow step by step. If the index structure needs to be rebuilt, decoding latency suffers. Confirm whether the index supports incremental appends, and measure the cost of each append operation.
3. Accuracy Regression Testing
Cover at least the following scenarios:
- Long-document QA where key information sits in the middle of the context;
- Multi-hop tasks requiring reasoning across large spans of text;
- Structured long text such as code repositories or logs.
Each test should compare results from the original attention and the sparse scheme side by side, and record changes in Top-K hit rates.
4. Phased Validation
A sensible rollout sequence:
- Reproduce the single-layer prefill latency breakdown on offline data to confirm the indexing share;
- Validate accuracy on a small model or a single layer;
- Run end-to-end stress tests on the full model, covering both prefill and decoding;
- Roll out gradually, keeping a fallback switch to standard attention.
6. Conclusion
The bottleneck of ultra-long context has shifted from “how to compute attention” to “how to find the tokens worth computing.” At the ten-million-token scale, the quadratic cost of index scoring consumes the vast majority of inference time. Latent sparse attention targets exactly this stage, and public reports show significant single-layer prefill speedups while maintaining comparable accuracy.
For engineering teams, the key is to first measure the share of indexing cost in their own systems, then judge whether compressed scoring delivers real gains. Speedup multipliers are only a reference; final conclusions must come from end-to-end performance and accuracy testing.
