Sparse Attention at 10M Token Context: Why the Indexer Is the Real Bottleneck and How Latent Space Fixes It

    As language models push context windows from 1M to 10M tokens, sparse attention alone no longer keeps prefill costs under control. This article breaks down the three cost stages of an attention call, explains why scoring and top-k selection still scale quadratically, and walks through Latent Sparse Attention (LSA), a two-level retrieval method that moves coarse scoring into a compressed latent space. It also covers why reported single-layer speedups vary across models, and how to apply the approach in production.

    1. The Cost Structure of Long Context Has Changed

    Over the past two years, mainstream large models have gradually turned million-token context into a default specification. Leading models first made 1M context the standard configuration of their official services, after which several vendors followed with lightweight models and began mixing sparse attention with linear attention in their architectures. These designs share the same assumption: instead of having every query scan the entire token history, each query selects a few of the most relevant segments to participate in the computation.

    That assumption has been validated repeatedly at the 1M scale. But as context keeps expanding toward 10 million tokens, an overhead that once looked negligible starts to spiral. Take a lightweight model with global attention layers as an example: during prefill at 10M tokens, roughly 98% of the time is not spent on the attention matrix multiplications, but on the indexer that decides which tokens to look at.

    The nature of the problem has therefore changed. Sparse attention has long proven that attending to a small subset is enough to preserve accuracy. What actually blocks extreme-length context is that the process of finding that small subset still grows quadratically with context length.

    2. Why the Bottleneck Lands on the Indexer

    A single attention call can be split into three cost stages:

    1. Scoring: evaluate the relevance of every historical key for each query;
    2. Selection: pick the top-k from the scoring results;
    3. Aggregation: compute a weighted sum over only the selected k positions.

    Sparsification compresses only stage 3. Stage 1 is still queries × keys, or O(n²), and the sorting or selection in stage 2 also operates at that quadratic scale. When n grows from 1M to 10M, n² grows 100×, while k is typically only a few hundred to a few thousand, so aggregation cost barely changes. Compute ends up consumed by “finding” rather than “calculating.”

    Schematically, the difference between a naive implementation and a latent-space implementation is where scoring happens:

    1. # Naive sparse attention: score in the original token space, cost O(n^2 * d)
    2. scores = q @ keys.T # [n, n]
    3. idx = topk(scores, k) # selection also happens at n^2 scale
    4. out = weighted_sum(values, idx) # only k positions, cheap
    5. # Latent-space sparse attention: compress the long sequence first, then locate within the short representation
    6. latent = compress(keys, m) # m << n, e.g. compress every 64~256 tokens into 1 slot
    7. coarse = q @ latent.T # [n, m], cost O(n * m * d)
    8. idx = refine(coarse, k) # fine-grained scoring only inside candidate blocks
    9. out = weighted_sum(values, idx)

    3. The Core Idea of Latent Sparse Attention

    A recent paper jointly released by a startup research team in London and a technical university in Zurich proposes Latent Sparse Attention (LSA). Its core is not “looking at less,” but “finding more cheaply”:

    • Compress into latent representations: aggregate the long context block by block into a small number of latent slots, forming a “catalog” far smaller than the original sequence;
    • Two-level localization: first perform coarse-grained scoring in latent space to shrink the candidate range from n to a few blocks; then do fine-grained reranking at original resolution only inside those candidate blocks to extract the top-k;
    • Reduced complexity: scoring drops from O(n²) to O(n·m) plus O(n·k), where m is the number of latent slots and m ≪ n, bringing the overall cost close to linear;
    • Preserved accuracy: because final aggregation still happens on the original tokens, compression only affects the retrieval path and does not directly lose information about the selected tokens.

    The paper reports that at 10M tokens, a lightweight model achieved a 22.7× prefill speedup on a single attention layer, while a model in the 27-billion-parameter class achieved 72.4× on the same layer type, with accuracy close to the original models across a series of tasks. It is worth stressing that these numbers are single-layer prefill results under specific models, specific layer types, and specific hardware conditions, and are not equivalent to end-to-end throughput gains.

    4. Why the Two Speedups Differ So Much

    The gap between 22.7× and 72.4× illustrates the boundaries of LSA’s benefit:

    • Native sparsity: models that are already highly sparse with a lightweight indexer have limited room for compression;
    • Share of global layers: only global attention layers benefit from LSA; local window layers and linear attention layers are almost unaffected;
    • Latent slot granularity m: the closer m is to n, the more stable the accuracy but the weaker the speedup, so it needs to be tuned per layer;
    • Implementation maturity: kernel fusion, block-level parallelism, and memory access layout often determine the measured speedup more than the algorithm itself.

    5. Engineering Recommendations

    To reuse this idea in your own extreme-length context pipeline, proceed in the following order:

    1. Measure before optimizing: profile prefill at the operator level to confirm the real share of the indexing and selection stages, and avoid optimizing the wrong target;
    2. Configure per layer: set different m and k for different layers, compressing aggressively in shallow layers and conservatively in deep ones;
    3. Align training and inference: the latent slot compression module needs to be trained jointly with the main model or adapted through post-training; inserting it directly at inference time usually degrades accuracy;
    4. Coordinate with the decoding side: the latent-space catalog built during prefill can be cached and reused, significantly reducing repeated indexing costs in multi-turn long conversations;
    5. Capacity and elasticity: extreme-length context inference is memory- and bandwidth-intensive, so container platforms can provide elastic scaling, object storage can hold long-session state, and logging services with monitoring alerts can help locate long-tail latency.

    6. Conclusion

    In the 10M-token regime, the next battle for sparse attention is not about “computing less” but about “finding more cheaply.” Moving retrieval into latent space and replacing global scoring with two-level localization is the key step to pushing quadratic complexity back toward linear. Meanwhile, elastic compute and observability capabilities from cloud platforms such as Baidu AI Cloud determine whether this optimization can be deployed reliably in production.