Sparse Attention at 10 Million Tokens: Key Techniques Behind a 22x Prefill Speedup
As long-context models push from one million to ten million tokens, the bottleneck shifts from attention computation to candidate selection, where indexing cost still grows quadratically. This article explains where that quadratic overhead comes from and how Latent Sparse Attention (LSA) moves top-k retrieval into a compressed latent space, using history compression, latent-space scoring, within-block refinement, and sparse aggregation to decouple retrieval cost from context length. It covers the reported speedups of roughly 22.7x and 72.4x in single-layer attention prefill, why the gains depend on model architecture, and practical engineering considerations around compression granularity, prefill versus decode evaluation, cache consistency, numerical stability, observability, and elastic resources.
Sparse Attention at 10 Million Tokens: Key Techniques Behind a 22x Prefill Speedup
1. Long Context Enters the 10 Million Token Era, and the Bottleneck Moves
Over the past two years, long-context capability has advanced along a clear curve. One million tokens went from an experimental feature to the default spec of mainstream online services, and a new wave of models has since matched it. The focus of competition has shifted from “can you fit it in” to “is it still cost-effective once it fits.”
Along that curve, nearly every long-context approach converges on the same judgment: each query should no longer scan the entire token history, but instead select a few of the most relevant segments to participate in the computation. This is the basic idea of sparse attention. It has been validated repeatedly at the million-token scale — reading only a small fraction of the history keeps accuracy loss controllable while cutting compute and memory overhead substantially.
But as context keeps growing from one million toward ten million tokens, an overhead that once seemed negligible starts to spiral. Take a single global attention layer as an example: at the ten-million-token scale, during the prefill stage roughly 98% 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, sparsification successfully pushed down the expensive attention computation, but shifted the cost onto candidate selection.
The nature of the problem therefore changes. Sparse attention has long proven that “looking at only a small part” is enough to preserve accuracy; what actually blocks ultra-long context is that “finding that small part” still grows quadratically with context length.
2. Where the Quadratic Indexing Overhead Comes From
To understand this overhead, attention needs to be split into two stages.
The first stage is scoring and selection: for each query, estimate its relevance to all historical tokens and pick the top-k candidates. The naive approach requires explicitly computing the similarity between the query and every key, a cost proportional to the number of queries times the number of keys — the classic O(n²). The second stage is aggregation: a weighted sum over only the k selected positions, with a cost of O(n·k). Since k is usually far smaller than n, this stage is no longer the bottleneck.
The problem is that, in order to “select accurately,” the first stage often adds extra projections, pooling, block-level statistics, or multiple rounds of reranking, which further inflates the constant factor. When n grows from 10⁶ to 10⁷, the n² term grows 100x, and the indexer goes from a supporting role to the main character.
A common engineering intuition is to “make k smaller.” But that hurts accuracy, especially on tasks that require global retrieval across a wide span, where too small a candidate set directly loses key evidence. Another path is to compress the history, but compression brings irreversible information loss. So the real solution has to do two things at once: the cost of candidate retrieval must not grow quadratically with n, and the retrieval space itself must be expressive enough to carry global information.
3. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Latent Space
A recent paper from a startup research team working with universities proposes Latent Sparse Attention (LSA). The core idea fits in one sentence: do top-k retrieval not in the original token space but in a compressed latent space, then map the hits back to their original positions.
The logic chain has four links.
- History compression: encode contiguous blocks of historical tokens into a small number of latent vectors (latent slots), each carrying the aggregated semantics of its block. History length n is compressed to m, with m far smaller than n.
- Latent-space scoring: the query computes similarity against the m latents in latent space, reducing complexity from O(n) to O(m) and turning the overall indexing cost from quadratic into near-linear.
- Within-block localization: once a latent is hit, fine-grained top-k is performed only inside the original block that latent corresponds to. Block size b is a controllable constant, so this step costs O(b).
- Sparse aggregation: attention weighting is completed over the finally selected set of original tokens, keeping the same numerical path as the original model and thus preserving accuracy as much as possible.
The illustrative pseudocode below emphasizes the stage breakdown rather than specific interfaces:
# Conceptual illustration: latent retrieval + within-block refinementlatent = compress_history(kv_cache, slot_per_block=r) # n -> mscores = query @ latent.T # O(m), replaces O(n)block_ids = topk(scores, k_blocks) # coarse filter to blockscand = gather_within_blocks(kv_cache, block_ids, b) # within-block refinement, O(b)out = sparse_attention(query, cand) # same as the original path
The key benefit of this design is that retrieval cost is nearly decoupled from n, while the accuracy requirement — that candidates must contain the truly relevant segments — is guaranteed jointly by two-level recall (block-level coarse filtering plus within-block fine filtering).
4. Why Both 20x- and 70x-Order Speedups Are Achievable
The numbers reported in the paper: at ten million tokens, single-layer attention prefill is sped up by about 22.7x for one class of medium-sized models and by about 72.4x for another class of larger models, with accuracy close to the original models across a range of tasks.
The difference in speedup is not accidental; it is determined by model structure. Models with a higher proportion of global attention layers, longer history to scan per layer, and larger indexer constant factors gain more from “quadratic reduced to near-linear.” Conversely, if a model relies heavily on linear attention or local windows, its indexing overhead is already small, and the marginal benefit of LSA is naturally limited.
This also explains why hybrid architectures have become the mainstream choice: local attention handles fine-grained short-range modeling, linear attention handles low-cost long-range propagation, and sparse global layers handle precise look-back at critical moments — and it is exactly the cost structure of that last layer that LSA optimizes.
5. Engineering Implementation Notes
To evaluate this kind of approach in your own inference stack, focus on the following points.
- Trade-off between compression granularity and recall: the number of slots, block size b, and the number of coarsely filtered blocks are the three core knobs. Sweep them on an offline evaluation set first, lock in the accuracy inflection point, and only then talk about performance.
- Evaluate prefill and decode separately: LSA’s gains are concentrated in prefill; the decode stage processes a single query per step, so end-to-end latency needs to be measured separately.
- Cache consistency: latent vectors need incremental updates as history grows; make sure they work well with paged key-value caching and avoid re-encoding.
- Numerical stability: compression and aggregation introduce extra accumulation, so under mixed precision it is advisable to keep higher precision on the normalization and summation paths.
- Observability: bring indexing time, candidate hit rate, and information retention before and after compression into monitoring and alerting, and use logging and monitoring systems to locate long-tail requests.
- Elastic resources: ultra-long-context inference is sensitive to memory and bandwidth; pairing container platforms’ elastic scaling with object storage to externalize session state can significantly improve the cost curve.
6. Conclusion
The real obstacle in the 10-million-token scenario is not that attention cannot be computed, but that “who to compute with” is itself growing quadratically. Through the four-stage structure of “compress history — coarse filter in latent space — fine filter within blocks — sparse aggregation,” Latent Sparse Attention decouples retrieval cost from context length and delivers more than an order-of-magnitude prefill speedup while preserving accuracy.
For engineering teams, this points to a more general principle: as scale approaches its limits, the optimization focus should shift from “compute faster” to “compute less and compute accurately,” and hierarchical retrieval combined with latent-space compression is currently one of the most cost-effective levers available.
