Sparse Attention at 10 Million Tokens: The Key to a 22x Speedup

    As context windows scale from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to finding which tokens matter. This article breaks down the quadratic cost structure of long-context attention, explains how Latent Sparse Attention moves retrieval into a low-dimensional latent space to achieve sub-quadratic complexity, and why decoupling retrieval from computation is the critical design choice. It also provides a practical engineering checklist for evaluating candidate-set recall, tuning chunk size and latent dimensions, and monitoring indexer overhead in your own system.

    Introduction: The Context Length Race Enters the “10 Million Token” Phase

    Over the past two years, long context has moved quickly from an experimental feature to a baseline specification. Million-token context is becoming a default configuration for many model services, and architectures that mix sparse attention with linear attention are being adopted by more models. These approaches share the same premise: a query vector does not need to scan the entire token history; it only needs to select a small set of the most relevant tokens for computation.

    This premise has been validated repeatedly at the million-token scale. But as context pushes toward 10 million tokens, an initially unremarkable overhead starts to spiral out of control. Take a global attention layer as an example: at 10 million tokens, roughly 98% of prefill time is spent not on the 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 actually blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.

    1. Revisiting the Attention Cost Structure: Where the Quadratic Term Goes

    In standard full attention, every query computes relevance against all previous keys. With a context length of T, prefill costs O(T²), and decoding each token costs O(T). Going from 1 million to 10 million tokens increases attention computation by roughly 100x in theory.

    Sparse attention divides the work like this: a lightweight indexer first selects the k most relevant keys for each query, and the actual attention is computed only over those k keys, reducing the core attention cost to O(Tk).

    This approach rests on one assumption: the model really does need only a few keys. Relevant validation shows that at 128k tokens, letting each query attend to only its 512 most relevant keys (about 0.8% of all keys) still preserves roughly 98% of full-attention accuracy on long-context benchmarks.

    But there is a paradox here: for the indexer to know which 512 keys are most relevant, it must first score every key. Common industry techniques include lowering scoring precision, compressing dimensions, and aggregating multiple keys into a summary vector. These reduce the constant factor but do not change the fundamental fact that the number of scoring operations grows with T. As a result, the indexer itself becomes O(T²) in scale and turns into the new bottleneck.

    Schematically, the cost of a single layer can be split into two parts:

    1. total_cost ≈ indexer_cost + attention_cost
    2. ≈ O(T² · d_index) + O(T · k · d_head)

    When T reaches the tens of millions, the first term quickly overwhelms the second. This is the source of the “hidden bill.”

    2. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Space

    A recent paper targeting sub-quadratic attention for ultra-long context proposed the idea of Latent Sparse Attention, developed jointly by an overseas startup and a European technical university. Its core is not to further optimize the scoring function, but to change the space in which retrieval happens.

    The key points can be summarized in three layers:

    1. Keys and queries are projected into a low-dimensional latent space, and the indexer computes similarity only within that space, at a dimension significantly lower than the original head dimension;
    2. Representations in the latent space can be cached and reused, avoiding repeated reads of all original keys for every query;
    3. The actual attention is still performed on the original high-precision representations. Retrieval and computation are decoupled, so accuracy loss is confined to the candidate-set selection step.

    Because scoring happens in a low-dimensional space, and candidate-set generation can leverage chunking and approximate retrieval structures, the complexity of the indexing stage is reduced to near-linear, bringing the overall complexity down from quadratic to sub-quadratic. Public results show that at the 10 million token scale, a single attention layer’s prefill can achieve a speedup of tens of times, with the speedup ratio varying across model sizes, while maintaining accuracy close to the original model on a range of long-context tasks.

    3. Why “Decoupling Retrieval from Computation” Is the Key Design

    Traditional sparse attention binds two things together: it uses the same representation both to judge relevance and to perform weighted aggregation. This means any precision or dimension reduction done to accelerate retrieval directly contaminates the attention output.

    After decoupling, the system gains three engineering benefits:

    • Controllable accuracy: the candidate set may be selected incorrectly, but once selected, the aggregation is still performed at full precision;
    • Layered resources: the latent-space index is suitable for placement in GPU memory or system memory, while the original keys and values sit in a tier that is read on demand;
    • Replaceable structure: the indexer can be upgraded to a learned retriever without changing the attention kernel.

    4. Engineering Implementation Checklist

    To validate a similar approach in your own system, it is recommended to proceed in the following order:

    1. First evaluate candidate-set recall rather than only end-to-end accuracy, and establish the relationship curve between k and recall;
    2. Jointly tune chunk size and latent dimension; too large a chunk raises indexing cost, while too small a chunk loses recall;
    3. Optimize prefill and decode separately; for the decode stage, focus on cache layout and bandwidth;
    4. Build a long-context regression evaluation set covering retrieval-type, aggregation-type, and multi-hop tasks;
    5. Monitor the proportion of time spent in the indexing stage; once it exceeds one-third of total latency, it should be treated as an architecture-level bottleneck rather than an implementation issue.

    Conclusion

    The next round of optimization for ultra-long context is not about “computing more cheaply,” but about “finding more accurately and more cheaply.” Moving retrieval into a low-dimensional latent space and fully decoupling indexing from aggregation is currently the most representative path for pulling complexity back from quadratic to sub-quadratic. For developers, quantifying indexer overhead first and then discussing attention optimization is the right order in the era of 10 million tokens.