Sparse Attention at 10M Token Contexts: Cutting Indexing Costs by 22x with Latent Space
Long context has shifted from a differentiating feature to a baseline specification, with 1M token windows now common across mainstream model services. Yet pushing to 10M tokens exposes a hidden bottleneck: the indexer that decides which keys to attend to, which can consume roughly 98% of prefill time in a global attention layer. This article explains why sparse attention alone does not solve the problem, how Latent Sparse Attention moves scoring into a low-dimensional latent space to reduce indexing from O(T²) to sub-quadratic complexity, and what the reported speedups and engineering lessons mean for teams building long-context capabilities.
Sparse Attention at 10M Token Contexts: Cutting Indexing Costs by 22x with Latent Space
Long Context Has Become a Default Spec
Over the past year, long context has quickly moved from a differentiating selling point to a baseline capability. Million-token context windows are becoming the default specification for mainstream model services: some models set 1M context as the uniform standard across all official offerings, while some newer versions support 1M context and introduce a hybrid architecture combining sparse attention with linear attention for the first time.
These designs share a common technical choice: instead of having every query scan all historical tokens, they select only a small set of the most relevant keys for computation. This approach has been repeatedly validated at the 1M scale, with stable results.
But as context keeps expanding to 10 million tokens, an initially unremarkable overhead starts to spiral out of control.
The Overlooked “Hidden Bill”: The Indexer Becomes the Main Cost
Take one global attention layer from a model that supports 1M context. When running prefill at 10M tokens, roughly 98% of the time is spent not on the attention computation itself, but on the indexer that “decides which tokens to look at.”
The nature of the problem has therefore changed. Sparse attention has long proven that “looking at only a small subset” is enough to preserve accuracy. What actually blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.
1. A Recap of the Attention Cost Structure
In standard full attention, every query computes relevance against all previous keys. With a context length of T:
- The prefill stage has a computational cost of O(T²);
- Decoding each token has a computational cost of O(T).
Going from 1 million to 10 million tokens, the prefill attention computation theoretically increases 100x.
2. The Division-of-Labor Idea Behind Sparse Attention
Sparse attention works by division of labor: a lightweight indexer first selects the k most relevant keys for each query, and the actual attention then computes only over those k keys. This pushes the cost of the attention itself down to O(Tk).
This idea holds under one premise: the model genuinely needs only a few keys. Relevant validation shows that at 128k tokens, letting each query attend to only the 512 keys it is truly most relevant to (about 0.8% of all keys) still preserves roughly 98% of full-attention accuracy on long-context benchmarks.
3. The Paradox
But a paradox hides here: for the indexer to know which 512 keys are most relevant, it must first score every key. Mainstream sparse attention designs (whether two-stage indexing that does “coarse filtering then fine ranking,” or architectures hybridized with linear attention) cannot avoid this step. As a result, the computation of the indexing stage remains O(T²), only with a much smaller constant than full attention. Within 1M tokens, this constant advantage is significant enough; at 10M, the quadratic term overwhelms everything.
Schematically, the problem can be abstracted as:
# Naive indexing: score every key for each query, O(T^2) complexityscores = query @ all_keys.transpose(-1, -2) # [T, T]topk_idx = scores.topk(k, dim=-1).indices # select k keys per query
As long as the length of all_keys is T, the cost of this matrix multiplication is unavoidable.
The Breakthrough: Moving Indexing into Latent Space
A recent joint industry study proposes a method called Latent Sparse Attention. Its core idea is: do not perform full scoring in the original token space. Instead, first compress the keys into a low-dimensional latent space, complete coarse filtering in that latent space, and then return to the original space for local fine computation.
Its key mechanism can be broken down into three steps:
- Latent-space compression: Use a lightweight projection to map all keys into a small number of “latent slots.” The number of slots is far smaller than the number of tokens, for example on the order of √T or a fixed constant;
- Latent-space scoring: Each query computes relevance only against these latent slots, reducing complexity from O(T²) to O(T·√T) or even O(T·c);
- Local fine computation: Locate candidate regions based on latent-space scores, and perform exact attention only over the original keys in those regions.
Because the quadratic term is replaced by a sub-quadratic term, indexing overhead at the 10M scale is reduced by more than two orders of magnitude. The reported results are: at 10M tokens, a single attention layer of a 1M-context model achieves a 22.7x prefill speedup, while the same layer in a 27B-class model achieves a 72.4x speedup, all while maintaining accuracy close to the original model across a range of long-context tasks.
Why Latent Space Can “Represent” Original Tokens
Some may ask: won’t scoring after compression miss the truly relevant keys? This relies on two properties that have been widely validated:
- Low-rank nature of attention: The attention score matrix is typically approximately low-rank, and a small number of latent slots can capture the main directions of relevance;
- Hierarchical nature of retrieval: When people look for information, they first check the table of contents (latent space) and then turn to specific pages (original keys). The recall loss of two-stage retrieval is controllable.
In engineering practice, an additional safeguard is usually added: fully expand the top few slots with the highest latent-space scores, ensuring that highly relevant regions are not erased by compression error. This is a typical trade-off of “coarse filtering to preserve recall, fine computation to preserve precision.”
Implications for Engineering Practice
- Bottlenecks migrate: Optimizing long context cannot focus only on the attention itself. Keep profiling continuously to find the real hotspot. Today’s hotspot may be the indexer; tomorrow it may be the memory bandwidth of the KV cache.
- Sub-quadratic is the direction: Whether it is latent-space indexing, hierarchical retrieval, or hybrid linear attention, the essence is to reduce the O(T²) term. When choosing an approach, focus on “indexing complexity” rather than only “attention complexity.”
- Accuracy validation is not optional: Any sparsification scheme must run recall and accuracy regression on long-context benchmarks, especially “needle in a haystack” tasks and cross-segment reasoning tasks.
- Deployment-side coordination: Ultra-long context imposes higher demands on memory, bandwidth, and scheduling. In practice, it often needs to be combined with general techniques such as cache tiering and batching optimizations to share the load.
Conclusion
What is truly hard about 10M-token context is not “being able to compute it,” but “finding accurately and finding fast.” Latent Sparse Attention reduces the indexing stage from quadratic to sub-quadratic, delivering tens-fold speedups in prefill at the 10M scale while holding the accuracy line. For teams building long-context capabilities, this points to a clear engineering principle: continuously optimize the current bottleneck and compress the search space with hierarchical, low-rank ideas to keep inference costs under control in the era of ultra-long context.
