Latent Sparse Attention: 22.7x Speedup for 10M-Token Contexts
This article explains why sparse attention at the 10M-token scale is increasingly limited by the indexer rather than the attention computation itself, and introduces Latent Sparse Attention (LSA), a dual-layer indexing method that performs coarse filtering in a low-dimensional latent space before running fine-grained attention on a much smaller candidate subset. It covers the architecture, training strategy, reported speedups of 22.7x and up to 72.4x, deployment considerations, key parameters, and typical long-context use cases.
From “See Everything” to “See What Matters”: The Inevitable Evolution of Sparse Attention
Context window expansion has long been a central challenge in large language model development. When a model must process massive amounts of historical information, conventional full attention grows quadratically with sequence length: every doubling of context length multiplies compute cost by four. At million-token and even 10M-token context lengths, this “brute-force full scan” approach becomes impractical in engineering terms.
The industry has increasingly converged on a shared solution: instead of having every query scan all historical tokens, use a mechanism to select a small number of the most relevant key tokens for attention computation. This sparse attention approach has been repeatedly validated at million-token scale, preserving model accuracy while substantially reducing computation.
However, as context length moves from the million-token range toward 10M tokens, a previously overlooked hidden cost begins to surface: the indexing process that decides “which tokens to look at” is consuming most of the compute budget.
The Overlooked Bottleneck: Runaway Indexer Cost
Consider one global attention layer in a mainstream large model. During the prefill stage at 10M tokens, a counterintuitive statistic appears: 98% of runtime is not spent on attention computation itself, but on the indexer.
This finding changes the nature of the problem. Sparse attention has already shown that “looking at only a small subset of tokens” is enough to preserve accuracy. What actually blocks ultra-long-context applications is the preceding step: how to quickly find that small subset. In a naive sparse attention implementation, the indexer must evaluate relevance scores between every query and all historical tokens. That is itself a quadratic computation. The compute saved by sparsification is largely consumed by the indexing process.
The essence of the problem is this: sparsification merely shifts the computational bottleneck from the attention layer to the index layer, and the index layer’s cost also grows quadratically with context length. To achieve a real efficiency breakthrough at the 10M-token level, the indexing mechanism itself must be structurally optimized.
Latent Sparse Attention: Breaking Through with a Dual-Layer Index
To address this bottleneck, a new method called Latent Sparse Attention (LSA) has been proposed. Its core insight is that relevance matching should not be performed directly in the original token space. Instead, information should first be compressed into a low-dimensional latent space, where preliminary filtering is completed, before returning to the original space for refined attention computation.
The elegance of this idea lies in a dual-layer indexing architecture that fully decouples “what to find” from “how to attend.”
Layer 1: Latent Coarse Filtering with Matrix Factorization Instead of Pairwise Comparison
In the first layer of LSA, the model builds a low-dimensional latent index. Specifically, through learnable compression matrices, the model maps a sequence of length N into a compact representation set much smaller than N. Relevance computation no longer occurs in the original N×N space, but in an N×K low-dimensional space, where K is much smaller than N.
From a matrix-operation perspective, this is equivalent to decomposing the original relevance matrix into the product of two low-rank matrices. This design directly changes the order of computational complexity: if naive indexing requires N×N operations, latent-space indexing requires only N×K operations. When N grows from 1M to 10M, naive indexing compute grows by 100x, while LSA grows by only 10x, creating an order-of-magnitude gap.
Layer 2: Fine-Grained Attention on a Candidate Subset Only
After coarse filtering in the first layer, each query needs to attend only to a substantially reduced candidate token subset. The second layer performs conventional attention computation only on this subset, keeping attention-layer compute within an acceptable range.
Notably, both the coarse-filtering and fine-computation stages of LSA are jointly optimized through end-to-end gradient backpropagation, and the indexer’s training objective is strongly aligned with the final language modeling objective. This differs fundamentally from heuristic sparse methods such as fixed-window or random-sampling approaches: the LSA indexer is task-aware and can dynamically adjust its filtering strategy based on context semantics.
Architecture Choices and Training Strategy: Division of Labor Across Heterogeneous Attention Layers
In practice, LSA is not applied to every layer of the model. Instead, it uses a heterogeneous architecture: shallow layers retain full or local attention to capture fine-grained local relationships, while deep layers introduce LSA to handle long-range dependencies and global information aggregation. This design draws on the “local first, global later” information-processing paradigm in cognitive science and is a key engineering decision for balancing accuracy and efficiency.
Each LSA layer contains two key components:
- Latent space constructor: compresses the current sequence into a compact low-dimensional representation. Its design resembles a lightweight cross-attention module, but its output dimension is much smaller than its input dimension.
- Gated routing unit: based on the query’s representation in latent space, dynamically determines which token set to read in detail and the weight of each token.
For training, LSA uses a staged approach: first, standard pretraining on large-scale general corpora; then, fine-tuning the indexer on long-text corpora so the model gradually adapts to ultra-long-context scenarios. Because the latent dimension is much smaller than the original dimension, the indexer accounts for a very small share of total model parameters—less than 1%—and the additional memory overhead is negligible.
Performance Quantification: Speedup at 10M Tokens
In public evaluations, LSA achieved a 22.7x speedup during the prefill stage of a single attention layer in a mainstream large model at 10M-token scale. On another model with a larger parameter count, the speedup reached 72.4x. In terms of accuracy, LSA maintained performance close to the original model across a range of long-text understanding, reasoning, and retrieval tasks, with no obvious accuracy loss.
The compute comparison behind this speedup is instructive. At 10M tokens, the indexing overhead of a naive sparse method is on the order of 10^14 operations, while LSA’s latent-space index reduces this to roughly 10^11 operations. That three-order-of-magnitude difference translates directly into tens of times improvement in end-to-end latency.
Engineering Deployment and Typical Use Cases
From an engineering perspective, LSA does not require special hardware support; training and inference deployment can be completed on existing GPU clusters. Its core operator is low-rank matrix multiplication, which is naturally friendly to mainstream distributed strategies such as tensor parallelism and pipeline parallelism.
Key parameters to consider during deployment include:
- Latent dimension K: balances compression ratio and coarse-filtering quality, typically in the range of 128 to 512.
- Candidate set size S: the maximum number of tokens retained for fine computation in each layer, requiring a tradeoff between context coverage and compute budget.
- Inter-layer heterogeneity ratio: how many low-precision sparse layers to retain in shallow layers and how many LSA layers to configure in deep layers, involving a tradeoff between accuracy and throughput.
In typical applications, LSA is particularly suitable for three categories of tasks:
- Large-scale document intelligence: processing an entire encyclopedia, all financial reports, or batches of papers at once, and quickly locating cross-document relationships.
- Ultra-long dialogue systems: accurately recalling early key facts across tens of thousands of dialogue turns without being affected by window truncation.
- Code repository-level understanding: performing global modeling over million-line codebases and enabling precise reasoning about cross-file dependencies.
Future Outlook: From 10M to Unlimited Context
The proposal of LSA shows that the performance bottleneck in sparse attention is not insurmountable. The key is to transform brute-force search in a high-dimensional space into efficient indexing in a low-dimensional space. This design philosophy aligns with the classic database idea of “coarse filtering first, precise lookup second,” and again demonstrates the value of cross-domain methodology transfer.
Of course, 10M is not the endpoint. As context length continues to move toward the hundreds-of-millions level or even unlimited context, a single-layer index may still prove insufficient. A future direction may be to build multi-level tree-structured indexes, performing filtering layer by layer at different granularities to form a more efficient information retrieval path. In addition, hybridizing LSA with linear attention and selecting different mechanisms across layers may open new room for performance gains.
For developers and architects, the current conclusion is already clear: as we enter the 10M-token era, the optimization focus of attention mechanisms has shifted from “attention computation” to “index computation.” Whoever solves the indexing efficiency bottleneck first will gain an early advantage in the ultra-long-context direction. LSA provides one validated and reliable path, and the road ahead extends far beyond 10M.
