Sparse Attention at 10 Million Tokens: How Latent-Space Retrieval Delivers a 22x Prefill Speedup
As context windows scale from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to deciding which tokens to attend to. This article breaks down where the quadratic indexing cost comes from, explains how Latent Sparse Attention (LSA) moves relevance scoring into a low-dimensional latent space with probabilistic filtering, and reports the published prefill speedups of 22.7x and 72.4x alongside the accuracy trade-offs. It closes with practical engineering guidance on chunking, pipeline overlap, dynamic k, observability, and elastic resource scheduling.
1. Background: From Million to 10 Million Tokens, the Bottleneck Moves
Over the past two years, long context has shifted from an experimental feature to a default specification. Million-token context is now a standard configuration across several model services, and hybrid architectures that combine sparse attention with linear attention are used to balance memory footprint against throughput. These designs share the same premise: instead of having every query vector scan the entire token history, each query selects a few of the most relevant segments to compute over.
That premise has been validated repeatedly at the million-token scale. But as context keeps growing toward 10 million tokens, a previously unremarkable cost starts to spiral. Take a certain class of global attention layers: at the 10-million-token scale, roughly 98% of prefill time is not spent on the matrix math of attention itself, but on the indexer that decides which tokens to look at.
The nature of the problem has changed. Sparse attention has long proven that attending to a small subset is enough to preserve accuracy. What actually blocks ultra-long context is that finding that small subset still grows quadratically with context length.
2. Where the Quadratic Cost Comes From
Breaking the prefill stage apart, the cost has three components:
- Attention computation: proportional to the number of selected tokens, and roughly linear after sparsification;
- Indexing/scoring: relevance must be evaluated for every historical token against each query, which is inherently O(N²);
- Data movement: index results determine the random read range over KV, and the more scattered the index, the lower the memory access efficiency.
Sparsification only compresses the first term; the second and third become dominant. Worse, the indexing stage is typically memory-bound rather than compute-bound, so it cannot be hidden by adding more compute. It also sits on the critical path and cannot be fully overlapped with subsequent computation.
3. The Core Idea of Latent Sparse Attention
A recent paper from a startup research team in collaboration with universities introduces Latent Sparse Attention (LSA). Its central claim: do not make the “who to select” decision in the original token space; move retrieval into a low-dimensional latent space instead.
The method can be summarized in four steps:
- Dimensionality reduction projection: compress each historical token’s key vector into a low-dimensional latent representation whose dimension is far smaller than the original head dimension;
- Latent-space scoring: the query vector is dotted with the compressed representations in the same latent space to obtain a coarse relevance estimate;
- Probabilistic filtering: apply Top-k or threshold sampling based on the score distribution, keeping only a small set of candidates and avoiding an exact sort over all tokens;
- Exact read: run full attention only over the selected original KV.
The key is the combination of steps 2 and 3: the low-dimensional dot product reduces the cost of a single scoring pass by an order of magnitude, while probabilistic filtering replaces “exactly sorting everything” with “approximately retrieving the head,” bringing the indexing stage down from quadratic to near-linear.
Illustrative pseudocode:
# Conceptual illustration, not a specific implementationlatent = project_down(kv_keys) # [N, d_latent], d_latent << d_headscores = query_latent @ latent.T # low-dimensional scoring, memory-access friendlyidx = top_k_or_sample(scores, k) # approximate filtering, avoids exact full sortout = attention(query, kv_keys[idx], kv_values[idx])
4. Where the Gains and Costs Draw the Line
The paper reports that at the 10-million-token scale, prefill for a single attention layer is sped up by 22.7x and 72.4x respectively (corresponding to two model configurations of different sizes), while accuracy stays close to the original model across multiple tasks. Speedups vary considerably between models, typically depending on the efficiency of the original indexing implementation, the head dimension, and the latent compression ratio.
The costs are equally clear: the latent projection introduces extra parameters and training cost; approximate filtering carries a risk of missing relevant tokens, which must be compensated for by alignment during training; and increased index randomness weakens memory locality, requiring a chunked layout to compensate.
5. Engineering Implementation Notes
- Chunking and prefetching: organize KV by chunks so that filtering results land in contiguous address ranges as much as possible;
- Overlapping indexing with computation: place low-dimensional scoring early in the pipeline so it runs in parallel with the previous layer’s output computation;
- Dynamic k: use a small k for short contexts and scale k up with budget for long contexts to keep accuracy under control;
- Observability: build monitoring and alerting around candidate hit rate, miss rate, and per-layer time share, using a logging service and monitoring system to locate indexing bottlenecks;
- Elastic resources: training and inference workloads differ greatly, so container platforms and message queues can be used for queue-based scheduling and elastic scaling, with object storage holding long-context samples.
6. Conclusion
The next round of optimization for ultra-long context is not about computing faster, but about selecting more cheaply. Moving the relevance decision into a low-dimensional latent space and replacing exact full sorting with probabilistic filtering is currently a viable path for pushing indexing cost from quadratic back to near-linear. For developers, the practical starting point is to quantify how much time the indexing stage consumes, then choose the compression ratio and k accordingly, rather than optimizing the wrong bottleneck.
