Sparse Attention at 10 Million Token Context: The Critical Path to a 22x Speedup

    As context windows scale from millions to tens of millions of tokens, sparse attention shifts the bottleneck from computing attention to finding which tokens matter. This article breaks down the hidden cost of index scoring, which still grows quadratically with context length, and explains how latent-space sparse attention projects queries and keys into a low-dimensional space to reduce complexity from O(T²·d) to O(T²·d'). It also covers reported speedups of over 20x (and up to 70x on some models) for single-layer prefill, plus practical engineering considerations around full-pipeline complexity, accuracy regression testing, prefill and decoding decoupling, and hybrid layer strategies.

    1. The New Cost Structure of Ultra-Long Contexts

    Over the past two years, long context has shifted from an optional feature to a default specification. Million-token context windows are now standard in many general-purpose LLM services, and ten-million-token exploration has entered engineering scope. The core technical choice behind this trend is consistent: instead of having every query scan all historical tokens, each query selects only a few of the most relevant keys for computation.

    This approach has been repeatedly validated at the million-token scale. But when the context grows another tenfold, an originally minor overhead starts to spiral. Take a global attention layer as an example: at ten million tokens, most of the prefill time is not spent on attention computation itself, but on the indexing step that decides which tokens to look at.

    The nature of the problem has therefore changed. Sparse attention has already proven that “looking at only a small subset” is enough to preserve accuracy. What truly blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.

    2. The Hidden Bill of Sparse Attention

    2.1 The Full-Attention Cost Baseline

    In standard full attention, every query computes relevance against all previous keys. With a context length of T, the prefill stage costs O(T²), and decoding each token costs O(T). Going from one million to ten million tokens increases prefill attention computation roughly one hundredfold.

    2.2 Division-of-Labor Design and Its Assumption

    Sparse attention works by division of labor: a lightweight indexer first selects the k most relevant keys for each query, then the actual attention computes only over those k keys, reducing attention overhead to O(Tk).

    This design rests on one assumption: the model truly needs only a few keys. Industry validation shows that at around a hundred thousand tokens, letting each query attend to only the few hundred keys it is genuinely most relevant to (under roughly one percent of all keys) still preserves over ninety percent of full-attention accuracy on long-context benchmarks.

    2.3 The Paradox

    To know which few hundred keys are most relevant, the indexer must first score every key. Common mitigations in the industry include lowering scoring precision, compressing dimensions, and aggregating multiple adjacent keys into a block before scoring. These reduce the constant factor but do not change the order of magnitude: index scoring itself remains O(T²), and as context grows it overtakes attention computation to become the primary bottleneck.

    3. Latent-Space Sparse Attention: Moving Indexing into a Low-Dimensional Space

    A recent study on sub-quadratic attention for ultra-long contexts proposes a new path: instead of performing full scoring in the original token space, project queries and keys into a low-dimensional latent space, perform similarity retrieval there, then map the retrieval results back to the original space for sparse attention.

    The key insight is that the discriminative information needed for relevance ranking is often concentrated in a subspace far smaller than the model’s hidden dimension. The indexing stage therefore does not need to read full representations; it computes only over compressed representations, reducing complexity from O(T²·d) to O(T²·d’), where d’ is far smaller than d. Combined with block-level aggregation and approximate retrieval, this can approach linear complexity.

    In public experiments, this method delivered over twentyfold prefill speedup for a single attention layer at ten million tokens, with speedups exceeding seventyfold on some models, while maintaining accuracy close to the original model on long-context benchmarks.

    4. Engineering Implementation Notes

    • Account for full-pipeline complexity. Beyond attention and indexing, consider KV cache memory usage and the extra parameters and memory-access overhead of projection matrices.
    • Accuracy regression testing is not optional. A drop in retrieval recall directly shows up as “lost middle information” in long-document tasks and requires tiered evaluation across multiple length levels.
    • Decouple optimization for prefill and decoding. The indexing cost characteristics differ between prefill and per-token decoding: the former can be batched, while the latter is more latency-sensitive.
    • Layered hybrid is a pragmatic choice. Using global sparse attention in only some layers and local windows or linear attention in the rest often achieves a better balance between gains and risk.

    5. Conclusion

    The core tension of ten-million-token context has shifted from “can we compute it” to “can we find it.” Moving the indexing step from the original representation space to a latent space, combined with block-level aggregation and approximate retrieval, is currently one of the most engineering-feasible directions for pushing complexity down to the sub-quadratic regime. For teams that need to control inference costs in scenarios such as ultra-long document understanding and repository-level code analysis, this is worth adding to the technical pre-research list.