Sparse Attention at 10M Token Context: Solving the Indexing Bottleneck
As context windows move from 1M to 10M tokens, the main cost of sparse attention shifts from attention computation to the indexer that selects which keys to attend to. This article explains why that indexing step still scales quadratically, introduces Latent Sparse Attention (LSA), which moves similarity search into a low-dimensional latent space to push indexing toward sub-quadratic cost, and covers reported layer-level speedups, accuracy considerations, engineering practices, and evaluation recommendations for long-context deployment.
1. Long Context Enters the 10M Token Era
Million-token context is shifting from a differentiating feature to a baseline configuration. Some providers already ship 1M context as the default spec of their official service, and some model families have recently introduced hybrid architectures that combine sparse attention with linear attention. These designs share the same assumption: instead of having every query scan the entire token history, each query selects only a few of the most relevant keys to attend to.
This approach has been validated repeatedly at the 1M scale. But as context keeps growing toward 10M tokens, an initially unremarkable overhead starts to spiral.
Take one global attention layer in a model that supports a hybrid attention architecture. Running prefill at 10M tokens, roughly 98% of the time is not spent on the attention computation itself, but on the indexing step that decides which tokens to look at. The nature of the problem changes accordingly: sparse attention has already shown that attending to a small subset is enough to preserve accuracy, so what actually blocks long context is that the cost of finding that subset still grows quadratically with context length.
2. The Hidden Cost of Sparse Attention
2.1 A Quick Recap of Attention Cost
In standard full attention, every query computes relevance against all previous keys. With context length T, prefill costs O(T²) and decoding each token costs O(T). Going from 1M to 10M tokens means the attention computation in prefill grows by roughly 100x in theory.
2.2 Division-of-Labor Sparsification
The core idea of sparse attention is a division of labor: a lightweight indexer first picks the k most relevant keys for each query, and the actual attention is computed only over those k keys, bringing the cost of attention itself down to O(Tk).
This works under one premise: the model really does need only a few keys. Related validation shows that at 128k tokens, letting each query attend only to its 512 “truly” most relevant keys (about 0.8% of all keys) still preserves roughly 98% of full-attention accuracy on long-context benchmarks.
2.3 The Paradox
For the indexer to know which 512 keys are most relevant, it has to score every key first. Common industry approaches include lightweight scoring based on low-rank projections, two-stage filtering based on local windows plus global summaries, and approximate retrieval that reuses some attention heads. Whichever is used, as long as scoring must cover all historical keys, the indexing stage remains O(T²). Attention itself gets cheaper, but the indexer becomes the new dominant cost.
The following illustrative pseudocode shows this structure:
# Naive sparse attention: the indexing stage is still quadraticscores = indexer.score(q, all_keys) # O(T^2)topk_idx = topk(scores, k) # O(T log k)out = sparse_attention(q, keys[topk_idx])# O(Tk)
3. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Space
A method called Latent Sparse Attention (LSA), released by a research team in collaboration with universities, aims to push long-context attention into the sub-quadratic regime. Instead of further optimizing the scoring formula, it changes where scoring happens.
3.1 Basic Construction
LSA first projects keys and queries into a low-dimensional latent space, performs similarity retrieval and top-k selection there, then maps the selected indices back to the original space for exact attention. Because the latent dimension is far smaller than the head dimension, both the constant factor and the growth of the indexing stage are significantly reduced.
# Latent sparse attention: indexing stage is near-lineark_lat = proj_k(keys) # O(T)q_lat = proj_q(q) # O(1)scores = sim(q_lat, k_lat) # O(T * d_lat)topk_idx = topk(scores, k)out = sparse_attention(q, keys[topk_idx])# O(Tk)
3.2 Why Accuracy Holds Up
The low-dimensional projection is not arbitrary compression: the indexer is only responsible for coarse filtering, while exact scoring is still done by the original attention. Recall in the coarse stage sets the upper bound, so implementations typically pair it with a two-stage strategy: first take a candidate set in the latent space (for example, 2k to 4k), then run exact top-k within that candidate set. This avoids full exact scoring while reducing the risk of missing relevant keys.
3.3 Reported Results
At 10M tokens, the method reports roughly 22.7x and 72.4x speedups for prefill on a single global attention layer (corresponding to two model configurations of different scale), while maintaining accuracy close to the original model across multiple long-context tasks. Note that these numbers are layer-level results under a specific implementation and hardware setup; in production, measure on your own model and cluster.
4. Engineering Practices
- Layered hybrid design: use LSA for coarse filtering in global layers, keep sliding windows in local layers, and let linear attention layers serve as a low-cost long-range channel, so the three complement each other.
- Tuning the candidate set: too small a candidate set hurts recall; too large degrades back to quadratic. Start from 2k and adjust along the task’s recall curve.
- Overlap indexing with computation: the indexing stage is memory-access heavy and can be pipelined with the previous layer’s computation to hide latency.
- Memory and bandwidth: the latent cache must stay resident, so plan capacity alongside the KV cache; prioritize a contiguous layout for index tensors.
- Observability: monitor indexing time, recall, and top-k hit rate to avoid silent regressions where accuracy holds but latency does not improve.
5. Evaluation Recommendations
- Benchmarks: combine a general long-context benchmark, retrieval-augmented QA, and repository-level code understanding to cover different sparsity patterns.
- Metrics: look at prefill latency, decode throughput, peak memory, recall, and task accuracy together.
- Regression strategy: fix the random seed and candidate-set configuration, run layer-level benchmarks first, then end-to-end validation.
6. Conclusion
At 10M-token context, the central challenge has moved from “too expensive to compute” to “too slow to find.” The direction LSA offers is to move retrieval into a low-dimensional space so that indexing goes from quadratic to sub-quadratic. For developers, the real payoff is not a single speedup number, but taking long context from “it runs” to “it scales in deployment.”
