Sparse Attention at 10M Token Context: How Latent Indexing Delivers Up to 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 finding which tokens to attend to. This article explains why the indexer becomes a new quadratic, memory-bound cost, and how Latent Sparse Attention (LSA) moves retrieval into a low-dimensional latent space to decouple selection cost from context length. It covers the reported 22.7x and 72.4x prefill speedups at 10M tokens, accuracy behavior, engineering considerations such as incremental latent maintenance, chunking, quantization, and observability, plus the limits and risks of lossy compression.
1. Long Context Is Shifting the Bottleneck from Compute to Search
Over the past two years, long-context capability has moved quickly from an experimental feature to a default specification. Million-token context is now standard across several model services, and architectures have broadly converged on a hybrid design that combines global attention with sparse or linear attention. The shared logic is straightforward: instead of having each query vector scan the entire token history, the model selects only a small set of the most relevant segments to participate in the computation.
This approach has been validated repeatedly at the million-token scale. But as context grows toward 10 million tokens, an overhead that once seemed negligible starts to spiral out of control. In one model with global attention layers, roughly 98% of prefill time at the 10M-token scale is not spent on the attention matrix multiplications at all. It is spent on the indexer, the component that decides which tokens to look at.
This changes the nature of the problem. Sparse attention has already shown that attending to a small subset is enough to preserve accuracy. What actually blocks extreme long context is that the cost of finding that subset still grows quadratically with context length.
2. Why the Indexer Becomes the New Quadratic Bottleneck
Naive sparse attention can be broken into three steps:
- Compute relevance scores between the query and all historical tokens.
- Select the Top-K most relevant tokens.
- Aggregate attention over only those K tokens.
The complexity of the third step has already been reduced to linear. But the first step still has to touch the entire history. Scoring typically requires an inner product between the query vector and the full set of key vectors, which is O(L·d) (where L is the context length and d is the head dimension). Stacked across multiple layers and heads, the overall cost trends quadratically with length. Worse, this step is a classic memory-bound operation: compute units sit largely idle while data movement becomes the bottleneck.
The source of the cost is clear in illustrative pseudocode:
# Naive implementation: score everything, then filterscores = q @ K.T # [L] scale, grows linearly with contextidx = topk(scores, k=2048) # selection itself must scan everythingout = softmax(scores[idx]) @ V[idx]
When L grows from 1e6 to 1e7, the memory access for the scores line alone increases tenfold, and it sits on the mandatory path of every layer and every attention head.
3. Latent Sparse Attention: Moving the Search into a Low-Dimensional Space
A recent paper from a startup research team in collaboration with universities proposes Latent Sparse Attention (LSA). Its core insight is direct: since the bottleneck is searching over the full original dimension, do not search in the original dimension.
LSA introduces a set of learnable low-dimensional latent vectors (latent tokens, or compression slots) and first compresses the historical keys and values into a latent space far smaller than the context length. The query only needs to compute relevance scores and perform Top-K selection in this low-dimensional latent space, then return to the original tokens to fetch the corresponding keys and values for aggregation.
You can think of it as “build a table of contents first, then read the book”:
- Original sparse attention: flip from the first page to the last page every time to find a keyword.
- LSA: maintain a fixed-length table of contents, locate the chapter there first, then read a few pages closely.
The complexity gains stack from two sources. First, the scoring dimension drops from d to d_latent (typically much smaller than d). Second, the candidate set shrinks from L to a constant-scale size on the order of the number of latent slots. The selection process is therefore approximately decoupled from context length.
Illustrative pseudocode:
# LSA approach: locate in low-dimensional latent space, aggregate in original spacelatent = compress(K, d_latent) # pre-compressed, can be maintained incrementallyscores = q_latent @ latent.T # low-dimensional scoring, scale ~ M (M << L)idx = topk(scores, k=2048) # small candidate set, cheap to scanout = softmax(q @ K[idx].T) @ V[idx] # return to original space for exact aggregation
The key is that the fourth step preserves exact attention in the original dimension, so accuracy loss is confined to “whether the localization is accurate” rather than “whether the computation is coarse.”
4. Measured Gains and Accuracy
The data reported in the paper reflects the effectiveness of this design: at the 10M-token scale, for the prefill stage of a single attention layer, one model with a hybrid attention architecture achieved roughly a 22.7x speedup, while another mainstream open-weight model achieved roughly a 72.4x speedup. At the same time, accuracy on a range of long-context tasks stayed close to the original models.
The large gap between the two numbers is not accidental. It correlates strongly with the efficiency of the model’s original indexer implementation: the closer the original indexer is to the memory-access limit, the larger the relative gain after switching to low-dimensional localization. This also points to a practical lesson: the payoff of an optimization always depends on how bad the component you are replacing is.
5. Engineering Implementation Notes
To borrow this idea in your own inference pipeline, focus on the following:
- Maintain latent state incrementally: build latent vectors during prefill and update them incrementally as new tokens arrive during decode, avoiding re-compression at every step.
- Chunking and parallelism: split history into chunks, compress within each chunk, and score across chunks in parallel, which maps naturally to tensor parallelism and sequence parallelism.
- Memory and bandwidth accounting: latent vectors themselves occupy memory, but far less than the full keys and values; combined with paged key-value cache management, this can significantly reduce fragmentation.
- Coordinate with quantization: low-dimensional scoring is more sensitive to precision, so keep higher precision for latent vectors and use low-bit quantization for the original keys and values.
- Observability: track “indexer time / attention time” as a separate metric in monitoring, alerting, and logging so you can pinpoint where the bottleneck has moved.
- Elastic resources: extreme long-context inference is sensitive to compute and memory fluctuations, so elastic scaling and queue-based scheduling on a container platform can smooth peak pressure.
6. Applicability and Risks
LSA is not free. Compression means information loss. When a task requires precise retrieval over very long distances, such as needle-in-a-haystack localization, latent-space localization may miss targets. Latent vectors introduce additional parameters and training or adaptation costs. The candidate set size K and the number of latent slots M need to be tuned per task. A reasonable strategy is to keep a small number of global “anchor” tokens uncompressed and to fall back to the original sparse path for high-risk layers.
7. Conclusion
In the 10M-token era, the core tension has shifted from “attention cannot be computed” to “candidates cannot be found accurately or affordably.” By moving retrieval into a low-dimensional latent space, Latent Sparse Attention decouples selection cost from context length, delivering order-of-magnitude speedups in extreme long-context prefill while keeping accuracy under control. For platform providers and developers, it is worth including indexer overhead among the first-screen metrics in performance profiling early, and building supporting designs around key-value cache management, quantization strategy, and elastic scheduling.
