Sparse Attention at 10M Token Context: Solving the 22x Speedup Bottleneck with Latent Space Retrieval
As context windows scale from 1M to 10M tokens, the main cost of sparse attention shifts from computing attention to selecting which tokens to attend to. This article explains why the quadratic overhead persists in the indexer, introduces Latent Sparse Attention (LSA) and its two-stage retrieval design, and covers accuracy preservation, engineering considerations, and evaluation criteria for long-context inference.
1. The Bottleneck Has Changed: From “Too Much Compute” to “Too Hard to Find”
Over the past two years, mainstream long-context models have converged on a common idea: instead of having each query scan the entire token history, select only a few of the most relevant tokens for computation. This approach has been repeatedly validated at the 1M token scale and has become a common default specification for long-context serving.
But when the context grows to 10 million tokens, an overhead that once seemed negligible starts to spiral. Take a global attention layer in a hybrid architecture model as an example: during prefill at 10M tokens, most of the time is not spent on the attention computation itself, but on the indexer that decides which tokens to look at.
This means the nature of the bottleneck has shifted:
- The early bottleneck was the attention matrix computation, which grows quadratically with sequence length.
- After sparsification, the computation is reduced to near-linear.
- However, the step of “choosing which tokens” still implicitly requires scanning and scoring the full history, so the quadratic cost has not truly disappeared—it has just moved elsewhere.
In other words, sparse attention has proven that “looking at only a small subset” is enough to preserve accuracy. What really blocks ultra-long context is that “finding that small subset” remains expensive.
2. Where the Quadratic Overhead Actually Hides
To understand the value of the new method, let’s break down the indexing stage. A typical sparse attention layer performs selection in roughly four steps:
- Compute a query-matchable representation for each historical token (a key-side summary).
- Compute a dot product or equivalent score between the current query and that representation.
- Select the top-k indices.
- Aggregate attention only over the selected tokens.
Step 4 is linear, but steps 2 and 3 must run over the full history. With sequence length N, number of layers L, and number of heads H, the total indexing overhead is on the order of O(L·H·N·d). During prefill, as N grows from 1M to 10M, combined with the constants from multiple heads and layers, indexing becomes the dominant cost by far.
Schematically, the time for this layer can be decomposed as:
T_layer ≈ T_index(N, d, H) + T_attend(k, d, H)where k << NWhen N reaches the tens of millions, T_index can account for over 90%
The conclusion is straightforward: as long as indexing is still performed at the original token granularity and original dimensionality, no top-k strategy can escape a linear scan over the full history, and with multiple layers and heads stacked together, the overall behavior looks quadratic.
3. The Core Idea of Latent Sparse Attention
A recent paper jointly released by a startup research team and a university introduces Latent Sparse Attention (LSA). Its starting point is not to make k smaller, but to move the entire “selection” process into a low-dimensional latent space.
The core idea can be summarized in three points:
- Dimensionality-reduced summary: instead of using full-dimensional keys for scoring, historical tokens are compressed into low-dimensional latent representations, and indexing happens only in this small space.
- Space decoupling: the indexing dimension d_latent is much smaller than the original dimension d, significantly reducing the constants in scoring and sorting.
- Two-stage retrieval: first, coarse-filter candidate blocks in the latent space, then perform fine-grained top-k in the original space, avoiding a “full scan of the original space.”
The structure can be expressed in pseudocode:
# Precomputation stage: compress history into the latent space (can be jointly optimized with model training)latent = compress(history_keys) # shape: [N, d_latent], d_latent << d# Selection stage for each queryq_lat = project(query) # project into the same latent spacecoarse = topk(score(q_lat, latent), kc) # coarse filtering, complexity O(N * d_latent)fine = topk(score(query, keys[coarse]), kf) # fine selection, complexity O(kc * d)out = attend(query, keys[fine], values[fine])
The key point is that although the coarse filtering stage is still linear in N, the dimensionality is very small; the fine selection stage operates only on a small candidate set. The actual time of the two multiplied together is far lower than scoring the full history in the original dimensionality.
4. Why Accuracy Is Preserved
A long-standing criticism of sparse attention is that it “misses key information.” LSA’s accuracy preservation logic rests on three design choices:
- Training integration: latent space compression is not post-processing but is jointly trained with the main model, so the indexer learns “which information matters for subsequent generation” rather than merely performing geometric approximation.
- Recall from coarse filtering: the number of candidate blocks kc is tunable, and the goal of the coarse filtering stage is high recall—better to keep more candidates than to wrongly discard them in the first step.
- Precision from fine selection: the tokens that ultimately participate in attention are still the top-k in the original space, so semantic details are not smoothed away by low-dimensional compression.
This explains a common observation: on tasks such as long-document retrieval, multi-hop question answering, and code repository understanding, the method can maintain accuracy close to the original model while achieving significant speedup, rather than trading a noticeable accuracy drop for speed.
5. Engineering Implementation Notes
If you want to evaluate similar ideas in your own inference stack, consider the following engineering details:
- Caching strategy: latent space summaries can be persisted alongside the KV cache to avoid repeated compression; watch the trade-off between memory and bandwidth.
- Batching and paging: long-context prefill is usually processed in blocks, so coarse filtering should support block-level incremental updates rather than recomputing from scratch each time.
- Numerical stability: the distribution of dot products changes after low-dimensional projection, so pay attention to scaling and overflow before softmax.
- Compatibility with parallelism strategies: the indexing stage has low communication volume and is well suited to combine with sequence parallelism and expert parallelism to reduce cross-device synchronization.
- Observability: bring indexing time, candidate hit rate, and top-k truncation rate into monitoring, alerting, and logging so you can pinpoint whether the speedup is actually taking effect.
For cloud deployment, you can typically combine a container platform to host inference services, object storage to store models and caches, and a message queue to smooth request spikes, while using a monitoring and alerting system to observe tail latency.
6. Evaluation and Selection Recommendations
When evaluating this type of solution, do not look only at single-point throughput. It is recommended to build a three-dimensional evaluation:
- Speed dimension: report the proportion of indexing time and attention time separately to confirm whether the bottleneck has truly shifted.
- Accuracy dimension: cover tasks such as retrieval, multi-hop reasoning, long-document summarization, and repository-level code understanding, and observe tail samples.
- Cost dimension: measure compute and memory usage per token to assess service feasibility at the tens-of-millions context scale.
A practical selection criterion: if your business context stays in the hundreds of thousands of tokens over the long term, a conventional sparse solution is sufficient; only when the context stably enters the million-to-ten-million range and indexing becomes the dominant cost will the benefits of latent space retrieval methods be amplified.
7. Conclusion
The competition in long context is shifting from “can you fit it in” to “how fast can you find it once it’s in.” When indexing becomes the main cost, there is limited room for further optimization at the original token granularity; moving the selection process into a low-dimensional latent space, decoupling indexing from sequence length and model dimensionality, is a currently validated and effective technical path. For developers, understanding this bottleneck shift matters more than memorizing a particular speedup number.
