Sparse Attention at 10 Million Token Contexts: How Latent Sparse Attention Delivers Up to 22x Speedup
As context windows scale from millions to tens of millions of tokens, the main bottleneck in long-context inference shifts from attention computation to the indexing step that decides which tokens to attend to. This article breaks down the cost structure of full and sparse attention, explains how Latent Sparse Attention moves key scoring into a low-dimensional latent space to reduce indexing costs, and reviews reported speedups, accuracy trade-offs, and engineering practices for deploying these methods in ultra-long context scenarios.
Introduction: From Million to 10 Million Tokens, the Bottleneck Has Shifted
Over the past two years, long context has quickly become a standard capability in LLM serving. Million-token context moved from an exclusive feature of a few flagship models to a default specification on many platforms. Models supporting million-token context then began adopting hybrid structures that combine sparse attention with linear attention. These designs share one premise: each query no longer scans all historical tokens but selects only a small set of the most relevant ones for computation.
At the million-token scale, this approach has been repeatedly validated. But as context extends to 10 million tokens, an initially minor overhead starts to spiral out of control. Take one global attention layer in a hybrid attention model that supports million-token context. During prefill at the 10 million token scale, roughly 98% of the time is spent not on attention computation itself, but on the indexing step that decides which tokens to look at.
This changes the nature of the problem. Sparse attention has already shown 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. This article systematically analyzes the principles, benefits, and engineering considerations of a new class of methods known as Latent Sparse Attention.
1. Cost Structure Review: Where Does Attention Overhead Actually Go?
1.1 The Quadratic Bill of Full Attention
In standard full attention, every query computes relevance against all previous keys. With context length T, prefill requires O(T²) computation, and decoding each token costs O(T). Increasing context from one million to ten million tokens theoretically increases prefill attention computation by roughly 100x.
1.2 The Division of Labor in Sparse Attention
Sparse attention works by division of labor: 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 itself to O(Tk).
This approach relies on one premise: the model genuinely needs only a small number of keys. Related validation shows that with shorter contexts, letting each query attend only to the small number of keys most relevant to it (a tiny fraction of all keys) still preserves about 98% of full attention accuracy on long-context benchmarks.
1.3 The Overlooked Hidden Bill
A paradox hides here: for the indexer to know which keys are most relevant, it must first score every key. Common industry approaches include reducing index precision, compressing dimensions, and merging multiple keys into one. In essence, these all aim to lighten the indexer’s load. However, as long as scoring is still performed per key, the indexing overhead remains strongly correlated with context length and becomes the dominant cost at the 10 million token scale. This is precisely the opening for achieving “an order of magnitude faster than traditional sparse attention.”
2. Latent Sparse Attention: Moving Selection into a Low-Dimensional Space
The core idea of Latent Sparse Attention is to avoid per-key scoring in the original high-dimensional key space. Instead, keys are first projected into a low-dimensional latent space, where relevance evaluation and candidate filtering take place. The small set of selected original keys is then passed to the attention computation.
The key design breaks down into three layers:
- Dimensionality reduction projection: a learnable linear mapping compresses keys into a low-dimensional representation, significantly reducing memory access and computation during scoring;
- Latent-space retrieval: similarity computation and candidate ranking are performed in the low-dimensional space, moving the indexing stage from quadratic toward sub-quadratic;
- Selective restoration: only the selected small set of keys is restored to its original representation and participates in attention, keeping accuracy loss controllable.
Illustrative pseudocode:
# Pseudocode: single-head flow of Latent Sparse Attentionz = proj_k(keys) # Project keys into a low-dimensional latent spacescores = query @ z.transpose() # Latent-space scoring, significantly lower costidx = topk(scores, k) # Select k candidatesselected = keys[idx] # Restore only the selected keysout = softmax(query @ selected.T) @ values[idx]
The benefit of this design is that the most expensive full scoring step is moved from the original dimensions into a low-dimensional space, while the main attention computation remains exact, achieving a better balance between accuracy and speed.
3. Results and Boundaries: Where Does the Speedup Come From?
According to public descriptions, this class of methods can achieve more than 20x speedup for prefill of a single global attention layer at 10 million tokens, and tens of times speedup for another model structure, while maintaining accuracy close to the original model across multiple tasks. It should be emphasized that these figures are layer-level results under specific experimental conditions. Actual end-to-end gains are affected by model structure, number of attention heads, batch size, and hardware bandwidth.
Three boundaries deserve attention in engineering:
- Gains scale with context length: the longer the context, the higher the proportion of the indexing stage, and the more pronounced the speedup; gains are limited with short contexts.
- Accuracy depends on candidate quality: too small a k value may miss key tokens, requiring sensitivity analysis tailored to the task.
- Synergy with hybrid architectures: the ratio of linear attention to global sparse layers directly affects overall throughput.
4. Deployment Recommendations: How to Use It in Ultra-Long Context Scenarios
- Profile before optimizing: use monitoring and logging services to locate the time distribution in the prefill stage and confirm whether the indexer is the main bottleneck.
- Set k values by layer: different layers and tasks can use different candidate counts to balance accuracy and speed.
- Combine with general cloud capabilities: use container platforms to host inference services, object storage to manage long-text corpora, and monitoring and alerting to track tail latency.
- Build an evaluation loop: evaluate on both long-context benchmarks and real business samples, avoiding a focus on average scores while ignoring long-tail tasks.
Conclusion
In the era of 10 million token contexts, the competitive focus of sparse attention has shifted from “how much to look at” to “how to find what to look at at low cost.” By moving retrieval into a low-dimensional space, Latent Sparse Attention pulls the indexing stage from quadratic toward sub-quadratic, offering a reusable engineering path for ultra-long context inference. For developers, understanding the cost structure, choosing the right optimization layer, and establishing quantitative evaluation are the keys to turning these methods into real business gains.
