Sparse Attention at 10M Token Context: Why the Indexer Becomes the Bottleneck and How Latent Sparse Attention Delivers Up to 22x Speedup

    As context windows grow from 1M to 10M tokens, the cost structure of long-context inference shifts: sparse attention reduces the attention computation itself to O(Tk), but the indexer that decides which tokens to attend to still scales quadratically and can consume up to 98% of a single layer's prefill time. This article breaks down the causes of that hidden cost, explains the core idea of Latent Sparse Attention, which moves relevance scoring into a low-dimensional latent space to make indexing sub-quadratic, and provides a framework for analyzing accuracy retention, engineering implementation, and evaluation so developers can make informed architecture choices for ultra-long context scenarios.

    When the context length moves from 1M toward 10M tokens, the cost structure of long-context inference changes fundamentally. The sparse attention widely adopted across the industry compresses the actual attention computation to O(Tk), yet the indexer that “decides which tokens to look at” still grows quadratically with length, and during the prefill stage at 10M tokens it can account for 98% of the time in a single layer. This article takes a neutral view of the causes behind this “invisible bill” and introduces the basic idea of Latent Sparse Attention: moving relevance scoring into a low-dimensional latent space, which reduces indexing complexity to sub-quadratic. It also lays out an analysis framework covering accuracy retention, engineering implementation, and performance evaluation, to help developers make sound architecture choices in ultra-long context scenarios.

    1. Background: When Contexts Get Longer, the Bill Moves

    Over the past two years, mainstream large models have gradually turned 1M context into a default specification, and some newer models have introduced hybrid architectures combining sparse attention with linear attention. Their shared choice is to stop having each query traverse all historical tokens, and instead select only a few of the most relevant keys to participate in the computation.

    This route has been repeatedly validated at the 1M scale. But as the context pushes on to 10 million tokens, an originally unremarkable overhead starts to spiral out of control: when running prefill in a global attention layer, most of the time is not spent on attention itself, but on the indexing step of “which tokens should be looked at.”

    The nature of the problem therefore changes. Sparse attention has already proven that “looking at only a small part” is enough to preserve accuracy; what really blocks ultra-long context is that “finding that small part” remains expensive.

    2. Cost Breakdown: Attention Is Not Expensive, Indexing Is

    In standard full attention, each query computes relevance against all preceding keys, which costs O(T^2) for prefill and O(T) per decoded token. As the context grows from 1M to 10M, the attention computation increases roughly 100x.

    Sparse attention divides the work as follows: a lightweight indexer first selects the k most relevant keys for each query, then the real attention computes only over those k keys, pushing the attention overhead down to O(Tk).

    The premise for this idea to hold is that the model really does need only a few keys. Existing validation shows that at 128k tokens, letting each query look at only the 512 truly most relevant keys (about 0.8% of all keys) still retains roughly 98% of full-attention accuracy on long-context benchmarks.

    But a paradox follows: for the indexer to know which 512 keys are the most relevant, it must first score every key. Common industry approaches include lowering scoring precision, compressing dimensions, and merging multiple keys into a single block. These techniques ease the constant factor, but they do not change the order of magnitude of index scoring growing quadratically with T.

    An illustrative complexity comparison:

    1. Full attention: prefill O(T^2) decode O(T)
    2. Sparse attention: prefill O(T*k) + index O(T^2 * c) decode O(T)
    3. Latent sparse attention: prefill O(T*k) + index sub-quadratic decode near O(T)
    4. where c is the constant factor from lower-precision/lower-dimensional scoring, and k is the number of keys selected per query

    3. The Core Idea of Latent Sparse Attention

    The key to Latent Sparse Attention is moving “relevance scoring” from the original token space into a low-dimensional latent space: keys and queries are first projected into compact latent representations, then similarity computation and top-k selection are completed in the latent space, and finally sparse attention is performed back in the original space.

    This brings three benefits:

    • The scoring dimension drops significantly, making each similarity computation cheaper;
    • Latent representations can be reused and cached, avoiding repeated scans of all original keys for every query;
    • The selection process is decoupled from the attention computation, making it easier to implement with more efficient operators and parallel strategies.

    The logic is this: since only a few keys are ultimately needed, the “search” phase does not have to perform exhaustive exact comparison in the original high-dimensional space; instead, the search should be carried out in a space with higher information density and a more controllable size.

    4. Why Accuracy Can Be Preserved

    Accuracy retention depends on three design points:

    1. The latent space must retain sufficient discriminative power. Too low a projection dimension loses distinctiveness and causes top-k to select the wrong keys; a trade-off is needed between compression ratio and discriminative power.
    2. Selection must be coordinated with training. If the indexer is jointly trained with the main model or aligned through distillation, the selected keys are closer to the set of “truly most relevant” ones.
    3. Layered and block-level strategies act as a fallback. Using latent-space indexing for global layers while keeping window attention for local layers can balance long-range dependencies and local detail.

    In other words, the risk of sparsification lies not in “looking at less,” but in “selecting with bias.” The latent-space approach puts the optimization focus on reducing both selection bias and selection cost.

    5. Results and Evaluation Dimensions

    In a 10M token prefill scenario, Latent Sparse Attention achieves about 22.7x speedup on a single attention layer compared with existing sparse approaches, and the speedup can reach tens of times on another type of model architecture, while maintaining accuracy close to the original model across a range of long-context tasks.

    When evaluating ultra-long context solutions, it is worth focusing on the following dimensions:

    • Effective context length and retrieval accuracy: score retention on long-context benchmarks;
    • Prefill latency and throughput: especially the share taken by the indexing stage;
    • Per-token cost in the decoding stage;
    • GPU memory usage and caching strategy;
    • Hybrid compatibility with linear attention and window attention.

    6. Engineering Recommendations

    • Profile before optimizing: measure the time share of indexing versus attention in prefill to confirm where the bottleneck is;
    • Design in layers: use latent sparse indexing for global layers and window attention for local layers;
    • Cache latent representations: cache reusable projection results to reduce repeated computation;
    • Control k and block size: too small a k hurts accuracy, too large weakens the speedup;
    • Gradual rollout and fallback: keep a full-attention fallback path and switch dynamically by task and length;
    • Monitoring and alerting: set up monitoring and alerts for latency, memory, and accuracy metrics to catch degradation early.

    7. Conclusion

    As contexts enter the era of tens of millions of tokens, the bottleneck of long-context inference has shifted from “computing slowly” to “searching slowly.” By moving indexing into a low-dimensional latent space, Latent Sparse Attention pushes indexing complexity down to sub-quadratic, providing a practical acceleration path for ultra-long context. For developers, the key is not to blindly pursue a larger window, but to understand the cost structure, choose the right sparsification strategy, and use observable engineering practices to safeguard accuracy and stability.