Sparse Attention at 10M Token Context: Why the Indexer Becomes the Bottleneck and How Latent Retrieval Delivers a 22x Prefill Speedup
As context windows scale from millions to tens of millions of tokens, the dominant cost in sparse attention shifts from computing attention to finding which tokens to attend to. This article explains why the indexer becomes a quadratic bottleneck at 10M tokens, how Latent Sparse Attention (LSA) moves scoring and top-k selection into a low-dimensional latent space to reduce that cost to near-linear, and what it takes to integrate the approach into an existing inference stack. It covers reported single-layer prefill speedups of roughly 22.7x and 72.4x, along with practical guidance on chunking, caching, hybrid layer placement, decoding reuse, and accuracy safeguards.
1. Long Context Is Shifting the Bottleneck from Compute to Search
Over the past two years, long-context capability has moved quickly from an experimental feature to a default specification. Million-token context is becoming a standard configuration for many model services, and 10M-token context is starting to enter engineering discussions. The core idea behind this shift is not mysterious: instead of having each query scan every historical token, a model selects only a few of the most relevant segments to participate in computation. This “attend to a small subset” sparsification approach has been validated repeatedly at the million-token scale. It keeps compute and memory overhead under control while largely preserving accuracy.
But as the context grows to 10M tokens, an overhead that once seemed negligible starts to spiral. Consider one global attention layer in a hybrid attention model. During prefill at 10M tokens, roughly 98% of the time is spent not on the attention computation itself, but on the indexer that decides which tokens to attend to. In other words, the real cost center has moved from computing attention to retrieving candidate tokens.
The nature of the problem has therefore changed. Sparse attention has already shown that attending to less is viable. What blocks ultra-long context is the act of finding that small subset in the first place, and its cost still grows quadratically with context length.
2. Why the Indexer Becomes the New Quadratic Bottleneck
Breaking the flow apart, a global attention layer during prefill involves roughly three steps:
- Scoring: compute a relevance score between each query and all historical tokens;
- Selection: pick the top-k candidates by score;
- Computation: perform a weighted sum of attention over the candidates only.
Sparsification optimizes only step 3, reducing its complexity from O(N²) to roughly O(N·k). But steps 1 and 2 still face a history of length N, so scoring and filtering remain on the order of O(N²). When N grows from 1M to 10M, this overhead increases by about 100x and becomes the dominant term.
Schematically, this “naive sparsity” can be written as:
# Pseudocode: prefill logic for naive sparse attentionscores = q @ keys.T # [N, N], quadratic scoring, blows up time and memoryidx = topk(scores, k) # each query selects k candidatesout = softmax(scores[idx]) @ values[idx]
The problem is obvious: the [N, N] score matrix cannot be fully materialized at 10M tokens. Even with chunked computation, the accumulated floating-point work is unacceptable.
3. Latent Sparse Attention: Moving the Search into a Low-Dimensional Space
A recent paper from a joint effort by a startup research lab and universities proposes Latent Sparse Attention (LSA): rather than retrieving in the original token space, first compress the query and key into a low-dimensional latent space, perform scoring and top-k selection there, then return to the original space for attention computation.
The core insight is that relevance ranking is far less sensitive to dimensionality than attention weighting itself. The representation used for ranking can be coarser and cheaper; precision is only truly required for the weighted sum of the candidates that are finally selected. The flow then becomes:
- Projection: use a low-rank mapping to compress the query and key to dimension d (d is much smaller than the head dimension);
- Latent-space scoring: compute similarity in the low-dimensional space, reducing the cost to O(N·d);
- Selection: take the top-k candidate indices;
- Exact computation: perform attention in the original space over the candidates only.
Since d is a constant and much smaller than N, step 2 drops from quadratic to near-linear, and the indexer is no longer the bottleneck. The paper reports that at 10M tokens, prefill for a single global attention layer is sped up by about 22.7x (one hybrid architecture model) and about 72.4x (another general-purpose large model), while maintaining accuracy close to the original model across multiple tasks. Note that this is the speedup for single-layer prefill; end-to-end gains will be reduced by factors such as the proportion of layer types, the decoding stage, and I/O.
4. Engineering Integration: Plugging LSA into an Existing Inference Stack
Reproducing these gains in a real system requires attention to a few engineering points.
- Chunking and streaming: perform low-dimensional projection and scoring in chunks to avoid materializing any N×N structure; candidate indices can be accumulated in a streaming fashion.
- Cache friendliness: the latent-space representation is small and suitable for residing in GPU memory or high-bandwidth cache, reducing repeated projection.
- Mixing with linear/local attention: in a hybrid architecture, usually only some layers are global attention, so LSA only needs to replace those layers while local and linear layers stay as they are.
- Decoding handoff: the candidate indices and latent representations produced during prefill should be reusable for incremental decoding, avoiding recomputation at every step.
- Accuracy safeguards: run sensitivity analysis on the dimension of the low-rank projection and the top-k value of k, and keep a higher-precision path for critical layers when necessary.
A simplified integration sketch:
# Pseudocode: Latent Sparse Attention (low-dimensional retrieval + exact computation in original space)q_l = q @ Pq # project down to d dimensionsk_l = k @ Pkscores = q_l @ k_l.T # near-linear scoring (executed in chunks)idx = topk(scores, k)out = attention(q, k[idx], v[idx]) # only candidates participate in exact computation
5. The Trade-off Between Accuracy and Speed
LSA-style methods are essentially trading controllable retrieval error for order-of-magnitude speed. The low-dimensional approximation in the retrieval stage may miss a few genuinely relevant tokens, but in practice the attention distribution is usually highly concentrated, and top-k already covers most of the weight, so the impact on the final output is limited. Engineering recommendations:
- Evaluate with task-level metrics (rather than single-layer error), covering scenarios such as long-document QA, retrieval, and code understanding;
- Run a grid search over k and d to find the smallest configuration within the “accuracy plateau”;
- Monitor long-tail queries to prevent a few samples from degrading significantly due to missing candidates.
6. Conclusion
As context moves from millions to tens of millions of tokens, the focus of optimization has shifted from computing less attention to cheaply finding the part that needs to be computed. By performing retrieval in a low-dimensional space and exact computation in the original space, Latent Sparse Attention reduces the indexer’s quadratic cost to near-linear, delivering more than a 20x speedup for single-layer prefill at 10M tokens and offering a reusable engineering path for ultra-long-context inference. For developers, the key is to get three things right at once: bottleneck identification, chunked streaming implementation, and accuracy safeguards, so that this kind of speedup can be realized in real workloads.
