Sparse Attention at 10M-Token Contexts: Latent-Space Retrieval for 22x Faster Prefill

    As context windows grow toward 10 million tokens, the main bottleneck in sparse attention shifts from the attention computation itself to the indexer that selects relevant tokens. This article explains why retrieval overhead can grow quadratically with context length, introduces a latent-space sparse attention approach that compresses history into a low-dimensional space for cheap coarse screening before running exact attention on selected tokens, and summarizes publicly reported results, including about 22x speedup on one attention layer of a mainstream sparse-attention model and over 70x on a dense-attention model. It also covers precision considerations, engineering constraints, and practical guidance for profiling bottlenecks, using two-stage retrieval architectures, budgeting context, and evaluating new architectures with standardized long-context benchmarks.

    Sparse Attention at 10M-Token Contexts: Latent-Space Retrieval for 22x Faster Prefill

    1. The Evolution of Ultra-Long Context: From “See Everything” to “Select What Matters”

    Over the past year, context windows in mainstream large models have expanded dramatically. Leading model providers first set 1 million tokens as the default specification for official services. More recently, next-generation flagship models from multiple vendors have begun supporting comparable context sizes and introducing hybrid designs that combine sparse attention with linear attention at the architecture level. These technical choices reflect a shared judgment: in autoregressive generation, having every query traverse the entire history is neither economical nor necessary. Instead, selecting a small number of the most relevant tokens from a massive context for attention computation can substantially reduce cost with almost no loss in accuracy.

    This judgment has already been validated at the million-token scale. Sparse attention reduces attention complexity from O(n²) to approximately O(n·k), where k is the number of selected tokens. This has made long-document understanding, codebase-level analysis, and multi-turn ultra-long conversations practical.

    2. The Bottleneck Shifts: When “Selection” Becomes the Main Cost

    However, as context size continues to grow toward 10 million tokens, a previously minor overhead begins to dominate: the indexer that decides which tokens should be attended to.

    Consider a global attention layer in a large model that uses sparse attention. During the prefill stage at 10 million tokens, roughly 98% of the time is not spent on the attention computation itself, but on the indexer retrieving relevant tokens for each query. The nature of the problem therefore changes fundamentally:

    • Sparse attention has already demonstrated that “looking at only a small subset” is enough to preserve accuracy.
    • The real obstacle for ultra-long context is that the computation required to “find that small subset” still grows quadratically with context length.

    The reason is that mainstream sparse methods typically compute relevance scores between a query and all historical keys, or their block-level summaries, in the original high-dimensional space. Even when blocking, clustering, or other approximation techniques are used, the total amount of score computation remains strongly correlated with sequence length. If the context grows by 10x, indexing overhead may grow by 100x, eventually consuming all the benefits brought by sparsification.

    3. Breaking the Bottleneck: Relevance Retrieval in Latent Space

    A recent research approach proposed a latent-space sparse attention method, which can be abstractly understood as Latent Sparse Attention. Its core idea is: instead of performing point-by-point retrieval over original token representations, first compress the historical context into a low-dimensional latent space, perform low-cost coarse relevance screening in that latent space, and then map back to the original space to run exact sparse attention.

    This can be broken down into three key stages:

    1. Compressed encoding: Through lightweight projection or aggregation operations, compress the high-dimensional key sequence into low-dimensional latent representations. This changes the retrieval cost per query from scaling linearly or quadratically with sequence length to operating only on a latent representation set much shorter than the original sequence.
    2. Latent-space coarse screening: The query is also mapped into the latent space and compared with the compressed representations to quickly locate candidate regions. Because both the dimensionality and number of latent representations are greatly reduced, this step no longer scales uncontrollably with the original context length.
    3. Exact computation in the original space: Standard attention computation is performed only on candidate tokens selected during coarse screening, keeping output accuracy largely consistent with the original model.

    The process can be described with illustrative pseudocode:

    1. # 1. Compress historical context into latent space
    2. latent_keys = compress(keys) # length n -> m (m << n)
    3. # 2. Perform low-cost coarse screening in latent space
    4. scores = q_latent @ latent_keys.T # complexity depends only on m
    5. top_regions = topk(scores, k) # select candidate regions
    6. # 3. Map back to original space and run exact attention only on candidate tokens
    7. selected = gather(keys, values, top_regions)
    8. output = attention(query, selected.keys, selected.values)

    This two-stage structure of “coarse screening + exact computation” is analogous to “recall + ranking” in search engines: use inexpensive approximate computation to narrow the candidate set, then concentrate expensive computation on a small number of high-value objects.

    4. Benefits and Trade-offs: An Order-of-Magnitude Speedup with Basically No Accuracy Loss

    According to publicly reported experimental results, in a 10-million-token prefill scenario, this method speeds up a single attention layer of a mainstream sparse-attention model by about 22x, and speeds up a dense-attention model by more than 70x. At the same time, it maintains accuracy comparable to the original model on a range of tasks, including long-context retrieval, reasoning, and summarization.

    It is important to note that these benefits come with preconditions:

    • The context must be long enough: Below the million-token scale, indexing overhead accounts for a limited share, so the speedup from latent-space methods is not significant.
    • Compression must not lose critical information: Latent representations must retain sufficient ability to discriminate relevance. Otherwise, coarse screening may miss truly important tokens, so recall quality needs to be ensured through training or calibration.
    • Memory access patterns must be friendly: Beyond reducing theoretical computation, operator fusion, blocked loading, and other engineering optimizations are needed to translate FLOPs advantages into actual end-to-end latency improvements.

    5. Engineering Implications for Developers

    For developers building long-context applications, this technical evolution offers several actionable lessons:

    First, quantify the bottleneck before optimizing. In ultra-long context scenarios, do not assume that attention matrix computation is the main time consumer. Use profiling tools to measure the share of time spent on indexing/retrieval versus attention computation, avoiding ineffective optimization in the wrong direction.

    Second, make good use of hierarchical and two-stage retrieval architectures. Whether inside the attention mechanism or in external retrieval-augmented generation (RAG) pipelines, “cheap recall + expensive reranking” is a proven paradigm. In cloud deployments, you can combine object storage to store long-document chunks, vector retrieval services for recall, and large models for close reading and reasoning.

    Third, pay attention to the nonlinear relationship between context length and cost. From 1 million to 10 million tokens, cost growth is often not 10x but a higher order of magnitude. On the business side, establish a context budget mechanism: summarize and compress historical conversations, structure long documents into chunks, and send only truly necessary content to the model.

    Fourth, maintain a cadence for evaluating new architectures. Sparse attention, linear attention, latent-space retrieval, and other approaches are still evolving rapidly. Build your own regression evaluation set using standardized long-context benchmark tasks, and use data rather than marketing performance numbers when upgrading models or inference frameworks.

    6. Conclusion

    Competition in ultra-long context has shifted from “can it fit” to “can it afford the computation.” Sparse attention solves the problem of “looking at too much,” while latent-space sparse retrieval further solves the problem of “finding relevant tokens is too expensive.” When indexing overhead no longer expands quadratically with length, real-time processing at the 10-million-token scale becomes truly engineering-feasible. For developers, understanding the general “recall—exact computation” paradigm is more valuable in the long run than chasing any single solution.