Sparse Attention at 10M Context: How Latent-Space Retrieval Removes the Indexing Bottleneck
Long-context models have moved from 1M to 10M tokens, but sparse attention still carries a hidden quadratic cost: the indexer that decides which keys to attend to. This article breaks down that cost structure and explains Latent Sparse Attention, which moves relevance retrieval from the raw token space into a low-dimensional latent space. It covers the four-stage flow (compression, coarse filtering, fine-grained attention, calibration), sample pseudocode, reported prefill speedups at 10M tokens, engineering considerations such as chunked streaming, quantization and observability, and guidance on when the approach is and is not appropriate.
1. Background: The New Bottleneck Once Long Context Became Standard
Over the past year, million-token context windows have spread quickly. 1M context is now a default spec across mainstream model services, and some lightweight models have adopted hybrid structures that combine sparse attention with linear attention. The industry consensus is straightforward: instead of having every query scan all historical tokens, select a small set of the most relevant keys to participate in the computation.
This approach has been validated repeatedly at the 1M scale. But as context keeps growing toward 10 million tokens, an overhead that used to be unremarkable starts to spiral. In one class of global attention layers, running prefill at 10M tokens spends roughly 98% of the time not on the attention computation itself, but on the indexing step that decides which tokens to look at.
The nature of the problem has therefore shifted. Sparse attention has already shown that attending to only a small fraction of keys is enough to preserve accuracy. What actually blocks ultra-long context is that the cost of finding that small fraction still grows quadratically with context length.
2. Cost Breakdown: Why Sparse Attention Is Still Not Sub-Quadratic
In standard full attention, every query computes relevance against all preceding keys. With context length T, prefill cost is O(T²) and per-token decoding is O(T). Going from 1M to 10M tokens inflates the attention computation by roughly 100x.
Sparse attention splits the work in two: a lightweight indexer first selects the k most relevant keys for each query, then attention is computed only over those k keys, reducing the attention itself to O(Tk). This holds only if the model genuinely needs just a few keys. Related validation shows that at 128k tokens, letting each query attend to about 0.8% of the most relevant keys still retains roughly 98% of full-attention accuracy on long-context benchmarks.
The paradox is that the indexer must score every key to decide which k are most relevant. If scoring itself requires pairwise interaction between the query and all keys, the indexing stage remains O(T²) and the end-to-end pipeline is not truly sub-quadratic. This is the shared “hidden bill” of many current sparse attention designs.
3. Core Idea: Move Relevance Search into Latent Space
The key idea behind Latent Sparse Attention is to move relevance retrieval from the raw token space into a low-dimensional latent space. The flow breaks down into four steps:
- Compress: project the keys/values of the long sequence into low-dimensional latent representations, forming a compact “memory index”.
- Coarse filtering: the query performs a lightweight match only against the latent representations, shrinking the candidate pool from T to a constant-scale set that is only weakly related to T.
- Fine-grained computation: restore the original dimensionality on the candidate subset and run the actual sparse attention.
- Calibration: correct coarse-filtering bias with a small number of global statistics so that key tokens are not missed.
Illustrative pseudocode:
# z: latent memory, dimension d_lat << d_headz = compress(kv) # O(T * d * d_lat)scores = q @ z.T # O(T * d_lat), replacing O(T^2 * d)cand = topk(scores, k) # candidate set of size kout = sparse_attention(q, k, v, cand)
Complexity drops from “pairwise scoring between the query and every key” to “scoring between the query and a low-dimensional latent memory”. The indexing stage becomes near-linear and the end-to-end pipeline enters the sub-quadratic range. The paper reports a 22.7x prefill speedup on one class of global attention layers at 10M tokens, and 72.4x on another model, with multi-task accuracy close to the original model.
4. Engineering Implementation Notes
- Chunking and streaming: build latent memory block by block to support streaming prefill and paged caching, lowering peak GPU memory.
- Quantization and low precision: latent space is more quantization-friendly and can be paired with low-precision storage to further compress bandwidth.
- Coordination with linear attention: use linear attention locally and latent sparse retrieval globally to form hybrid layers.
- Observability: monitor index hit rate, candidate set coverage and accuracy drift, and establish regression baselines.
- Cloud practice: combine elastic scaling on a container platform, object storage for long-context caches, and logging plus monitoring/alerting services for full-pipeline tracing.
5. Applicability and Selection Guidance
Latent Sparse Attention is not a universal fix. For tasks that depend heavily on precise global retrieval, such as exact string matching or verbatim citation across a full document, coarse filtering may miss matches, so you need a larger candidate set or a few retained global layers. In practice, start with 128k for accuracy alignment, then scale up gradually to 1M and 10M. Track “indexing time share” as the core metric: when that share exceeds 50%, the bottleneck has shifted from computation to retrieval, which is exactly the point to introduce a latent sparse approach.
