Scaling Long Context to 10 Million Tokens: Cutting Sparse Attention Indexing Overhead by an Order of Magnitude
This article explains why, at 10 million tokens, the cost of selecting which tokens to attend to outweighs the attention computation itself. It introduces Latent Sparse Attention (LSA), which moves token selection into a low-dimensional latent space, and reports its prefill speedups and accuracy results. It also gives engineering guidance on profiling attention layers and choosing between sparse attention approaches.
1. The Long-Context Debate: From Looking at Everything to Looking Selectively
The context lengths of large models have grown faster over the past year than many people expected. Models once shipped with 128K as their flagship configuration. Now mainstream models commonly offer million-token context as the default. Long-context capability has become a baseline feature of foundation models, not a differentiator.
The key technique behind this shift is the hybrid architecture that combines sparse attention with linear attention. The core idea is simple. Each query no longer attends equally to every historical token. Instead, a mechanism selects a small set of the most relevant tokens and computes exact attention over them. This approach has been validated repeatedly at the million-token scale. Accuracy loss stays under control, and the savings in memory and compute are substantial.
However, as context grows toward 10 million tokens, a cost that used to be minor starts to get out of control, and the nature of the problem changes.
2. The Real Bottleneck Is Finding Tokens, Not Computing Attention
Take a typical global attention layer as an example for a rough order-of-magnitude estimate. At the 10-million-token scale, during prefill, most of the measured time is not spent on the attention computation itself. It goes to the indexing stage, which decides which tokens to look at. One study reports that this share can reach 98%.
Why is indexing so expensive? Mainstream sparse attention methods usually rely on some retrieval mechanism to pick relevant tokens. This might be block-level importance scoring, top-k selection, or a lightweight index structure. These operations all share the same basic steps:
- Score or summarize all historical tokens once.
- Sort the scores or apply top-k selection.
- Gather the selected results back for exact attention.
The cost of these three steps grows superlinearly with context length. Sparse attention shows that looking at a small subset is enough to preserve accuracy. But finding that subset has become a new quadratic wall. The longer the context, the higher the wall.
3. Latent Sparse Attention: Compressing the Search into a Low-Dimensional Space
A recent joint study proposes Latent Sparse Attention (LSA), a method that targets indexing overhead directly. Its core idea is to move the token selection process from the original high-dimensional representation space into a low-dimensional latent space.
LSA includes several key design choices:
1. Maintain low-dimensional latent summaries. The system keeps a highly compressed latent representation of historical tokens. It does not rely on the raw KV cache for scoring. Because the representation dimension is greatly reduced, the compute and memory access for scoring drop by several orders of magnitude.
2. Perform token selection in latent space. The query first interacts with the low-dimensional summaries to quickly locate a candidate set of tokens. Then it runs exact multi-head attention only over those candidates. The complexity of this selection step changes from growing with the full sequence length to growing with the size of the latent space.
3. Plug into existing sparse architectures. LSA does not change the basic “look selectively” paradigm. It replaces the most expensive part, the selection step, so it can be layered on top of existing sparse attention methods.
4. Results: Prefill Speedups of Tens of Times With Nearly Unchanged Accuracy
In tests at the 10-million-token level, the method shows significant gains:
- For models with a hybrid architecture, the prefill speed of a single global attention layer can exceed 22x.
- For dense attention models with larger parameter counts, the speedup can exceed 70x, because indexing takes a larger share of their cost.
- On standard benchmarks for long-text understanding and retrieval-based question answering, accuracy stays roughly on par with the original models.
The benefit of this kind of optimization grows as context length increases. The longer the context, the larger the share of indexing cost, and the larger the relative gain from latent compression. This matters for future longer contexts, such as hundred-million-token code base-scale or archive-scale tasks.
5. Practical Takeaways for Engineering
For teams that need to deploy long-context capabilities in production, this progress suggests several actionable points:
Start by profiling where time goes inside the attention layer. Do not assume that slow prefill means slow matrix multiplication. Use a profiling tool to break down the attention layer’s internal latency. Confirm the share of time spent in the indexing/selection stage versus the compute stage, then target the real bottleneck. You can start with an analysis like this:
# Pseudocode: latency breakdown of an attention layerattn_compute = measure(attention_forward, q, k, v)index_cost = measure(select_tokens, full_kv, query)# If index_cost / attn_compute is high, the bottleneck is in "finding" rather than "computing"
Distinguish retrieval-based from learned sparse methods. Retrieval-based methods are engineered transparently and are highly interpretable, but their indexing cost grows with length. Latent-space methods internalize the selection process into model inference. Their cost is lower, but they require retraining or fine-tuning to adapt. Each approach fits a different range on the accuracy-cost curve.
Optimize prefill and decode differently. During prefill, there are many queries, so indexing cost surges. During decode, each step processes a single query, so the bottleneck shifts mainly to KV cache memory access and capacity. The two stages need different combinations of optimizations, not a single method.
Apply optimizations by layer in hybrid architectures. Sliding-window and local attention layers do not need extra indexing optimization. Global attention layers are the main battleground. Identify the few layers that are truly expensive, and concentrate the optimization budget there.
6. Conclusion
The competition for long context is shifting from “Can it be supported?” to “Can it be supported cheaply?” After sparse attention solved the compute problem, the quadratic cost of “finding” became the new frontier. Latent sparse attention shows a feasible path: compress the selection process into a low-dimensional representation. It also points to a broader principle for optimization. In long-sequence systems, any hidden stage that grows quadratically with length will eventually become a bottleneck that must be tackled head on.
