10M Token Long Context: Latent Sparse Attention Achieves 22x Speedup

    As context windows scale from 1 million to 10 million tokens, the primary bottleneck for sparse attention shifts from the cost of computation to the cost of finding relevant tokens. This article analyzes the indexer paradox in ultra-long contexts, details the design logic and two-stage filtering mechanism of latent sparse attention, and outlines engineering best practices to achieve a 22x speedup while maintaining accuracy.

    10M Token Long Context: Latent Sparse Attention Achieves 22x Speedup

    When context windows expand from 1 million to 10 million tokens, the core contradiction facing sparse attention is no longer “whether to be sparse,” but “how to find the small subset of tokens to look at more quickly.” This article dissects the design logic, cost structure, and engineering implementation of latent sparse attention to address this bottleneck.

    1. From 1M to 10M: Why Sparse Attention Still Stalls

    The cost structure of standard full attention is clear: at a context length of T, each query in the prefill phase must calculate relevance against all keys, meaning computation scales quadratically with T. In the decode phase, generating each token requires interacting with historical tokens, scaling linearly with T. Expanding the context from 1 million to 10 million tokens theoretically increases prefill attention computation by about 100 times.

    The basic division of labor in sparse attention is: first, use a lightweight indexer to select k most relevant keys for each query, then compute exact attention only on these k keys. This compresses the exact attention overhead to O(Tk), seemingly bypassing full T² computation.

    The problem, however, is that the indexer must first answer “which keys are relevant.” If the indexer needs to traverse all keys and score them for each query, it still carries the shadow of quadratic growth. Reducing scoring precision, lowering projection dimensions, or compressing multiple keys into a block can reduce constant overhead, but it cannot change the fundamental “query quantity × key quantity” scale. When T reaches the tens of millions, the indexer can transform from a “lightweight auxiliary module” to the primary time consumer in prefill.

    In single-layer prefill at the 10-million-token level, it is commonly observed that the indexing phase accounts for the vast majority of time consumption, sometimes reaching 90%. The time actually spent on exact attention over candidate keys is relatively small. In other words, sparse attention saves the cost of “looking” but does not fully save the cost of “finding.”

    2. The Indexer Paradox: Higher Sparsity Requires Better Recall

    The premise of sparse attention is that the model indeed only needs a small number of critical keys. Public experiments typically show that in long-context tasks, attending to only a tiny fraction of the most relevant tokens per query can still retain accuracy close to full attention. But this conclusion carries an implicit condition: the selected few tokens must be highly accurate.

    This forms the indexer paradox: to look at less, you must first find accurately; to find accurately, you must first evaluate relevance across a large number of keys. Schemes like block sparsity, low-dimensional projection, and key compression essentially lower the unit price of “evaluation,” but do not eliminate the problem that the “evaluation scope” still expands with the context.

    Therefore, what ultra-long contexts truly need is not another smaller indexer, but a structural complexity reduction in the indexing phase: converting full high-dimensional query-key interactions into hierarchical candidate filtering in a low-dimensional latent space, allowing coarse and fine screening to divide the labor, preventing every query from performing high-dimensional scoring on all keys.

    3. Core Approach of Latent Sparse Attention

    The approach of latent sparse attention can be summarized in three layers:

    1. Low-dimensional Latent Indexing: Project keys into a lower-dimensional latent space and build a reusable index structure at the block level. Queries are also projected into the same latent space to perform coarse screening via low-dimensional scoring. This significantly reduces the cost of a single relevance evaluation, and the index can be cached and incrementally updated.
    2. Block-level Coarse Screening and Intra-block Fine Screening: First recall candidate regions at the block level, then perform token-level fine screening within the candidate blocks to ultimately obtain a small number of candidate keys. Coarse screening avoids full high-dimensional interactions token by token, while fine screening ensures candidate accuracy.
    3. Exact Attention Only on the Candidate Set: The final attention computation still uses the original high-dimensional representations, applying exact softmax attention only to the recalled k keys. This keeps the output semantics as close to the original model as possible while concentrating the main computation on the few candidates.

    The schematic pseudo-code is as follows, focusing on illustrating the two-stage filtering process rather than specific implementation parameters:

    1. def two_stage_sparse_attention(Q, K, V, k, block_size):
    2. # 1. Build low-dimensional block-level index, cacheable and reusable
    3. K_block_latent = project_blocks(K, block_size)
    4. Q_latent = project_query(Q)
    5. # 2. Block-level coarse screening: low-dimensional scoring, avoiding full high-dimensional interactions
    6. block_scores = coarse_score(Q_latent, K_block_latent)
    7. candidate_blocks = topk_blocks(block_scores, n_blocks)
    8. # 3. Intra-block fine screening: get a small number of tokens from candidate blocks
    9. token_scores = fine_score(Q_latent, K[candidate_blocks])
    10. idx = topk_tokens(token_scores, k)
    11. # 4. Exact attention applied only to candidate tokens
    12. return exact_attention(Q, K[idx], V[idx])

    The key to this process is not any specific function name, but the engineering decomposition of “full high-dimensional scoring” into “low-dimensional coarse screening + local fine screening + exact attention.” Coarse screening controls the scale, fine screening ensures recall quality, and the exact phase guarantees output accuracy.

    4. Performance Gains and Accuracy Boundaries

    In public experimental settings, a single-layer prefill at the 10-million-token level can achieve a speedup of about 22x compared to conventional sparse schemes. For different model scales, the speedup varies depending on the indexer proportion, block size, and candidate count. The significance of this magnitude is: when the indexing phase becomes the primary bottleneck, optimizing the indexing path is more effective than continuing to optimize exact attention.

    However, this speedup is not an unconditional gain. The accuracy of latent sparse attention depends on whether the candidate recall covers critical tokens. If the low-dimensional projection loses important relevance information, or if block-level coarse screening misses long-range critical blocks, even the most accurate exact attention cannot compensate. Therefore, evaluation should not only look at average perplexity but also at tasks like long-context retrieval, multi-hop reasoning, long-distance dependency, and exact citation.

    5. Engineering Implementation Essentials

    1. Candidate Recall Rate Monitoring
    Regularly sample and compare the overlap rate between sparse candidates and full attention’s top-k, and aggregate statistics by task type. Retrieval tasks are more sensitive to recall, while local language modeling might be more forgiving.

    2. Trade-off Between Block Size and k
    A larger block makes coarse screening cheaper, but increases the fine screening scope within the block; a larger k stabilizes accuracy, but increases exact attention cost. Layer-specific configurations should be made based on layer count, head count, and context distribution, rather than using one global set of parameters.

    3. Index Caching and Incremental Updates
    The prefill phase can reuse the block-level low-dimensional index, while the decode phase only needs to incrementally update the index for new tokens. For multi-turn conversations and long document Q&A, index caching can significantly reduce the cost of redundant construction.

    4. Numerical Stability and Accuracy Fallback
    Low-dimensional scoring requires proper normalization and scale control to prevent score drift under long contexts. When recall confidence is low or the candidate distribution is too dispersed, the candidate set should be expanded or fall back to a denser attention path, ensuring correctness is prioritized.

    5. Mixing with Local/Linear Attention
    Local windows or linear attention are suitable for handling neighbor tokens and streaming context, while latent sparse attention is suitable for global critical tokens. A hybrid architecture should avoid having every layer bear the high cost of global indexing; placing global sparse layers only at key layers is sufficient.

    6. Conclusion

    The bottleneck of 10-million-token context is shifting from “attention computation is too expensive” to “candidate indexing is too expensive.” The value of latent sparse attention lies in migrating the indexing phase from full high-dimensional scoring to a low-dimensional, block-level, reusable candidate filtering path, allowing sparse attention to remain viable under ultra-long contexts. For engineering teams, the real focus should not just be the 22x number, but the indexing time proportion, candidate recall rate, trade-offs between k and block size, and accuracy fallback mechanisms. Only by integrating “finding accurately” and “computing economically” into the design simultaneously can a 10-million-level context possess a practically deployable cost foundation.