Sparse Attention at 10M-Token Context: A 22x Speedup by Moving Token Selection into Latent Space
As context windows grow from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to selecting which tokens to attend to. This article breaks down why the selection stage degrades to quadratic complexity, explains how Latent Sparse Attention moves retrieval into a compressed latent space to decouple selection cost from sequence length, and covers accuracy considerations, engineering practices, and the boundaries where this approach is worth evaluating.
1. Background: Once Context Passes 10M Tokens, the Bottleneck Moves
Over the past two years, long context has quickly become a standard capability in LLM serving. Million-token context has moved from an exclusive feature of a few flagship models down to a general specification, and 10M-token context is now entering the picture for certain scenarios: understanding very large code repositories, correlating logs that span a year or more, and joint question answering over large document collections.
Along this progression, one technical route has been widely adopted: instead of having every query vector scan the entire history of tokens, each query selects only a few of the most relevant tokens to participate in the computation. At million-token scale this idea has been validated repeatedly, with controllable accuracy loss and relatively mature engineering implementations.
But as context keeps growing to the 10M-token range, an overhead that used to be unremarkable starts to spiral. Take a certain class of global attention layers: when running the prefill stage at 10M tokens, most of the time is not spent on the matrix operations of attention itself, but on the indexing step that “decides which tokens to look at.” In other words, the real cost center has migrated from “computing attention” to “selecting tokens.”
The nature of this change is worth emphasizing. Sparse attention has already shown that “looking at only a small fraction” is enough to preserve accuracy. What actually blocks very long context is the act of “finding that small fraction,” whose cost still grows quadratically with context length. The indexer has to perform similarity retrieval, sorting, and filtering over a massive history; the larger the scale, the slower the retrieval, until it eats up the gains that sparsity provided.
2. Root Cause: Why “Selection” Costs More Than “Computation”
To understand this bottleneck, split the attention layer into two stages.
The first stage is selection: determining a candidate token set for each query. Common approaches include nearest-neighbor selection based on a local window, bucketed retrieval based on hashing or clustering, and approximate similarity computation based on low-rank projection. What these methods share is that they need a global or semi-global retrieval pass over the long sequence.
The second stage is computation: applying attention-weighted summation only over the candidate set. Because the number of candidates is capped at a constant or sublinear level, the cost of this stage is relatively manageable.
The problem is that on large sequences the first stage often degrades to quadratic complexity. Even with approximate techniques such as bucketing or clustering, as sequence length grows the number of buckets, the number of retrieval candidates, and the sorting overhead all inflate at the same time. Meanwhile, to preserve accuracy the candidate count cannot be squeezed too small, which creates a dilemma: too few candidates and accuracy drops, too many candidates and the index blows up.
So the key to optimization is not to keep compressing the candidate count, but to change the space in which “selection” happens. This is exactly the starting point of Latent Sparse Attention.
3. Core Idea: Move Retrieval into Latent Space So Selection Cost No Longer Grows Quadratically
The basic premise of Latent Sparse Attention is this: retrieval in the original token space is inherently strongly coupled to sequence length, but if the sequence is first compressed into a low-dimensional latent space and similarity matching plus candidate filtering are done there, the cost of retrieval can drop significantly.
The logic chain can be summarized in three steps.
Step one, build latent representations. Apply learnable dimensionality reduction or aggregation to the key vectors of historical tokens, forming a set of latent vectors whose count is far smaller than the original sequence. Aggregation can take the form of segmented pooling, learnable query compression, or low-rank projection, with the goal of shrinking scale while preserving as much semantic distinctiveness as possible.
Step two, match in latent space. Use the current query to retrieve the few most relevant latent vectors. The candidate scale here is determined by the number of latent vectors rather than the number of original tokens, so retrieval cost drops sharply.
Step three, map back from latent space to the original space. Use the hit latent vectors to locate the corresponding blocks of original tokens, and run fine-grained attention only within those blocks. Because the number of candidate blocks is bounded, the computation stage stays sparse.
The key benefit is that the complexity of selection shifts from “growing quadratically with original length” to “growing with latent space size,” and latent space size can be tuned independently through the compression ratio. Put differently, it decouples “finding relevant tokens” from length.
Expressed as illustrative pseudocode:
# Conceptual illustration, not a concrete implementationlatent_keys = compress(history_keys, ratio=r) # compress the sequence into latent spacehit = topk(sim(query_latent, latent_keys), k) # latent-space retrieval, cost tied to latent space sizeblocks = map_to_blocks(hit) # map back to original token blocksout = sparse_attention(query, history, blocks) # fine-grained attention only within candidate blocks
It is worth stressing that the compression ratio and the number of candidate blocks are two independent knobs: the former determines retrieval cost, the latter determines the balance between computation cost and accuracy. This decoupling makes it possible to tune parameters separately per layer and per task rather than applying one global setting.
4. Results and Accuracy: Order-of-Magnitude Speedups Without Accuracy Concessions
In publicly described results, this class of methods brings tens-of-times speedup to the prefill stage of a single attention layer at 10M-token scale, with the magnitude of the speedup varying across model sizes and larger models benefiting more. This matches intuition: the larger the model and the longer the sequence, the higher the share of indexing overhead, and the greater the marginal benefit of optimizing the index.
On accuracy, the key question is whether the compression process preserves enough semantic distinctiveness. In practice this usually requires comparative evaluation across several task types, including retrieval-style question answering over long documents, cross-passage reasoning, code structure understanding, and long-conversation memory. Three kinds of metrics deserve attention: the accuracy shift of the task relative to the original model; the accuracy curve across different compression ratios, to confirm there is a usable flat region; and long-tail sample behavior, so that averages do not hide local degradation.
A common engineering conclusion is that a higher compression ratio is not always better. There is a “flat accuracy region” within which further compression yields only marginal gains while risking long-tail degradation. The tuning goal, therefore, is not extreme compression but finding the boundary of that flat region.
5. Engineering Implementation Notes
If you want to evaluate a similar idea in your own system, focus on the following.
- Differentiated configuration per layer. Not every layer needs the same sparsity strategy. Layers closer to the output are more sensitive to accuracy and can keep a higher candidate count; middle layers can be compressed more aggressively.
- Deploy indexing and computation separately. The index structure can be cached and updated incrementally, while the computation stage can be optimized for batching. Profile the two separately so that mixing them does not make the bottleneck hard to locate.
- Incremental maintenance of the compressed structure. In long-context scenarios history keeps growing, so the latent structure needs to support incremental insertion and eviction rather than a full rebuild every time.
- Coordinate with caching strategies. General techniques such as prefix caching and paged attention can be layered on top of latent-space retrieval, but watch for consistency between cache hits and retrieval candidates to prevent mismatches where something is “in the cache but not selected by retrieval.”
- Observability. Turn index latency, candidate hit rate, compression ratio, and accuracy shift into monitoring metrics, backed by logging and alerting, so that tuning can continue after the long-context feature ships.
When deploying on the cloud, it is common to run inference services on a container platform, store long-context data and index snapshots in object storage, use a message queue to smooth out request spikes, and build a closed observation loop with logging and alerting. These are all general capability categories; specific choices should be evaluated against your own workload characteristics.
6. Applicability and Selection Guidance
Latent Sparse Attention is not a universal fix. It fits scenarios with these characteristics: extremely long context, a high share of retrieval overhead, and tasks whose dependence on local detail can be satisfied by block-level candidates. Conversely, if a task requires fine-grained token-by-token interaction over the full sequence, or if key evidence in the history is extremely dispersed, the information loss from compression may be amplified, and it should be evaluated cautiously.
For selection, follow a simple principle: measure first, then optimize. Profile once at the target length to confirm whether the indexing stage really is the dominant cost. Only when the indexing share is high enough will changes like latent-space retrieval deliver order-of-magnitude gains. Otherwise, optimizing the computation stage may offer a better return on investment.
Overall, the next stage of competition in very long context is shifting from “how much can be seen” to “how to find the part that should be seen at low cost.” Moving the selection process into latent space is a currently validated technical path and is worth evaluating first in 10M-token context scenarios.
