Ten Million Token Context: Breaking the Sparse Attention Speed Bottleneck
As million-token context windows become standard in mainstream LLM services, the real barrier to scaling toward ten million tokens is no longer model size or GPU memory, but the cost structure of attention itself. This article breaks down why full attention scales quadratically, why sparse attention shifts the bottleneck to the indexer, and how Latent Sparse Attention moves selection into a low-dimensional latent space to achieve sub-quadratic indexing. It includes a conceptual pseudocode example, the rationale for this approach, and a practical engineering checklist for adoption.
Ten Million Token Context: Breaking the Sparse Attention Speed Bottleneck
1. Ultra-Long Context Is Becoming the New Battleground for LLMs
Over the past year, mainstream LLM services have moved million-level context from an “optional feature” to a “default specification.” For developers, this means feeding an entire codebase, a full year of logs, a long collection of contracts, or complete multi-turn conversation histories into a single request has shifted from a demo to an everyday task. When stakeholders keep asking “can we reach ten million tokens,” the nature of the problem has quietly changed: it is no longer about whether the model parameters or GPU memory are sufficient, but about the cost structure of the attention mechanism itself.
Understanding this requires going back to the basic accounting of attention.
2. Two Expansions of Attention Cost
2.1 Full Attention: Quadratic Growth with Length
In standard full attention, every query computes relevance against all preceding keys. Let the context length be T:
- The compute for the prefill stage is roughly O(T²);
- The incremental compute for decoding each token is roughly O(T).
When the context grows from 1M to 10M, the length increases 10x, and the prefill attention compute grows by roughly 100x. This curve is unacceptable from an engineering standpoint.
2.2 Sparse Attention: Push Attention Down, Push Indexing Up
The division of labor in sparse attention is clear: a lightweight “indexer” first selects the k most relevant keys for each query, and then the actual attention is computed only over those k keys. The main attention overhead is thus compressed to O(Tk), and as long as k is far smaller than T, this part is nearly negligible.
This approach rests on a repeatedly validated premise: the model really only needs a small number of keys. Ablation studies on long-context benchmarks across the industry have reached a fairly consistent conclusion—at the 128k scale, letting each query attend to only about 512 of its truly most relevant keys (typically less than 1% of the total) still preserves roughly 98% of full attention’s effectiveness. In other words, “looking at only a small fraction” is enough to retain accuracy.
But the bill has not disappeared; it has just moved. To decide which 512 keys are most relevant, the indexer must first score every key. This creates a paradox: after attention is sparsified, the cost of deciding “where to look” actually grows quadratically with context length.
2.3 An Overlooked Overhead
Take a global attention layer in a model that supports million-level context as an example. During prefill at 10M tokens, roughly 98% of the time is not spent on attention computation but on the indexer. Put differently, the bottleneck is no longer “computing attention” but “selecting tokens.”
Existing mitigations—lowering index precision, compressing index dimensions, or merging multiple keys into a block before scoring—only shrink the constant factor; they cannot change the order of magnitude of indexing growing quadratically with length. This is the real wall in the ten-million-token scenario.
3. Latent Sparse Attention: Moving “Selection” into a Low-Dimensional Space
Recently, an overseas startup research institution and a European technical university jointly published a method called Latent Sparse Attention, aiming to reduce ultra-long-context attention from quadratic to sub-quadratic. Its core idea can be summarized in one sentence: do not perform selection in the original token space; instead, first construct a low-dimensional latent space and complete relevance scoring and candidate filtering within it.
The logic chain is as follows:
- Dimensionality-reduced scoring: Project keys into a low-dimensional latent representation, and have the indexer compute query-key similarity in the low-dimensional space. Scoring cost drops from being quadratically related to T to being approximately linearly related to T.
- Candidate recall: Recall a small number of candidates (block-level or token-level) for each query in the latent space, with the candidate size still controlled by k.
- Exact attention: Perform high-precision attention only on the recalled candidates to guarantee output quality.
- Complexity result: The overall cost drops from O(T²) to sub-quadratic, and the accuracy loss introduced by k is compensated by the expressive power of the latent space.
The published material gives a reference magnitude: at 10M tokens, prefill for a single attention layer can be sped up by more than an order of magnitude, with speedup ratios varying across model sizes, while maintaining accuracy close to the original model on a range of long-context tasks. It should be emphasized that such numbers are results under specific implementations and specific hardware, and engineering deployment must re-measure with your own model and workload.
The following illustrative pseudocode helps explain the “index first, then compute exactly” structure:
# Conceptual illustration, not a real APIdef latent_sparse_attention(Q, K, V, k):# 1. Project into a low-dimensional latent spaceK_lat = project_to_latent(K) # shape: [T, d_lat], d_lat << d_headQ_lat = project_to_latent(Q)# 2. Score and recall top-k in the latent space (approximately linear cost)scores = Q_lat @ K_lat.T # low-dimensional similarityidx = topk(scores, k) # candidate key indices for each query# 3. Compute exact attention only on candidatesK_sel = gather(K, idx)V_sel = gather(V, idx)return softmax(Q @ K_sel.T / sqrt(d)) @ V_sel
4. Why This Path Is Worth Pursuing
- Correct order of magnitude: Existing solutions optimize the constant; the latent-space solution optimizes the order of complexity, and only the latter can support 10M and even longer contexts.
- Controllable accuracy: The sparse route has been proven acceptable even at extremely low recall rates, and the latent space further reduces the probability of “selecting wrongly.”
- Engineering pluggability: Indexing and exact computation are decoupled, making it easy to stack with existing optimizations such as chunked prefill, KV cache reuse, and operator fusion.
5. Engineering Adoption Checklist
- Measure the indexing share first: Break down prefill time at the target length to confirm whether the indexer has become the dominant term, avoiding premature optimization.
- Jointly tune latent dimension and recall rate: Too low a latent dimension leads to wrong selections, while too high defeats the purpose of dimensionality reduction; k should be set based on task type (retrieval vs. summarization).
- Coordinate with chunking strategy: Splitting long sequences into chunks and reusing caches can further amortize indexing cost.
- Accuracy regression: Use long-context benchmarks to build a recall-rate–accuracy curve and lock in a working point acceptable for the business.
- Observability: Establish monitoring metrics for indexing time, candidate hit rate, and cache reuse rate to make regressions easier to locate.
6. Conclusion
The core tension of ten-million-token context has shifted from “being able to compute” to “selecting accurately and quickly.” The answer offered by Latent Sparse Attention is to move selection into a low-dimensional space, trading sub-quadratic indexing cost for scalability. For developers, what truly needs to be mastered is not a specific implementation, but the transferable design paradigm of “dimensionality-reduced indexing first, exact attention second,” and to validate the boundaries of its benefits with your own model and workload.
