Sparse Attention at 10M Token Context: Why the Indexer Becomes the Quadratic Bottleneck
As context windows grow from 128K to 1M and now toward 10M tokens, sparse attention has proven that attending to only a few relevant tokens preserves accuracy. However, the selection step—finding those tokens—still scales quadratically and can consume 98% of prefill time. This article explains why the indexer, not the attention matmul, becomes the bottleneck at extreme context lengths, introduces Latent Sparse Attention (LSA) as a cheaper retrieval backend that moves scoring into a low-dimensional latent space, and outlines practical engineering considerations for adoption. You will learn how LSA achieves 22.7x and 72.4x single-layer prefill speedups at 10M tokens, along with key tuning, memory-access, and accuracy-regression guidance.
1. Long Context Is Shifting the Bottleneck from Compute to Addressing
Over the past two years, long context has moved from 128K to 1M and is becoming a default specification for mainstream model serving. The key technical choice behind this shift is sparse attention: instead of having each query scan all historical tokens, it selects only a few of the most relevant tokens to participate in computation. At the 1M scale, this approach has been repeatedly validated—attending to a small subset barely affects accuracy.
But as context pushes toward 10 million tokens, an originally negligible overhead starts to spiral out of control. In a model with global attention layers, for example, 98% of prefill time at 10M tokens is spent not on the attention matrix multiplications, but on the indexer that decides which tokens to attend to.
The nature of the problem has changed. Sparse attention has already proven that attending to a small subset is sufficient. What truly blocks extreme long context is that finding that subset still grows quadratically with context length.
2. Why the Indexer Becomes the New Quadratic Bottleneck
Attention can be decomposed into two steps:
- Selection: find the top-k relevant tokens for each query.
- Computation: perform attention only over those k tokens.
The computation step has complexity O(N·k), where k is a constant, so it grows linearly with N. The selection step, if implemented naively by scoring a query against all historical keys and then taking top-k, has complexity O(N²). When N grows from 1M to 10M, computation grows 10x, but selection grows 100x, so selection completely dominates.
Illustrative pseudocode:
# Naive sparse attention: selection stage is quadraticscores = q @ K.T # [N, N], infeasible at N=10Midx = topk(scores, k) # pick k tokens per queryout = softmax(q @ K[idx].T) @ V[idx]
Two additional amplifiers compound this in practice: the overhead of top-k sorting itself, and the memory-access cost of gathering the selected tokens from GPU memory or host memory. The larger N is, the more fatal these two factors become.
3. Latent Sparse Attention: Moving the Search into a Low-Dimensional Space
A recent paper from a joint team of a startup research group and a university introduces Latent Sparse Attention (LSA). Its core idea is not to change the attention formula, but to change how addressing works: instead of performing full scoring in the original high-dimensional key space, keys are first compressed into a low-dimensional latent space. Similarity retrieval and top-k selection happen in that latent space, then the corresponding values are fetched from the original space for computation.
The benefits are structural:
- The scoring dimension drops from d to r (r ≪ d), significantly reducing the constant factor of the selection stage.
- The latent space can be paired with approximate nearest neighbor retrieval, approximating O(N²) selection with near-linear cost.
- The computation stage still touches only k tokens, confining accuracy loss to a single question: whether the selection is accurate.
The paper reports that at 10M tokens, a single attention layer’s prefill is sped up by 22.7x (on a model with global attention layers) and 72.4x (on another 27B-class model), while maintaining accuracy comparable to the original model across multiple tasks. Note that these are single-layer prefill speedups; end-to-end gains depend on the number of model layers and the memory-access ratio, and cannot be linearly extrapolated.
4. Engineering Implementation Notes
- The latent dimension r is a critical hyperparameter: too small and selection is inaccurate; too large and it degrades to the original space. Start ablations from d/8.
- The retrieval structure must match the workload: prefill scores a long sequence in one pass, making it suitable for chunking plus approximate retrieval; decode is token-by-token and needs a cached latent-space index to avoid repeated construction.
- Memory access is an invisible wall: even if selection becomes faster, if the top-k gather remains random access, the gains will be eaten up. Prioritize contiguous layouts and prefetching.
- Layered hybrid: use LSA for global layers to preserve long-range dependencies, sliding windows for local layers to preserve fine detail, and linear attention layers to reduce cost, alternating the three by layer.
- Accuracy regression must cover long-range tasks: needle-in-a-haystack, multi-hop question answering, and long-document summarization are all indispensable.
5. Relationship with Existing Approaches
LSA is not a replacement for sparse attention; it gives sparse attention a cheaper retrieval backend. It is orthogonal to linear attention, sliding windows, and hierarchical caching, and can be combined with them. The practical implication for developers is: when your context grows from 1M to 10M, do not rush to add more GPUs—first measure the proportion of the selection stage in prefill. If it exceeds half, optimizing the indexer offers far better returns than optimizing the matmul.
When deploying on the cloud, such capabilities typically rely on container platforms for elastic scaling, object storage for long texts, message queues for peak shaving, and logging plus monitoring with alerting for long-tail latency observation. These are general engineering practices rather than vendor-specific features.
