Sparse Attention at 10 Million Tokens: Why Indexing Is the Real Bottleneck and How Latent Sparse Attention Delivers a 22x Speedup
As context windows scale from millions to tens of millions of tokens, the bottleneck in long-context inference shifts from computing attention to finding which tokens to attend to. This article explains why the indexing step in sparse attention still scales quadratically, and how Latent Sparse Attention (LSA) moves scoring and top-k selection into a low-dimensional latent space to cut that cost to near-linear. It reports the paper's single-layer prefill speedups of roughly 22.7x and 72.4x, and outlines practical engineering considerations for adopting this approach, including measuring indexer overhead, tuning the latent dimension, adapting hybrid architectures, and running accuracy regression tests.
1. The First Bottleneck in Ultra-Long Context Is Shifting From Compute to Search
Over the past two years, long-context capability has quickly become a default configuration for large model serving. Context windows of a million tokens have moved from being a selling point of a few flagship models to a standard specification in many online services. One of the key technologies enabling this shift is sparse attention: instead of having each query traverse all historical tokens, only a small set of the most relevant tokens is selected to participate in the computation.
This approach has been repeatedly validated at the million-token scale. But as the context grows to tens of millions of tokens, an initially negligible overhead starts to spiral out of control. Take a global attention layer in a certain hybrid architecture model as an example: at the tens-of-millions-of-tokens scale, during the prefill stage, roughly 98% of the time is spent not on the attention computation itself, but on the indexing step that “decides which tokens to look at.”
This means the nature of the problem has changed. Sparse attention has long proven that “looking at only a small fraction” is enough to preserve accuracy. What truly blocks ultra-long context is that the cost of “finding that small fraction” still grows quadratically with context length.
2. Why Indexing Becomes a Quadratic Bottleneck
To understand this, first break down the cost structure of a single attention call. Standard attention requires computing the relevance of each query against all historical keys, with a complexity of O(N²). Sparse attention reduces the number of keys participating in the weighted sum from N to k (where k is much smaller than N), so the computation part drops to O(N·k).
But the problem is this: to select those k keys, you typically still need to compute relevance scores across the board first, then take the top-k. The scoring step is still O(N²), just with a smaller constant and more memory-access-friendly behavior. At a million tokens, this portion is still acceptable; at tens of millions of tokens, the absolute magnitude of N² grows sharply, and the indexer goes from a supporting role to the main character.
The structural difference is clear from the following illustrative pseudocode:
# Traditional sparse attention: computation is saved, selection is notscores = q @ K.T # O(N^2), the real bottleneckidx = topk(scores, k) # O(N log k)out = softmax(scores[idx]) @ V[idx] # O(N*k)
Therefore, the focus of optimization should not remain on “looking at a few fewer tokens,” but on “locating the candidate set at a lower cost.”
3. Latent Sparse Attention: Moving Selection Into a Low-Dimensional Space
A recent paper jointly released by a startup research team and universities proposes the idea of Latent Sparse Attention (LSA). Its core is not to compress k further, but to change the space in which “scoring and selection” happen:
- Dimensionality-reduction projection: First project the query and key into a low-dimensional latent space, perform relevance scoring and top-k selection in that low-dimensional space, reducing the indexing complexity from O(N²) to nearly O(N·d) (where d is the latent dimension, much smaller than N).
- Select in latent space, read in original space: Candidate indices are produced in the low-dimensional space, but the actual key/value retrieval still happens on the original high-dimensional representations, avoiding accuracy loss.
- Complementary to linear attention: Linear attention excels at compressing history, while sparse attention excels at precise retrieval. Combining the two can strike a balance between “remembering the global picture” and “seeing the local detail.”
The paper reports the following results: at the tens-of-millions-of-tokens scale, it speeds up the prefill of a single attention layer in a certain hybrid architecture model by about 22.7x, and speeds up another general-purpose large model by about 72.4x, while maintaining accuracy close to the original model across multiple tasks. It should be emphasized that these are single-operator/single-layer acceleration figures; end-to-end gains depend on model architecture, the proportion of the indexer, and system implementation.
4. Engineering Implementation Notes
To draw on this direction in your own system, consider the following points:
- Measure the indexer proportion first: Use logging services and monitoring alerts to confirm the indexer’s time proportion during the prefill stage. Latent-space selection only makes sense when indexing is the main bottleneck.
- Trade off the latent dimension: A too-small d selects wrong candidates and hurts accuracy; a too-large d degrades back to the original complexity. It is recommended to start from a small value and run ablations.
- Hybrid architecture adaptation: Use sparse retrieval for global layers and linear compression for local layers, avoiding full indexing in all layers.
- Inference framework and compute coordination: Low-dimensional scoring is memory-access-friendly and can be combined with container platform elastic scaling and suitable acceleration hardware to improve throughput.
- Accuracy regression is not optional: Any “selection approximation” must be paired with regression evaluation on long-text tasks, watching for degradation in retrieval-type and multi-hop reasoning metrics.
5. Conclusion
In the era of tens of millions of tokens, the deciding factor in long-context inference has shifted from “computing fast” to “finding accurately and cheaply.” The value of Latent Sparse Attention lies in compressing the quadratic selection cost to near-linear, opening up engineering feasibility for ultra-long context. For developers, understanding the judgment that “indexing is the bottleneck” matters more than memorizing a specific speedup number.
