Breaking the Indexer Bottleneck in Sparse Attention at 10 Million Tokens
Sparse attention makes 1M-token contexts practical, but at 10 million tokens the indexer that selects which tokens to attend to becomes the dominant cost. This article explains why indexer cost grows quadratically and how Latent Sparse Attention (LSA) moves candidate selection into a compressed latent space to decouple retrieval cost from sequence length. It also covers the reported speedups and practical engineering recommendations.
1. From 1 Million to 10 Million Tokens: Another Leap in Context Length
Over the past two years, long-context capability has become a key competitive area for large language models. One leading open-source model made a 1M-token context its default specification for official service. Several other vendors followed with models that support 1M-token contexts, and many of them introduced hybrid architectures that combine sparse attention with linear attention. These models share one engineering choice: instead of letting each query attend to every historical token, they select a small number of the most relevant tokens for attention computation.
This approach has been validated repeatedly at the 1M scale. Whether for document question answering, code repository understanding, or long video subtitle analysis, sparse attention preserves accuracy while reducing attention compute from O(N²) to roughly O(N·k), where k is the number of selected tokens. For a time, the industry believed that the computational challenge of ultra-long contexts was largely solved.
However, as context length moves toward 10 million tokens (10M), an overhead that was once minor begins to grow out of control. It exposes a deeper flaw in this approach.
2. Bottleneck Shift: Attention Is Faster, but Choosing What to Attend to Is Slower
2.1 An Overlooked Profiling Result
In a profiling analysis of the global attention layers of a hybrid-architecture model that supports 1M-token contexts, the prefill stage at 10M tokens showed a surprising result. About 98% of the time was not spent on attention computation itself. It was spent on the indexer, which decides which tokens to attend to.
In other words, sparse attention lowered the cost of computing attention, but the cost of selecting tokens quietly increased. At extreme sequence lengths, selection becomes the dominant cost.
2.2 Why the Indexer Grows Quadratically
Mainstream sparse attention indexers typically compute a relevance score for each query against all historical tokens. They use methods such as lightweight scoring networks or dot products after low-rank projection, and then apply Top-K selection. This creates three problems:
- Scoring is performed per token. Even if each score is cheap, the total work is proportional to sequence length N. Because every query scores N keys, the overall complexity is O(N²).
- Memory access patterns are unfriendly. Indexing typically cannot take full advantage of tiling and operator fusion as standard attention does, so memory bandwidth becomes a hidden bottleneck.
- Constant factors grow linearly with context length. At 1M tokens, indexing overhead is tolerable. At 10M tokens, the quadratic term outweighs the savings that sparse attention provides.
The problem has therefore changed. Sparse attention has already shown that attending to a small subset is enough to preserve accuracy. What now limits ultra-long contexts is that finding that small subset still grows with the square of context length.
3. The Core Idea of LSA: Moving Selection into a Low-Dimensional Latent Space
To address this tension, researchers have proposed Latent Sparse Attention (LSA). Its core idea can be summarized in one sentence: instead of selecting candidates in the high-dimensional, per-token original space, first compress historical tokens into a low-dimensional latent space, then perform retrieval in that latent space.
3.1 Three-Stage Structure
LSA’s pipeline has three stages:
- Compression (Latent Encoding): A lightweight projection or aggregation module compresses the representations of N historical tokens into M latent vectors, where M ≪ N, for example a fixed few thousand. This step is linear in sequence length and naturally supports chunked, streaming processing.
- Latent Indexing: Instead of scoring a query against all N keys, the query is first scored against the M latent vectors to quickly identify candidate regions. Retrieval cost drops from O(N) to O(M), which decouples it from the original sequence length.
- Exact Attention: Standard high-precision attention runs only on the selected candidate tokens, so output quality is preserved.
3.2 Illustrative Pseudocode
def lsa_attention(query, kv_cache, latent_projs, top_k):# Stage 1: historical tokens have already been compressed offline into M latent vectors# latent_projs: [M, d_latent], M << N# Stage 2: latent-space retrieval, cost decoupled from Nscores = query @ latent_projs.T # [M]candidate_blocks = topk(scores, k=top_k) # hit several token blocks# Stage 3: exact attention only on candidate tokenskeys = gather(kv_cache.keys, candidate_blocks)values = gather(kv_cache.values, candidate_blocks)return softmax(query @ keys.T) @ values
3.3 Why Accuracy Can Be Preserved
Intuitively, adding a compression step may lose information. LSA keeps accuracy close to the original model on long-text tasks for two main reasons. First, the latent vectors are not simple pooling. Training objectives align retrieval relevance with final attention contribution, so the Top-K results in latent space overlap heavily with the Top-K results in the original space. Second, final attention is still computed exactly over the original tokens. Compression affects only the recall of candidates, not the representation of content once it has been recalled. This applies the two-stage idea of recall followed by reranking to the attention mechanism.
4. Reported Results: Large Speedups at 10M Tokens
According to the published paper, in the 10M-token prefill setting:
- For a single attention layer in a hybrid-architecture model, LSA delivers about 22.7x speedup.
- For a dense model with about 27 billion parameters, the speedup reaches about 72.4x. This model’s original indexing overhead accounted for a larger share of runtime, so the gain is larger.
- On a range of benchmarks, including long-document retrieval, multi-turn dialogue, and code understanding, accuracy remains roughly on par with the original model.
The speedup grows with sequence length. The longer the sequence, the more severe the quadratic cost of the original indexer, and the more visible the benefit of LSA’s length-decoupled retrieval. LSA is therefore not a one-time patch. It represents an improvement in how cost scales with context length.
5. Engineering Recommendations
For developers who want to apply long-context models in their own products, the following directions build on the LSA approach:
- Profile before optimizing. Do not replace attention implementations blindly. Use a profiler to split prefill time between indexing and computation, and confirm where the bottleneck is. Below 1M tokens, traditional sparse attention may already be sufficient.
- Train the compression module jointly with retrieval objectives. Align the latent encoder with retrieval quality metrics, such as candidate recall, so that compression loss does not translate directly into accuracy loss.
- Plan the inference infrastructure. Long-context inference places heavy demands on GPU memory and compute scheduling. Teams can store the KV cache and latent vectors in tiers and load them on demand to reduce per-GPU pressure. General-purpose cloud capabilities, such as GPU compute, object storage, and inference acceleration services, can support this setup.
- Choose sparsity granularity based on the workload. Block-level sparsity is more memory-access friendly than token-level sparsity. Combined with latent retrieval, it can balance recall and throughput.
6. Conclusion
The evolution of ultra-long context attention has moved from letting every query attend to all tokens, to attending to a small subset, and then to finding that subset quickly in a low-dimensional latent space. LSA addresses the central question of how to approach full-attention quality at lower cost. It shifts the bottleneck from computation to retrieval, then decouples retrieval from sequence length. As 10-million-token contexts move into real business applications, index-first designs like this are likely to become a standard part of next-generation efficient attention architectures.
