Sparse Attention Indexing at 10M Tokens: The Latent Sparse Attention Approach
As context windows scale toward 10 million tokens, sparse attention reduces the cost of attending to a small subset of keys, but the indexer that selects those keys can become the dominant prefill bottleneck. This article examines the cost structure of ultra-long contexts, explains why top-k indexing remains close to quadratic, and describes Latent Sparse Attention (LSA), which performs retrieval in a low-dimensional latent space before applying exact attention to selected key blocks. It also covers the sources of speedup, accuracy trade-offs, and production considerations such as profiling, decoupling indexing from attention computation, elastic infrastructure, and regression testing.
1. The Cost Structure of Ultra-Long Contexts: Where the Cost Goes
In recent years, large-model context windows have expanded rapidly from hundreds of thousands of tokens to the million-token level, and leading models now commonly treat million-token context as a default service specification. As context continues toward 10 million tokens, an overhead that was once easy to overlook starts to spiral out of control.
Consider the cost of standard full attention. When context length is T, every query in the prefill stage must compute relevance against all preceding keys, resulting in O(T²) computation. In the decoding stage, generating each token costs O(T). If context grows from 1 million to 10 million tokens, prefill attention computation grows by 100×. This quadratic curve is the most fundamental economic constraint on ultra-long contexts.
The idea behind sparse attention is a division of labor: a lightweight indexer first selects the k most relevant keys for each query, and the actual attention computation is then performed only over those k keys, reducing attention overhead to O(Tk). The premise of this approach has been repeatedly validated. Research shows that on long-context benchmarks, allowing each query to attend only to the very small subset of keys that are truly most relevant—for example, less than 1% of all keys—can still preserve roughly 98% of the accuracy of full attention.
2. The Overlooked Paradox: Finding “That Small Subset” Costs More Than Looking at It
The problem lies in the indexer itself. To know which k keys are most relevant, the indexer must first score every key. Mainstream approaches use various cost-reduction techniques: lowering scoring precision, compressing scoring dimensions, or merging multiple keys into a block for coarse-grained evaluation. These techniques reduce the unit cost of scoring, but they do not change the number of scores required. The number of scoring operations still grows linearly with T, and every query must be scored independently.
Actual measurements reveal a striking fact: during prefill at the 10-million-token scale, in a model with a hybrid sparse architecture, roughly 98% of the time in a single global attention layer is not spent on attention computation itself, but on the indexer that decides which tokens to look at. Attention itself is already O(Tk), yet indexing still carries O(T²) or near-O(T²) overhead.
This is the “hidden bill” of sparse attention: sparsification successfully compresses the cost of “looking,” but shifts the bottleneck to “finding.” When context reaches the 10-million-token level, the cost of finding becomes the dominant factor and the decisive contributor to overall latency.
3. Latent Sparse Attention: Compressing Indexing to Sub-Quadratic Complexity
To address this bottleneck, researchers recently proposed a class of methods that can be summarized as Latent Sparse Attention (LSA). The core idea is simple: since scoring every key individually is too expensive, first project keys into a low-dimensional latent space, perform retrieval and filtering there, and then return to the original space for exact attention.
The overall process can be divided into three steps:
- Latent-space projection: A learnable low-rank projection compresses high-dimensional key vectors into very low-dimensional latent representations. Because the projection matrix can be precomputed and incrementally maintained, this step grows linearly with T and has a very small constant factor.
- Latent-space scoring and retrieval: Queries are also projected into the latent space and compared with the latent representations of all keys. Because the latent dimension is compressed by one to two orders of magnitude, scoring computation drops from O(T·d) to O(T·d’), where d’ is much smaller than d. More importantly, scoring can be organized by blocks and use the high throughput of matrix multiplication, completely avoiding the memory-access bottleneck of element-wise scoring.
- Exact attention replay: Based on latent-space scores, the top-k key blocks are selected, and standard attention is then performed over those selected keys in the original high-dimensional space.
The key insight behind this design is that indexing only needs to “find accurately,” not “compute precisely.” Relevance scores in the latent space only need to be sufficient for sorting and for placing truly relevant keys into the top k. After ranking, precise computation is still performed by full-precision attention in the original space. Therefore, the information loss introduced by latent-space projection has almost no impact on final accuracy.
Mechanistically, this resembles the two-stage “dual-tower coarse ranking + fine ranking” architecture in recommender systems: coarse ranking uses a cheap model to filter a small set from a massive candidate pool, and fine ranking uses an expensive model to process only that small set. LSA brings this engineering wisdom into attention itself.
4. Performance and Trade-offs: Where the Tens-of-Times Speedup Comes From
In 10-million-token prefill scenarios, this class of methods can achieve tens-of-times speedup for a single attention layer. The gains can be broken down into three sources:
- The number of scores is unchanged, but the unit cost drops sharply: latent-dimension compression reduces the floating-point computation of scoring by one to two orders of magnitude.
- Memory-access patterns become friendlier: latent representations can reside in high-speed cache or be stored contiguously by block, avoiding the memory-access bottleneck of “large-matrix random access” in original attention.
- Top-k selection overhead is controllable: once k is fixed, the overhead of block selection and exact attention is at the O(Tk) and O(k²) levels, and the relationship with T degrades to linear.
On accuracy, benchmarks covering typical long-context capabilities such as retrieval, multi-hop reasoning, and aggregation show that the gap between this method and the original full-attention model remains small. This suggests that latent-space projection mainly discards redundant information that does not contribute to ranking, rather than task-relevant semantic signals.
Of course, there are costs: the projection matrix requires additional training or calibration; there is a distribution shift between latent-space scores and true attention scores; and extreme retrieval scenarios may produce misses, which need to be mitigated by appropriately increasing k or introducing multi-level filtering.
5. Practical Considerations for Production Deployment
For teams that need to support ultra-long contexts in production, this direction offers several lessons:
- Profile the bottleneck before discussing optimization. Before introducing any sparse scheme, teams should perform operator-level profiling of prefill and decode separately. Many teams find that “attention is slow” and immediately switch to a sparse implementation, only to discover that under ultra-long contexts the indexer becomes the new bottleneck—a costly trade.
- Design indexing and computation in a decoupled way. The precision requirements for the indexer differ from those of attention itself; it can be allowed to use low-precision, low-dimensional, blocked implementations. Implementations that couple the two together are difficult to optimize separately.
- Use elastic scaling of cloud infrastructure. 10-million-token prefill is a typical short-duration, high-throughput workload. It is suitable for on-demand scaling of inference instances through container platforms, combined with object storage to cache computed latent representations and KV blocks, and monitoring and alerting to track the share of indexing time, forming a complete optimization loop.
- Accuracy regression testing cannot be omitted. Any sparsification change should establish a regression pipeline on long-context benchmarks, covering tasks such as needle-in-a-haystack, multi-hop question answering, and long-document aggregation, to ensure that speedups do not come at the cost of accuracy collapse.
6. Conclusion
Sparse attention solves the problem of “seeing less,” while Latent Sparse Attention solves the problem of “finding faster.” As context scale moves from millions to 10 million tokens, the cost of “finding” determines whether the entire technical route is viable. Compressing retrieval into a low-dimensional latent space and reserving exact computation for the selected few keys—this two-stage division of labor is likely to become a standard paradigm for ultra-long-context inference. For engineering teams, what matters more is understanding the methodology behind it: measure first, then decompose, and then match each stage with the appropriate precision and compute. That is more valuable in the long run than chasing any single technique.
