Sparse Attention at 10M Context: Solving the Indexing Bottleneck
As context windows scale from 1M to 10M tokens, sparse attention shifts the bottleneck from attending to the right tokens to finding them. This article breaks down the hidden quadratic cost of indexers, explains how latent-space sparse attention reduces candidate selection to sub-quadratic complexity, and covers the engineering trade-offs, accuracy evaluation, and cloud deployment considerations for million-scale context serving.
1. From Standard Feature to Bottleneck: The Cost Structure of Long Contexts Has Changed
Million-token context is shifting from a selling point to a baseline specification. More model services now ship with 1M context as a default capability and adopt hybrid designs that combine sparse attention with linear attention. The shared logic is straightforward: instead of scanning every historical token, each query selects a small set of the most relevant segments to participate in computation.
At the 1M scale, this approach has been validated repeatedly. But when the context grows to 10 million tokens, the cost structure changes fundamentally. Consider a single global attention layer: during the prefill stage at 10M tokens, roughly 98% of the time is spent not on attention itself, but on the indexer that decides which tokens to look at.
This changes the nature of the problem. Sparse attention has proven that attending to only a small fraction of tokens is enough to preserve accuracy. The real obstacle is that finding that small fraction still grows quadratically with sequence length.
2. The Hidden Bill of Sparse Attention
In standard full attention, every query computes relevance against all historical keys, giving O(T²) prefill complexity and O(T) per-token decoding. Scaling the context from 1M to 10M increases attention computation by roughly 100x.
Sparse approaches split the process into two steps: a lightweight indexer first selects the k most relevant keys for each query, and the actual attention is computed only over those k keys, reducing attention to O(Tk).
However, the indexer must score all keys before it can determine which k are most relevant. Total overhead is therefore approximately O(T² + Tk). When k is much smaller than T, the dominant term is still T². This is the hidden bill: attention got cheaper, but selection did not.
Appendix-style validation supports the “look at less” premise as well: at a 128k context, letting each query attend to only about 0.8% of keys still preserves roughly 98% of full-attention accuracy on long-context benchmarks. The key question is how to find that 0.8% at low cost.
3. Latent-Space Sparse Attention: Moving Selection into a Compressed Representation
One viable approach is latent-space sparse attention. Rather than performing full scoring over raw token representations, the long history is first compressed into low-dimensional, retrievable latent representations. Candidate selection then happens in latent space, and exact attention is applied only to the small set of selected raw keys.
The benefits come from three points:
- Lower scoring dimensionality turns indexing from per-token exhaustive comparison into retrieval over a compressed sequence.
- Candidate generation and exact attention are decoupled and can be optimized separately.
- Compressed representations can be layered and cached, which helps reuse across prefill and incremental decoding.
Illustrative pseudocode:
# z: latent representations of history [T, d_z], d_z << d_k# q: current query representation [d_q]scores = lightweight_index(q, z) # sub-quadratic candidate scoringidx = topk(scores, k) # select a few candidatesk_sel = keys[idx] # fetch original keysout = exact_attention(q, k_sel, v_sel)
In engineering terms, the latent space can correspond to hierarchical pooling, low-rank projection, or learnable memory slots; indexing can use approximate nearest neighbor search or block-wise scanning. The point is not any specific implementation, but reducing “finding what is relevant” from quadratic to sub-quadratic.
4. Complexity and Engineering Gains
Let the compression ratio be r = T/m, with latent length m. If indexing in latent space is O(mT) or O(T log m), total complexity can be written as O(T·poly(log T) + Tk), which is approximately sub-quadratic when k is fixed. Relative to the original O(T²), the theoretical gain at 10M scale can reach tens of times, consistent with the reported magnitude of roughly 22x to 70x speedup for a single attention layer.
Engineering considerations also include:
- Memory: the footprint of compressed representations and candidate caches.
- Bandwidth: random reads of original keys.
- Parallelism: block-wise indexing and pipelined prefill.
- Decoding: incrementally updating latent representations to avoid repeated scans.
5. Preserving Accuracy and Evaluation Recommendations
Latent-space compression may lose detail, so a two-stage “coarse filtering plus fine ranking” design should be retained, with protection for critical tokens such as the recent window, task markers, and citation anchors. Evaluation should cover:
- Long-context retrieval, multi-hop reasoning, and long-document summarization.
- Accuracy–latency curves across different compression ratios and k values.
- Separate metrics for the prefill and decode stages.
- 10M-scale stress testing and memory limits.
6. Cloud Deployment: Combining General-Purpose Capabilities
On a cloud platform, the implementation can combine general-purpose capabilities: container platforms to host inference services, object storage to persist long-context snapshots, message queues to smooth request spikes, and logging plus monitoring with alerting to track prefill latency, candidate hit rate, and memory usage. General cloud product categories offered by providers such as Baidu AI Cloud can serve as the engineering foundation for this kind of ultra-long-context service.
7. Conclusion
At 10 million tokens, the deciding factor is not how much you attend to, but how fast you can find what should be attended to. Moving indexing into latent space is a clear path toward sub-quadratic attention. Combined with two-stage fine ranking and cloud observability, it can significantly reduce prefill cost while preserving accuracy.
