Sparse Attention at 10 Million Tokens: Fixing the Quadratic Indexing Bottleneck for 22x Faster Prefill
As context windows scale from hundreds of thousands to millions of tokens, sparse attention has become the default way to keep long-context inference affordable. But at 10 million tokens, the bottleneck shifts from computation to retrieval: the indexer that decides which tokens to attend to consumes most of the prefill time. This article explains why the quadratic indexing cost arises, how Latent Sparse Attention (LSA) moves candidate lookup into a low-dimensional latent space to approach linear scaling, and what the reported speedups and accuracy results look like. It also covers practical deployment considerations such as profiling the indexer, tuning the latent dimension, combining latent screening with chunking, and aligning training with inference.
1. At Extreme Context Lengths, the Bottleneck Moves From Compute to Lookup
Over the past two years, long-context capability has advanced rapidly from hundreds of thousands of tokens to millions, and is steadily becoming the default specification for mainstream model serving. The key technical choice behind this progress has been remarkably consistent: instead of having every query scan all historical tokens, each query selects only a few of the most relevant tokens to participate in computation. Sparse attention has therefore become the de facto standard configuration, and approaches such as hybrid linear attention are also used to further reduce the cost of global interaction.
This approach has been repeatedly validated at the million-token scale. But as context continues to grow toward 10 million tokens, an originally negligible overhead begins to spiral out of control. Take a global attention layer as an example: at the 10-million-token scale, most of the prefill time is not spent on the matrix operations of attention 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 “attending to only a small subset” is enough to preserve accuracy; what truly blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length. In other words, sparsification solved the computation volume but did not solve the retrieval volume.
2. Where the Quadratic Indexing Cost Comes From
To understand the optimization space, an attention layer can be broken into three stages:
- Scoring: compute similarity between the query and all historical keys to produce a candidate ranking;
- Selection: pick the few most relevant tokens according to a Top-K rule;
- Aggregation: perform a weighted sum over only the selected tokens.
The first stage is the root of the quadratic cost. Even if only K tokens are ultimately retained, the scoring stage still has to cover all N historical positions, giving a complexity of roughly O(N²·d). As N grows from millions to tens of millions, this term quickly consumes the entire time budget, while the genuinely valuable aggregation computation accounts for a tiny fraction.
Common engineering mitigations each have their limits: chunking and local windows reduce the constant factor but sacrifice long-range dependencies; cache reuse amortizes repeated queries but offers little help for one-off long-document prefill; quantization and operator fusion improve compute utilization per unit but cannot change the algorithmic essence that “the full set must be scanned once.”
3. Latent Sparse Attention: Moving Retrieval Into a Low-Dimensional Space
A recent paper from a joint research team proposes Latent Sparse Attention (LSA). Its core idea is not to keep optimizing the scoring operator, but to change the space in which retrieval happens: keys are first projected into a low-dimensional latent representation, candidate localization is completed in that low-dimensional space, and precise aggregation is then performed back in the original space.
It can be understood as “check the index first, then turn to the body text.” The original key sequence is like flipping through page by page, while the latent-space index is like a compressed table of contents: lower in dimension, more regular in structure, and efficiently searchable in batches. Because the localization cost is dominated by the latent dimension rather than the original dimension, overall complexity drops significantly from quadratic and approaches linear growth with context length.
A schematic flow can be written as:
# Pseudocode: latent retrieval + original-space aggregationz = project_to_latent(keys) # compress historical keys into a low-dimensional latent spacescores = query_latent @ z.T # low-dimensional scoring at much lower costidx = topk(scores, k) # select candidate positionsout = softmax(q @ keys[idx].T) @ values[idx] # precise aggregation back in the original space
The key point is the two-level structure of “coarse localization + precise aggregation”: the low-dimensional space is only responsible for narrowing the candidate range and bears no accuracy responsibility; accuracy is still guaranteed by a small amount of precise computation in the original space. This is also why LSA can achieve order-of-magnitude speedups while maintaining accuracy close to the original model.
4. Measured Gains and Accuracy
The results reported in the paper show that at the 10-million-token scale, the prefill stage of a single attention layer can achieve more than 20x speedup, with some model configurations exceeding 70x. The difference mainly comes from how well the model’s original indexing implementation matches the latent dimension: the higher the original indexing overhead, the greater the relative gain after the change.
The accuracy-side conclusion is equally important: across a series of long-context tasks, the modified model’s outputs are close to those of the original model, indicating that low-dimensional retrieval does not miss key tokens. In engineering practice, two additional metrics are typically observed: candidate hit rate (whether the selected tokens cover the bulk of the original Top-K) and recall on long-range dependency tasks, so that end-to-end scores alone do not mask local degradation.
5. Deployment Considerations
- Profile before optimizing: use operator-level profiling to confirm the indexer’s share, and avoid spending time on the wrong stage.
- The latent dimension is the main knob: too low hurts recall, too high shrinks the gains, so run a small-scale sweep per task.
- Coordinate with chunking: exact computation within chunks and latent coarse screening across chunks is a more stable combination for ultra-long context.
- Keep training and inference consistent: if the model can be further trained, jointly optimizing the latent projection with the main task is usually more stable than inserting it after the fact.
- Supporting infrastructure: ultra-long prefill puts heavy pressure on memory and throughput, so it can be combined with elastic scaling on a container platform, object storage for hosting long documents, and logging and monitoring services to locate long-tail latency.
6. Conclusion
The core tension of 10-million-token context is retrieval cost, not computation cost. Migrating “finding relevant tokens” from the original high-dimensional space to a low-dimensional latent space—trading coarse localization for linear complexity and precise aggregation for accuracy—is currently one of the most cost-effective directions. For teams that need to control prefill latency in scenarios such as ultra-long documents, repository-level code understanding, and multi-turn long conversations, this approach is worth validating first.
