Sparse Attention at 10 Million Token Context: Why the Indexer Becomes the Bottleneck and How Latent Retrieval Delivers a 22x Speedup
As context windows move from millions to tens of millions of tokens, the cost of sparse attention shifts from computation to selection. This article breaks down why the indexer turns quadratic at 10M tokens, explains how Latent Sparse Attention moves scoring into a compressed latent space to cut selection cost to near-linear, and outlines the engineering trade-offs—slot count, chunked prefill, memory access, accuracy regression, and serving—needed to reproduce the reported 22.7x and 72.4x per-layer speedups.
1. The Problem: Cost Structure Changes Past 10 Million Tokens
Over the past two years, long context has shifted from an optional feature to a default specification. Million-token context is now standard across many model services. The common industry approach is to stop having every query vector scan the entire history of keys and values, and instead select only a small set of the most relevant segments for computation. This is the basic idea behind sparse attention. At the million-token scale, it has been repeatedly validated: as long as the selection is accurate, the accuracy loss can be kept within an acceptable range.
But once context pushes toward 10 million tokens, an initially negligible overhead starts to spiral. Take a model with global attention layers as an example. At 10 million tokens, during the prefill stage, roughly 98% of the time is not spent on the matrix operations of attention itself, but on the indexer that “decides which tokens to look at.” In other words, sparsification saves computation, but it does not save retrieval.
The nature of the problem therefore changes. Sparse attention has already proven that “looking at only a small part” is enough to preserve accuracy. What truly blocks ultra-long context is the cost of “finding that small part,” which still grows quadratically with context length.
2. Root Cause: Why the Indexer Becomes the New Bottleneck
Splitting attention into two stages makes the issue clearer:
- Selection stage: score each query and find the top-k most relevant keys.
- Computation stage: perform weighted aggregation only over the selected k keys.
The computation stage has complexity O(n·k), which is linear as n grows. But if the selection stage uses a naive “score everything, then take top-k” approach, its complexity is O(n²). When n grows from 10⁶ to 10⁷, the n² term grows 100x while k stays fixed, so the selection stage completely overwhelms the computation stage.
Two engineering factors amplify the problem:
- Memory access amplification: full scoring requires repeatedly reading all keys and values, making bandwidth a hard constraint.
- Insufficient parallelism: top-k selection and sorting are hard to saturate compute with the way matrix multiplication can.
An illustrative complexity comparison (pseudocode, showing only order-of-magnitude relationships):
# Naive sparse attention: the selection stage dominatesscores = q @ K.T # O(n^2) scoring, unacceptable at n=10Midx = topk(scores, k) # selectionout = softmax(scores[idx]) @ V[idx] # O(n*k) computation
3. The Core Idea: Move Selection into Latent Space
A recent paper from a joint team of a startup research group and a university proposes Latent Sparse Attention. The key is not to design a smarter scoring function, but to change the space in which scoring happens: instead of doing full comparison in the original token dimension, first compress the long sequence into a low-dimensional latent representation, then perform retrieval and selection in latent space.
It can be summarized in three steps:
- Compress: map historical keys and values into a small number of latent vectors (latent slots), with a count far smaller than n.
- Retrieve: the query compares only against a small number of slots in latent space, reducing selection cost from O(n²) to roughly O(n·m), where m is the number of slots and m≪n.
- Backfill: based on the latent-space match, map back to a subset of original tokens for exact aggregation.
An intuitive analogy: original tokens are like an entire cabinet of unorganized files, and searching them one by one is extremely costly. Latent space is like building a compressed index first—look up the index to locate the drawer, then flip through only that one drawer.
The paper reports the following results: at 10 million tokens, in the prefill stage of a single attention layer, one class of hybrid-architecture models sees roughly a 22.7x speedup, and another class sees roughly a 72.4x speedup, while maintaining accuracy close to the original model across multiple tasks. The “single attention layer” qualifier here is important: it measures the in-layer replacement benefit, not end-to-end overall acceleration.
4. Why It Can Balance Speed and Accuracy
- Controllable error: compression is lossy, but retrieval only needs to “locate the correct region” and does not require exact ranking, leaving ample room for tolerance.
- Decoupling of computation and selection: the expensive comparison happens in low-dimensional space, while high-dimensional exact computation applies only to a small set of candidates.
- Natural fit with hybrid architectures: global layers handle long-range dependencies, linear/local layers handle short-range details, and latent-space retrieval mainly replaces the indexing part of the global layers.
5. Engineering Implementation Notes
- Choosing the slot count m: too small hurts recall, too large degrades back to full scanning; it is recommended to sweep a recall-latency curve per task.
- Pair with chunked prefill: split the long sequence into chunks and build latent representations chunk by chunk to reduce peak GPU memory.
- Memory access optimization: keep latent representations resident and load original keys and values on demand to reduce bandwidth pressure.
- Accuracy regression: build a long-context evaluation set, focusing on “needle in a haystack” retrieval tasks and multi-hop reasoning.
- Serving: ultra-long-context inference typically requires a container platform for elastic scaling, object storage to hold long samples, and monitoring and alerting to track time-to-first-token and throughput; on Baidu AI Cloud, these capabilities can be combined using general cloud service categories.
6. Conclusion
In the era of 10 million tokens, the optimization focus for long context has shifted from “compute fast” to “find accurately and find cheaply.” The value of Latent Sparse Attention lies in replacing high-dimensional full comparison with low-dimensional retrieval, pushing the quadratic bottleneck back to near-linear. For developers, focusing on four things during implementation—slot scale, chunking strategy, memory access layout, and accuracy regression—is enough to reproduce a similar acceleration path in their own models.
