Sparse Attention at 10M-Token Context: How Latent-Space Indexing Delivers 22x Prefill Speedup
As context windows scale from millions to tens of millions of tokens, sparse attention faces a new bottleneck: finding the relevant tokens cheaply, not just attending to a subset of them. This article breaks down why index cost, rather than compute, becomes the dominant constraint at extreme lengths, explains how Latent Sparse Attention moves candidate selection into a compressed latent space to make indexing near-linear, and covers the engineering side: compression module design, continued pretraining with a short-to-long curriculum, integration with chunked prefill and KV cache reuse, and the metrics to use when deciding whether this approach fits your workload. Reported results include over 20x prefill speedup for a single global attention layer at 10M tokens, up to roughly 70x under some architectures, with accuracy close to the original model on long-document understanding, multi-hop QA, and code retrieval.
When context length moves from millions to tens of millions of tokens, the core tension in sparse attention changes. Models do not lack the ability to look at only part of the sequence; what they lack is a low-cost mechanism for finding that part. The conventional approach scores and ranks similarity in the original token space, and that cost grows quadratically with sequence length until it consumes most of the prefill stage. A recent joint effort by an overseas startup research team and European universities proposes Latent Sparse Attention, which moves the “who to select” decision into a compressed latent space, approximates original relevance with low-dimensional representations, and pushes index-stage complexity close to linear. In experiments at the 10M-token scale, a single global attention layer achieves more than 20x speedup in prefill, with speedup ratios around 70x under some model architectures, while accuracy on long-document understanding, multi-hop QA, and code retrieval stays close to the original model. This article covers the root cause, the method, the engineering details, and adoption guidance so developers can judge whether the approach fits their workload.
1. Reframing the Problem: Sparse Attention Never Solved Selection Cost
The boundary of sparsity gains
Sparse attention rests on one assumption: for any query vector, only a few tokens in the history actually matter. That assumption has been validated repeatedly in long documents, codebases, and conversation histories, which is why mainstream long-context designs use hybrid structures such as global plus local layers, random sampling plus sliding windows, or block-level aggregation. But sparsification only lowers the cost of computing attention. It does nothing to lower the cost of deciding who matters.
Quadratic cost is transferred, not eliminated
Evaluating relevance in the original token space requires a similarity score between the query and every historical position, followed by Top-K selection. Increase sequence length tenfold and the candidate set grows tenfold, so the per-score cost rises too, and the overall trend stays quadratic. At tens of millions of tokens, this index overhead surpasses attention itself and becomes the dominant term in prefill. In practice it shows up as acceptable memory usage paired with absurdly high time-to-first-token, and batch throughput dragged down by a single request.
A layered view
Long-context inference can be split into three cost layers: the index layer (finding relevant tokens), the aggregation layer (weighted summation over selected tokens), and the projection layer (linear transforms and output). At million-token lengths, aggregation and projection dominate. Past ten million tokens, the index layer quickly overtakes them. The optimization target therefore has to shift from computing faster to searching more cheaply.
2. How It Works: Moving Retrieval into Latent Space
Core idea
The key observation behind Latent Sparse Attention is that judging relevance does not require the full original representation; a low-dimensional compressed representation already retains enough directional information. The flow becomes: compress the key vectors of historical tokens into a latent state sequence of uniform length, let the query score in that latent space, select candidate blocks, then return to the original space for exact aggregation.
How it differs from common approaches
- Unlike block-level summaries: latent states are not hand-crafted pooling results but learnable compressed representations, optimized end to end.
- Unlike retrieval add-ons: no external vector store or secondary index is needed; compression and scoring both happen inside the model.
- Unlike pure linear attention: exact global-layer expressiveness is preserved, with only the selection step made lightweight.
Complexity intuition
Let the sequence length be N and the compression ratio be r, so the latent sequence length is roughly N/r. Index-stage cost drops from a quadratic term in N to a near-linear term in N/r, while aggregation still runs only over the small set of selected original tokens, keeping accuracy loss controllable. The trade is one cheap coarse pass in exchange for skipping an expensive exact one.
3. Engineering Implementation
Compression module design
Compression is typically a lightweight projection plus position-aware aggregation, and it must preserve causality (a query cannot see the future), keep positions distinguishable, and match the compression ratio to the task’s length. Too low a ratio loses detail; too high a ratio degrades back to the original scheme.
Training and adaptation
Because a new module is introduced, some continued pretraining or long-context fine-tuning is usually required to align the compressed representation with the scoring distribution. A short-to-long curriculum works well in practice: converge stably on shorter sequences first, then extend length gradually to avoid early gradient noise.
Illustrative pseudocode
# Pseudocode: coarse filtering in latent space, exact computation in original spacedef latent_sparse_attention(q, k, v, compress, r=64, topk=2048):k_latent = compress(k) # [B, N/r, d]scores = einsum('bqd,bnd->bqn', q, k_latent)idx = topk(scores, k=topk) # coarse candidate blocksk_sel, v_sel = gather_blocks(k, v, idx, r)return softmax(q @ k_sel.T) @ v_sel # exact aggregation
Fitting into existing systems
The structure is more sensitive to memory bandwidth and relatively modest in compute demand, which makes it a good fit alongside chunked prefill, KV cache reuse, and continuous batching. If your stack already uses object storage for long documents, a message queue for task decoupling, and monitoring and alerting on time-to-first-token, integration can be smooth.
4. Adoption Guidance and Expected Returns
Where it fits
Ultra-long document review, cross-repository code understanding, long conversation memory, and context compression for multi-turn agents. The clearest gains appear in workloads above a few million tokens that are sensitive to time-to-first-token.
Where it does not
Short contexts, and tasks that depend on exact per-token matching such as verbatim proofreading or precise string location. Coarse filtering can introduce misses there, so a fallback path should be kept.
Metrics to evaluate
Track three things together: prefill throughput, time-to-first-token, and the accuracy decay curve on long tasks. Speedup ratio alone is easy to misread and must be tied to business metrics through A/B testing.
Where this is heading
Joint optimization of the compressed representation and the scorer, per-layer adaptive compression ratios, and dynamic mixing ratios with linear attention layers are all worth following. The overall judgment: once context reaches tens of millions of tokens, index efficiency replaces compute as the primary constraint on long context, and latent-space coarse filtering is currently the most engineering-feasible path.
