Sparse Attention at 10 Million Token Contexts: Why the Indexer Becomes the Bottleneck and How Latent Space Fixes It
As context windows scale from millions to tens of millions of tokens, the cost of selecting which tokens to attend to starts to dominate prefill time. This article breaks down why sparse attention shifts the bottleneck to the indexer, explains the core ideas behind Latent Sparse Attention—low-dimensional scoring, block-level candidates, and exact retrieval—and covers the complexity gains, reported speedups, accuracy considerations, and a practical engineering checklist for deployment.
1. The Cost Structure of Long-Context Inference Is Shifting
Over the past two years, long-context capability has moved quickly from an experimental feature to a default specification. Million-token context is becoming a standard configuration for mainstream model serving, and some models now pair million-token context with hybrid architectures that combine sparse attention and linear attention, further reducing the memory and compute pressure of long sequences.
The premise behind this approach is simple: a query vector does not need to scan every historical token. It only needs to select a small set of the most relevant ones to participate in the computation. At the million-token scale, this has been validated repeatedly, with controllable accuracy loss.
But as context keeps pushing toward the 10-million-token range, an overhead that once seemed negligible starts to spiral. Take a global attention layer as an example: at 10 million tokens during the prefill stage, roughly 98% of the time is not spent on the attention matrix multiplications, but on the indexer that “decides which tokens to look at.”
This changes the nature of the problem. Sparse attention has already shown that “looking at only a small fraction” is enough to preserve accuracy. What actually blocks ultra-long context is that the cost of “finding that small fraction” still grows quadratically with context length.
2. Why the Bottleneck Lands on the Indexer
To understand this, split attention into two steps:
- Selection: compute a relevance score between each query and all historical tokens, then pick the top-k.
- Computation: perform a weighted sum over only the selected k tokens.
The scoring in the first step is still fundamentally pairwise interaction between the query and all keys, with complexity O(N²·d). The second step has complexity O(N·k·d). When k is far smaller than N, the second step is no longer the bottleneck, while the first step has not been sparsified at all—it must look at everything before it can decide what to look at.
Schematically, it can be written as:
# Naive sparse attention: the selection stage still scores everythingscores = q @ keys.T # [N, N], O(N^2 * d)idx = scores.topk(k, dim=-1) # select top-kout = weighted_sum(q, keys, values, idx) # O(N * k * d)
When N grows from 1e6 to 1e7, the first term grows by roughly 100x, while the second grows by only 10x. The “indexing” step goes from a supporting role to the main character—and this is the fundamental reason the speedup can be amplified in 10-million-token scenarios.
3. The Core Idea of Latent Sparse Attention
A recent paper from a startup research team in collaboration with universities proposed the idea of Latent Sparse Attention: instead of performing selection in the original token space, first compress the keys/values into a low-dimensional latent space, complete relevance scoring and top-k selection in that latent space, then map the selected latent representations back to the original space to participate in the computation.
The key abstractions can be summarized in three points:
- Low-dimensional scoring: use a low-rank projection to compress keys into latent vectors, and perform scoring in the low-dimensional space, reducing the cost of a single interaction from d to r (r far smaller than d);
- Block-level candidates: filter candidates by block in the latent space, avoiding the quadratic term of per-token scoring;
- Exact retrieval: perform exact attention only on the original tokens within candidate blocks, keeping the output distribution close to the original model.
Pseudocode sketch:
# Latent selection: low-dimensional scoring + block-level candidates + exact retrievalh_keys = keys @ W_down # [N, r], r << dblock_scores = score(q @ W_down, h_keys.reshape(num_blocks, block, r))cand = block_scores.topk(k_blocks) # candidate blocksout = exact_attention(q, keys, values, cand) # exact computation only within candidates
4. Where the Gains Come From: Complexity and Measured Speedups
From a complexity standpoint, the selection stage drops from O(N²·d) to roughly O(N·r) or O(N·block·r), and the overall cost degrades from quadratic to near-linear. This explains why, at the 10-million-token scale, single-layer prefill across different models can achieve speedups on the order of 20x to 70x—the larger the base, the more significant the eliminated quadratic term.
There are two additional engineering benefits: first, low-dimensional scoring is friendlier to memory bandwidth; second, block-level candidates naturally fit chunked prefill and parallel scheduling. Note that these speedup figures are measured at the “single attention layer” level, and end-to-end gains will be diluted by other layers and communication overhead, so evaluation should be based on the complete inference pipeline.
5. Why Accuracy Holds Up
The sparse approach relies on two empirical facts: attention distributions are highly concentrated, with a small number of tokens contributing the vast majority of the weight; and relevant information tends to cluster in blocks. The latent-space approach adds a safeguard on top of this—the latent space is used only for “coarse filtering,” and the final computation is still performed exactly on the original tokens, so compression does not directly lose detail.
Practical recommendations:
- Keep a small number of global/sliding-window tokens to prevent long-range information from being missed;
- Tune candidate block size and k per task; the optimal values differ between long-document QA and code completion;
- For numerically sensitive tasks, run a small-scale comparison evaluation before scaling up.
6. Engineering Deployment Checklist
- Layered strategy: use sparse attention for global layers and sliding-window or linear attention for local layers; a hybrid architecture is more stable;
- Chunking and caching: candidate block indexes can be cached and reused, and combined with paged key-value caching to reduce memory fragmentation;
- Observability: instrument “selection time / computation time” separately to pinpoint the real bottleneck;
- Cloud deployment: container platforms host the inference service, object storage holds long-context corpora, and logging services with monitoring and alerting track time-to-first-token and throughput;
- Evaluation baseline: use the original model as the control, covering scenarios such as long-document retrieval, multi-hop QA, and code understanding.
7. Conclusion
In 10-million-token scenarios, the core tension has shifted from “being able to compute” to “selecting accurately and quickly.” Moving the selection process into a low-dimensional latent space, coarse-filtering at block granularity, and then returning to the original space for exact computation is currently the most cost-effective path forward. For developers, the real action item is: first quantify the indexer’s share of the time, then decide the priority of sparsification work.
