Sparse Attention at 10M Token Context: How Latent Indexing Delivers a 22x Prefill Speedup
This article examines why sparse attention hits a new bottleneck at 10 million tokens, where the indexer that decides which tokens to attend to consumes about 98% of prefill time. It explains the core idea behind Latent Sparse Attention (LSA), which moves token selection into a low-dimensional latent space, and shows how this yields a 22.7x speedup on one global attention layer and 72.4x on a 27B open-source model while preserving accuracy. Readers will also find practical guidance on low-rank projection training, adaptive k, KV cache management, and the difference between prefill and decode, plus how LSA relates to hybrid long-context architectures.
1. Long Context Is Eating the Compute It Saved
Over the past two years, the long-context race has revolved around a single number: from hundreds of thousands of tokens to one million, and then to making one million the default specification for official model services. This year, some providers already offer 1M context as a standard configuration, while others have introduced a “global attention + sparse/linear hybrid” structure in lightweight models for the first time. These approaches share a common underlying choice: instead of having every query scan all historical tokens, each query selects only a few of the most relevant tokens to participate in the computation.
This route has been repeatedly validated at the 1M scale. But when the context is pushed to 10 million tokens, an overhead that was once negligible starts to spiral out of control.
Take one global attention layer in a lightweight model that supports million-token context. At 10M tokens, during prefill, roughly 98% of the time is not spent on the attention matrix multiplications but on the indexer that “decides which tokens to look at.” In other words, the computation saved by sparse attention is consumed again by the task of “finding whom to attend to.”
The nature of the problem has therefore changed:
- Sparse attention has long proven that “looking at only a small subset” is enough to preserve accuracy;
- What actually blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.
Recently, an overseas startup research institution and a European technical university jointly published a paper proposing Latent Sparse Attention (LSA). Its central finding is that at 10M tokens, it can speed up the prefill of a global attention layer by 22.7x (and by 72.4x on another 27B-class open-source model), while maintaining accuracy close to the original model across multiple tasks.
Let’s break this down.
2. Why Indexing Becomes the New Bottleneck
To understand the value of LSA, we first need to make the cost structure of sparse attention clear.
Standard attention has a complexity of O(N²): N tokens interact pairwise. The idea of sparse attention is that each query interacts with only k keys (where k is far smaller than N), reducing the computation to O(N·k). It sounds great, but in practice it usually involves two steps:
- Scoring/selection stage: find the top-k most relevant keys for each query;
- Aggregation stage: perform a weighted sum only over the selected k keys.
The problem is that if the first step is performed directly in the original token dimension, you still have to compute the similarity between the query and all keys, and the complexity returns to O(N²). As a result, two engineering compromises are common:
- Block-level sparsity: split tokens into blocks, compute block-level summaries first, then select blocks, sacrificing fine-grained accuracy;
- Fixed-pattern sparsity: such as sliding window + global tokens, which does not depend on content but captures “strongly correlated long-range” tokens poorly.
When N grows from 1M to 10M, the O(N²) indexing overhead becomes the absolute dominant cost. This is the origin of the “98% of time spent in the indexer.”
Schematically, the selection stage of naive sparse attention can be written as:
# Naive approach: score in the original dimension, complexity O(N^2)scores = q @ k.transpose(-1, -2) # [B, H, N, N]idx = scores.topk(k, dim=-1).indices # select top-k for each queryout = gather_and_aggregate(v, idx) # aggregate only over selected keys
The bottleneck is the N×N matrix in the scores step.
3. The Core Idea of LSA: Move Selection into Latent Space
The key insight of LSA is: the selection process does not have to happen in the original token dimension; it can be done in a low-dimensional latent space.
The logic chain is as follows:
- Dimensionality reduction projection: project the query and key into a latent space of dimension d that is far smaller than head_dim (d is typically a few dozen dimensions);
- Low-dimensional scoring: compute similarity in the latent space, reducing complexity from O(N²·D) to O(N²·d), with a large drop in the constant factor;
- Candidate filtering: because low-dimensional scoring is highly correlated with the original scoring (the paper verifies this correlation experimentally), the recall of the top-k candidates is high enough;
- Precise aggregation: perform exact attention only over the selected k tokens in the original dimension.
The benefits are twofold:
- The indexing stage becomes cheaper: low-dimensional dot products are friendlier to memory bandwidth and cache, so the actual wall-clock time drops far more than the theoretical FLOPs ratio;
- Accuracy is controllable: because the final aggregation is still in the original dimension, the low dimension is used only to “nominate” and not to “compute,” avoiding the accuracy loss of block-level sparsity.
Pseudocode sketch:
# LSA: use low-dimensional latent space for selection, original dimension for aggregationq_low = proj_q_low(q) # [B, H, N, d], d << Dk_low = proj_k_low(k) # [B, H, N, d]scores_low = q_low @ k_low.transpose(-1, -2) # O(N^2 * d)idx = scores_low.topk(k, dim=-1).indices# Perform exact attention over top-k only in the original dimensionout = precise_attention(q, k, v, idx)
4. Why It Reaches 22x or Even 72x
The difference between 22.7x and 72.4x comes mainly from the proportion of global attention layers in the model architecture itself and from differences in the sparsity pattern. But the common factor is: when indexing accounts for more than 90% of total time, reducing the indexing cost by an order of magnitude yields an overall speedup close to that proportion.
We can build a simple Amdahl-style estimate:
- Let the indexing proportion be p = 0.98 and the aggregation proportion be 0.02;
- If LSA speeds up indexing by a factor of s, the overall speedup ≈ 1 / (p/s + (1-p));
- When s = 30, the overall result ≈ 1 / (0.98/30 + 0.02) ≈ 22.7.
This closely matches the numbers reported in the paper and shows that the source of the gain is clear and reproducible.
5. Four Things to Watch When Putting It into Practice
If you want to borrow the LSA idea in your own inference or training framework, the following points determine success or failure:
Initialization and training of the low-dimensional projection
If the latent projection matrix is randomly initialized, the recall of low-dimensional scoring will be very low. In practice, the projection needs to be trained jointly with the main attention, or warmed up in a distillation-like manner using the main attention’s Q/K.Adaptive k rather than a fixed k
A fixed k underfits in information-dense passages and wastes resources in sparse ones. You can dynamically adjust k based on the query’s entropy or score distribution, but you need to control the variance.Coordination with the KV cache
At 10M tokens, the KV cache itself is a major memory consumer. LSA only reduces indexing cost; it does not reduce cache capacity. It needs to be combined with general techniques such as quantization, tiered offloading to object storage, or high-speed caching.The difference between prefill and decode
The gains of LSA come mainly in prefill (processing a long sequence in one pass). In the decode stage, only one token is generated per step, so the indexing cost is naturally small and the benefit is limited; do not expect the same multiplier.
6. Relationship with Linear Attention and Hybrid Architectures
The current mainstream for long context is hybrid architectures: a few global attention layers handle “precise recall,” while the majority of linear/sparse layers handle “cheap coverage.” LSA does not replace this architecture; instead, it makes global attention layers affordable again.
This means designers can:
- increase the proportion of global layers to improve long-range dependency accuracy;
- or reduce global layers at the same accuracy to further cut costs.
Either way, LSA turns the “global attention layer” from a cost burden back into a tunable design variable.
7. Key Takeaways
- At 10M tokens, the bottleneck of sparse attention has shifted from “compute” to “selection”;
- Moving the selection process into a low-dimensional latent space is currently the most direct way to break through;
- The 22x-level speedup comes from structural optimization when the indexing proportion is extremely high, not from magic;
- Practical deployment requires handling projection training, adaptive k, KV cache, and prefill/decode differences together;
- When deploying ultra-long-context services on platforms such as Baidu AI Cloud, you can combine general container platforms, monitoring and alerting, and logging services to observe indexing latency and memory usage at a fine granularity, then decide whether to adopt a latent sparse approach.
