Long-Context Scaling to 10M Tokens: How Latent Sparse Attention Speeds Up Prefill
As context windows grow from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to finding which tokens to attend to. This article breaks down the hidden cost of full index scoring, explains how Latent Sparse Attention moves scoring into a low-dimensional latent space with block-level aggregation and candidate refinement to achieve sub-quadratic complexity, and reviews reported prefill speedups of over 20x and up to 70x at the 10M-token scale. It also covers practical evaluation tips on cost attribution, block size and candidate-block tuning, peak memory, prefill versus decode benchmarking, and needle-in-a-haystack accuracy checks.
1. Longer Contexts Change the Cost Structure
Over the past year, long context has shifted from a differentiating feature to a baseline capability. Mainstream model services have progressively made million-token context the default specification, and architecturally they commonly adopt a hybrid of sparse attention and linear attention. The industry consensus is that each query should no longer scan every historical token; instead, it selects a small set of the most relevant ones to participate in computation.
This approach has been validated repeatedly at the million-token scale. But as context pushes toward 10 million tokens, an originally unremarkable overhead starts to spiral. Take a global attention layer as an example: at 10M tokens, prefill spends the majority of its time not on the attention computation itself, but on the indexing step that “decides which tokens to look at.”
The nature of the problem therefore changes: sparse attention has already proven that “looking at only a small subset” is enough to preserve accuracy. What actually blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.
2. The Hidden Bill of Sparse Attention
In standard full attention, every query computes relevance against all previous keys. With context length T, prefill computation is O(T²), and decoding each token is O(T). Going from millions to 10 million tokens increases prefill attention computation by roughly 100x.
The division of labor in sparse attention works like this: a lightweight indexer first selects the k most relevant keys for each query, then the real attention computes only over those k keys, reducing attention itself to O(Tk).
This approach rests on one premise: the model genuinely needs only a few keys. Industry validation shows that at around 100K tokens, letting each query attend to only the truly most relevant few keys (within roughly 1% of all keys) still preserves over 90% of full-attention accuracy on long-context benchmarks.
But here lies a paradox: for the indexer to know which keys are most relevant, it must first score every key. The mainstream sparse approach typically has the query and keys do a dot product after low-dimensional projection, then takes Top-k. Scoring itself can be written as a matrix multiplication and looks cheap, but it is “all against all”: T queries against T keys, still O(T²). When T reaches 10 million, this overhead completely dwarfs attention itself.
Schematically, index scoring can be understood as:
# Pseudocode: full index scoring, scale is T x Tscores = query_index @ key_index.transpose(-1, -2) # [B, H, T, T]topk_idx = scores.topk(k, dim=-1).indices # pick k keys per query
Even if the dimension of query_index is compressed to something very small, the [B, H, T, T] intermediate tensor alone is enough to make memory and bandwidth the bottleneck. This is the source of the “hidden bill.”
3. The Core Idea of Latent Sparse Attention
A recent paper from a startup research team in collaboration with a university introduces Latent Sparse Attention, aiming to push attention overall into the sub-quadratic regime. Its core is not to compress k further, but to change the space in which “scoring” happens.
It can be understood in three layers:
- Low-dimensional latent-space scoring. Instead of having each query explicitly do a full dot product against every key, both queries and keys are mapped into a shared low-dimensional latent space, where relevance is evaluated in an aggregated manner, avoiding explicit construction of the T×T scoring matrix.
- Block-level candidate aggregation. Historical keys are organized into blocks, with a compact representation maintained per block in the latent space. The query first interacts with block-level representations to locate a small number of candidate blocks, then does fine-grained selection within blocks. Scoring thus changes from “query against all keys” to “query against a few blocks,” significantly reducing complexity.
- Decoupling from the main attention. The indexing stage is only responsible for “where to look”; the real attention still computes only over the selected k keys. The accuracy path therefore stays consistent with existing sparse schemes, and the change is concentrated in the indexer.
The shape of this hierarchical selection expressed in pseudocode:
# Pseudocode: block-level latent filtering + within-block Top-kblock_repr = latent_compress(keys, block_size=B) # one compact representation per blockblock_scores = query_latent @ block_repr.transpose(-1, -2) # T x (T/B)cand_blocks = block_scores.topk(nb, dim=-1).indicestopk_idx = refine_within_blocks(query, keys, cand_blocks, k)
The key is that T x (T/B) is smaller than T x T by a factor of block size, and within-block refinement runs only on candidate blocks, bringing the overall complexity down from quadratic to sub-quadratic.
4. Where the Gains Come From
The paper reports that at 10M tokens, a hybrid-architecture model achieves over 20x prefill speedup on a single attention layer, while another model reaches on the order of 70x, all while maintaining accuracy close to the original model across a range of long-context tasks. The engineering implications of these numbers break down as follows:
- The gains come mainly from the indexing side. Since indexing accounts for the majority of prefill time, reducing it from quadratic yields amplified end-to-end gains.
- Gains scale with context length. The longer the context, the more the quadratic term dominates, and the more pronounced the relative advantage of a sub-quadratic approach; at the scale of a few hundred thousand tokens, the gains may not stand out.
- Accuracy is not obtained by sacrificing attention. The method does not reduce k, nor does it change how the main attention computes, so the accuracy risk falls mainly on “whether candidate blocks miss the truly relevant keys.”
5. Key Points for Engineering Adoption
If you want to evaluate this kind of approach in your own inference stack, focus on the following:
- Do cost attribution first. At the target context length, separately measure the time share of attention computation, index scoring, memory access, and communication to confirm whether the bottleneck is truly on the indexing side and avoid optimizing in the wrong direction.
- Block size and candidate-block count are the core hyperparameters. Larger blocks make indexing cheaper but candidate granularity coarser; too few candidate blocks miss recall, while too many shrink the gains. Joint tuning of recall and latency is needed on the target task.
- Watch peak memory, not just compute. The full scoring matrix is a memory killer, and much of the value of sub-quadratic approaches shows up as lower peak memory, which allows larger batches or longer contexts.
- Evaluate prefill and decode separately. Prefill benefits from index optimization, while decode adds only one query per step and is bottlenecked more by key-value cache memory bandwidth; the two need separate benchmarks.
- Accuracy validation must cover needle-in-a-haystack tasks. The risk of index-based sparsity is missing distant key information, so the validation set should include information retrieval across large distance ranges and multi-hop reasoning tasks.
6. Conclusion
The next threshold for long context is not “whether you can look at only a subset,” but “whether you can find that subset cheaply.” Latent Sparse Attention changes indexing from full scoring to block-level aggregation and candidate refinement in a latent space, bringing overall complexity into the sub-quadratic regime and delivering order-of-magnitude prefill speedups at 10M tokens while preserving accuracy. For teams pushing context to longer distances, this suggests a pragmatic optimization order: first quantify index overhead, then rework the index space, and only then adjust attention itself.
