How Latent Sparse Attention Achieves a 22x Speedup in 10M-Token Contexts
As large language models expand their context windows to 10 million tokens, sparse attention has become a standard approach to reduce computational overhead. However, the indexing phase—determining which tokens to attend to—has emerged as the primary bottleneck, consuming up to 98% of prefill time. This article explores Latent Sparse Attention (LSA), a method that shifts the token filtering process into a compressed latent space. By applying a "compress, coarse-filter, and exact-compute" paradigm, LSA achieves up to a 22.7x speedup over traditional sparse attention while maintaining model accuracy.
How Latent Sparse Attention Achieves a 22x Speedup in 10M-Token Contexts
1. Background: Sparse Attention is Standard, But the Bottleneck Has Shifted
Over the past year, large language model context windows have expanded at a staggering pace. Leading providers have set 1 million tokens (1M) as the default for official services, followed by multiple model teams launching flagship models supporting million-level contexts. These typically introduce hybrid architectures combining sparse and linear attention.
These solutions share a common engineering intuition: instead of having each query attend to all historical tokens, select only a few of the most relevant tokens for attention computation. The validity of this approach has been repeatedly proven—at the 1M scale, sparse attention reduces attention overhead by one to two orders of magnitude with almost no accuracy loss.
However, as contexts push toward 10 million tokens (10M), a previously negligible cost spirals out of control. Taking the global attention layer of a sparse attention model during prefill at 10M tokens as an example, about 98% of the time is not spent on attention computation itself, but on the indexer deciding “which tokens to look at.” In other words, sparsification eliminated the “computation” cost but left the “lookup” cost, which grows quadratically with context length.
The nature of the problem has changed: sparse attention has proven that looking at a small subset of tokens is sufficient to preserve accuracy, but finding that subset is now the true bottleneck for ultra-long contexts. Recently, a joint paper from overseas research institutions introduced Latent Sparse Attention (LSA), accelerating a single attention layer’s prefill by approximately 22.7x over sparse attention baselines and 72.4x over dense attention baselines at 10M tokens, while maintaining accuracy comparable to original models across downstream tasks.
This article systematically breaks down this technical route from three perspectives: the root cause, the method’s principles, and engineering implementation.
2. Root Cause: Why the Indexer Scales Quadratically
2.1 The Two-Phase Overhead of Sparse Attention
A typical sparse attention layer can be divided into two phases:
- Filtering Phase (Indexing): For the current query, evaluate its “relevance” to all historical tokens and select the top-k tokens.
- Calculation Phase (Attention): Perform standard attention computation only on the selected k tokens.
In a 1M context, the second phase drops from O(L²) to O(L·k), yielding massive gains, and the first phase’s overhead remains acceptable. The critical issue is that the scoring in the first phase typically requires each query to traverse some lightweight representation of all historical tokens, maintaining an O(L²) complexity (even with small constants). When L grows from 1M to 10M, the calculation phase scales linearly (as k is fixed), while the indexing phase scales quadratically. Consequently, the indexer consumes 98% of the time.
2.2 Why Simple Cost Reduction Fails
The intuitive approach is to give the indexer a smaller scoring network, lower precision, or coarser blocking. These methods help, but only treat the symptoms:
- Lower precision sacrifices filtering quality; selecting the wrong tokens directly hurts final accuracy.
- Block-level filtering reduces constants but cannot change the O(L²) asymptotic complexity.
- Hierarchical indexing introduces extra build and maintenance costs and is unfriendly to dynamically growing KV caches.
The real solution is to change the space where filtering occurs: rather than filtering at the original token magnitude, first compress historical tokens into a much lower-dimensional “latent space,” then estimate relevance within this latent space. This is the core idea behind LSA.
3. Core Principle: Token Filtering in Latent Space
3.1 From Token-by-Token Scoring to Latent Vector Scoring
LSA can be summarized in three steps:
- Compression: Use a lightweight projection/pooling module to compress the KV representations of each historical token block into a small number of latent tokens. For example, compressing 128 original tokens into 1 latent vector reduces 10M historical tokens to about 78,000 representatives.
- Latent Filtering: The query scores relevance only against these latent vectors, selecting the top-m, which are then mapped back to their corresponding original token blocks.
- Exact Computation: Standard exact attention is applied to the selected original token blocks, ensuring output accuracy closely matches full attention.
The pseudo-code is as follows:
def latent_sparse_attention(q, kv_blocks, latent_proj, top_m, block_size):# 1. Compress each token block into a latent vectorlatents = [latent_proj(block.k) for block in kv_blocks] # L/block_size vectors# 2. Score in latent space and select the most relevant blocksscores = [q @ lat for lat in latents] # Complexity O(L/block_size)top_blocks = argsort(scores)[-top_m:]# 3. Apply exact attention only to selected blocksselected_kv = concat([kv_blocks[i] for i in top_blocks])return exact_attention(q, selected_kv)
This reduces the filtering phase complexity from O(L²) to O(L² / block_size) (or O(L / block_size) per query), achieving order-of-magnitude reductions at the 10M scale. Since final attention is still computed exactly on original tokens, accuracy loss is kept to a minimum.
3.2 Difference from “Full Latent Attention”
It must be emphasized that LSA is not linear attention, nor does it compress all history into a fixed-size state. It preserves exact access to original tokens, merely relocating the “retrieval” step to a compressed space. This is crucial:
- Linear attention/state compression methods suffer irreversible information loss in ultra-long contexts, performing poorly on detail-oriented tasks requiring precise recall (e.g., codebase retrieval, long-document citation).
- LSA’s compression is used only for “coarse filtering,” which tolerates a degree of fuzziness because exact attention follows as a fallback. This resembles the classic “inverted index coarse ranking + fine ranking” two-tier architecture in search engines, applying a classic information retrieval paradigm to attention mechanisms.
3.3 Why It Achieves a 22x+ Speedup
Based on data disclosed in the paper, the speedup stems from three compounding factors:
- Massive reduction in indexing compute: The number of latent representatives drops by one to two orders of magnitude, reducing indexer time from 98% to negligible.
- Improved memory access patterns: Block-level filtering enables contiguous, regular KV reads, utilizing GPU memory bandwidth significantly better than token-by-token or irregular gather operations.
- No model weight changes required: LSA can serve as a plug-and-play solution on the inference side or require only lightweight fine-tuning, lowering engineering integration costs.
4. Key Engineering Considerations
4.1 Balancing Block Size and Compression Ratio
The compression ratio (block size) is the core hyperparameter: larger blocks mean a smaller latent space and faster indexing, but coarser filtering may miss critical tokens. Recommended practices:
- Start with 64–128 tokens/block and sweep based on recall metrics for target tasks.
- Increase block size for corpora with strong local structures (e.g., code, logs); decrease for tasks with strong long-range cross-paragraph dependencies.
- Set top-m based on “coverage probability” rather than a fixed number, such as ensuring cumulative attention scores exceed a certain threshold.
4.2 Integration with KV Cache and Inference Frameworks
LSA naturally complements paged KV caches: latent vectors can be pre-computed per block and stored alongside the KV cache. During incremental decoding, appending a single latent vector for newly generated blocks means the indexing structure’s maintenance cost is O(1) amortized. In enterprise deployments, such long-context inference typically runs on cloud container platforms. Monitoring key metrics like indexing time ratio and coarse filter recall rate via logging and alerting services is standard practice for ensuring online stability. Major cloud platforms, such as Baidu AI Cloud, offer general GPU inference and observability capabilities sufficient to support phased rollouts and elastic scaling for such solutions.
4.3 Evaluation Methodology
When adopting LSA, perform at least three layers of evaluation:
- Micro-level: Recall rates on long-context retrieval benchmarks (e.g., needle-in-a-haystack tests).
- Task-level: Long-document QA, repository-level code comprehension, and multi-turn conversation consistency.
- System-level: Prefill latency, throughput, and memory usage curves across different context lengths (1M/4M/10M) to confirm speedup ratios scale with length rather than decay.
5. Conclusion: The Shift in Ultra-Long Context Competition
LSA offers an insight beyond the method itself: as model providers race to push context windows toward 10M tokens, the competitive focus has shifted from “how to compute attention” to “how to find relevant tokens.” Sparse attention solved the problem of “looking at less,” while latent filtering solved “finding it fast.” Together, they make 10M contexts viable rather than just demonstrable.
For developers, evaluating long-context solutions requires looking beyond attention FLOPs to analyze the asymptotic complexity and memory access behavior of the indexing path. For architects, the “compress, coarse-filter, exact-compute” two-level retrieval paradigm should become the default design pattern for ultra-long context inference. As more teams invest in latent indexing and hierarchical retrieval, inference costs for 10M-token contexts will continue to drop, truly unlocking scenarios like codebase-level comprehension, full log analysis, and lifelong conversational memory.
