Sparse Attention at 10M Token Context: Why Latent-Space Selection Delivers 22x Prefill Speedups
As context windows grow from 1M toward 10M tokens, the cost structure of long-context inference changes fundamentally. This article explains Latent Sparse Attention, an approach that moves token selection out of the original token space and into a compact latent space. Public research reports roughly 22.7x single-layer prefill speedups for one class of hybrid sparse/linear architectures and about 72.4x for another class of dense baselines at 10M tokens, with accuracy close to the original models. You will learn where the bottleneck shifts during prefill, the three-step mechanism behind latent selection, the complexity math behind the gains, how recall protects accuracy, and a practical rollout path with boundary conditions and risks.
When context length moves from 1M to 10M tokens, the cost structure of long-context inference changes fundamentally. We used to treat attention as the dominant cost, but at the 10M token scale, roughly 98% of the time spent in a global attention layer during prefill goes not to attention itself but to the indexing step that decides which tokens to look at. In other words, sparse attention has already solved the accuracy problem of “attending to only a small subset is enough,” but it has not solved the efficiency problem of “how to find that subset cheaply” — because the lookup itself still grows quadratically with context length.
The technique this article focuses on is Latent Sparse Attention. Its starting point is simple: if filtering in the original token space is too expensive, move the filtering into a low-dimensional latent space constructed artificially. Public research gives the following order-of-magnitude reference: at 10M tokens, prefill for a single attention layer can be sped up by about 22.7x (for one class of hybrid sparse/linear architecture models) and about 72.4x (for another class of dense baseline models), while maintaining accuracy close to the original models across multiple tasks. Let’s break this down.
1. The Bottleneck Shifts: From Computing Attention to Finding Tokens
Long-context inference is usually divided into two phases: prefill and decode. Prefill processes all historical tokens at once, concentrating compute and memory-access pressure; decode generates one token per step but repeatedly reads a growing context.
The basic assumption of sparse attention is that for any given query, only a very small number of keys/values actually influence the output. So we compress each query’s visible range to a fixed budget (for example, top-k tokens or a number of blocks). At the 1M scale, this step has been validated repeatedly, with controllable accuracy loss.
But the cost is hidden in the selection step. The naive approach scores the query against all historical tokens and then takes top-k; the blocked approach scores block summaries and then searches within blocks. Either way, selection cost rises quickly with context length, eventually overtaking attention computation itself at the 10M scale and becoming the dominant term. This is where “the indexer eats 98% of the time” comes from.
The conclusion is clear: further optimizing the attention operator has limited returns; the complexity of the retrieval path must be optimized.
2. The Core Mechanism of Latent Sparse Attention
Latent Sparse Attention has three key steps.
Step one: build a compact latent representation. Split the long sequence into fixed-size blocks, and compress each block into a small number of latent vectors via a lightweight projection (essentially a “semantic summary” of the block), with dimensionality far below the original head dimension. This step is parallelizable offline and scales linearly with sequence length.
Step two: perform scoring and filtering in the latent space. The query is also projected into the latent space and compared against block summaries with a small-scale similarity computation to get block-level scores, then top-b blocks are selected. Because the number of candidates drops from “number of tokens” to “number of blocks,” the number of comparisons falls by more than an order of magnitude.
Step three: perform exact attention only within the selected blocks. Only now do we return to the original dimension, compute real attention over tokens within the b blocks, and apply cross-block normalization correction to keep the numerical distribution consistent with the original attention.
The structure can be expressed with illustrative pseudocode:
# 1) Block-level latent summaries (linear complexity, parallelizable)blocks = chunk(kv, size=B) # [num_blocks, B, d]latent = proj_down(blocks).mean(1) # [num_blocks, d_lat], d_lat << d# 2) Latent-space filtering (candidate count = number of blocks)q_lat = proj_down_q(q) # [d_lat]scores = q_lat @ latent.T # [num_blocks]sel = topk(sel_b, scores) # select b blocks# 3) Exact attention within selected blockskv_sel = gather(blocks, sel).flatten(0, 1)out = softmax(q @ kv_sel.T / sqrt(d)) @ kv_sel
Three engineering details determine success or failure. First, block size and the number of candidate blocks need joint tuning: blocks that are too large degrade back to dense, while blocks that are too small increase scheduling overhead. Second, the latent dimension must be expressive enough to capture intra-block semantics while preserving the efficiency advantage of matrix multiplication. Third, cross-block softmax needs the correct normalization factor; otherwise systematic bias appears on long sequences.
3. Why the Speedup Reaches Tens of Times
Once the complexity is written out, the gains are obvious. Let sequence length be n, block size B, number of candidate blocks b, and latent dimension d_lat.
- Dense attention: selection cost is 0, attention cost is O(n²·d).
- Naive sparse: selection cost O(n·d), attention cost O(n·k·d), but the selection constant is very large and memory access is irregular.
- Latent sparse: selection cost O((n/B)·d_lat), attention cost O(n·b·B·d).
When n reaches the tens of millions, the term (n/B)·d_lat shrinks by several orders of magnitude relative to n²·d, while b·B is fixed as a constant budget, so overall growth shifts from quadratic to near-linear. Different model structures (whether linear attention or hybrid sparse layers already exist, how head counts and dimensions are set) significantly change the constant factors, which explains why the observed speedups differ markedly between the two model classes (about 22x versus about 72x).
It should be emphasized that these speedup figures are measured at the “single operator / single-layer prefill” level; end-to-end throughput is also affected by scheduling, memory bandwidth, and parallelism strategy, and should not be treated as a commitment to overall service performance.
4. Why Accuracy Holds Up
Recall of the latent filtering is the key to accuracy. In practice, recall can be improved in three ways: use a mix of mean and max pooling for block summaries to preserve the signal of salient tokens; keep a small number of “global anchor” blocks (such as the sequence’s starting block and the most recent block) always visible to cover attention-sink phenomena; and introduce a selection-consistency constraint during training so that latent-space ordering approximates the true attention distribution.
For engineering, it is advisable to run offline evaluation first: compare dense baselines against sparse configurations on tasks such as long-document retrieval, multi-hop question answering, and repository-level code completion, observe the marginal-return curve of top-b, find the starting point of the accuracy plateau, and then set the budget.
5. Deployment Recommendations and Cloud Practice
To validate this direction in your own system, proceed along the following path:
- Fix the baseline: first measure the prefill latency and memory usage of the dense implementation at the target length, and clarify the bottleneck’s share.
- Operator replacement: roll out latent filtering at the granularity of a single layer as a canary, keeping the interface unchanged for easy rollback.
- Parameter tuning: grid-search block size, number of candidate blocks, and latent dimension, recording the accuracy-latency Pareto frontier.
- Service it: on the inference-serving side, use a container platform for elastic scaling, and use log services plus monitoring and alerting to observe time-to-first-token, time-per-token, and cache hit rate; long-context data can be placed in object storage to avoid local disks becoming a bottleneck.
- Capacity planning: re-estimate the concurrency ceiling for long-context scenarios using near-linear complexity, which typically significantly increases single-machine capacity.
6. Boundaries and Risks
Latent sparsity is not a cure-all. For very short contexts, the fixed overhead of compression and filtering may not pay off; for exact-copy tasks (verbatim retrieval, hash-style matching), insufficient recall is exposed directly; and if training and inference use different filtering configurations, distribution drift occurs. A reasonable strategy is length-adaptive: use dense for short sequences, switch to sparse for long sequences, and reuse selected blocks during decoding to reduce jitter.
Overall, the optimization focus of the 10M token era has shifted from “how to compute less” to “how to search less.” Moving the selection process into a low-dimensional latent space, trading near-linear cost for a fixed-budget set of high-quality candidates, is currently the most engineering-feasible path, and it also creates room to redesign the cost model for ultra-long-context serving.
