Sparse Attention at 10 Million Tokens: Why the Indexer, Not Attention, Is the Bottleneck

    As context windows move from millions to tens of millions of tokens, sparse attention alone is no longer enough. This article explains why the indexing step becomes the dominant cost at extreme context lengths, how Latent Sparse Attention moves selection into a compressed latent space with two-stage retrieval, why accuracy holds up, and how to roll out the change layer by layer.

    1. Background: Context Enters the 10-Million-Token Era

    Over the past two years, long context has shifted from an experimental feature to a default specification. Million-token windows first appeared on a few flagship models, then moved down to lighter service tiers. After that, models supporting million-token context began mixing sparse attention with linear attention, producing the now-typical skeleton of a few global layers plus many local or linear layers.

    These designs share the same premise: instead of having every query scan the entire token history, each query selects only a handful of the most relevant tokens to compute against. The approach has been validated repeatedly at the million-token scale. But as context pushes toward 10 million tokens, an overhead that once looked negligible starts to spiral.

    2. The Real Bottleneck: The Indexer, Not Attention Itself

    Take a single global attention layer doing prefill at 10 million tokens. Most of the time 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 runs against intuition.

    The reason lies in how the complexity is structured:

    • Attention computation itself: once sparsified, complexity drops from roughly O(N²) to O(N·k), where k is the number of tokens retained per query, typically only hundreds to a few thousand.
    • The indexing and selection step: with the naive approach of scoring the query against all historical keys at coarse granularity and then taking the top-k, the scoring stage is still O(N²).

    So the nature of the problem has changed. Sparse attention already proved that attending to a small subset is enough to preserve accuracy. What actually blocks extreme context is that finding that subset still grows quadratically with length. When N goes from 10⁶ to 10⁷, attention computation grows only 10x (the linear part), while indexing overhead grows 100x and ends up consuming the entire layer’s runtime.

    Schematically, the logic looks like this:

    1. # Naive sparse attention: cheap to compute, expensive to select
    2. scores = q @ k_all.T # [B, H, N, N] — quadratic; blows up both memory and compute
    3. idx = scores.topk(k, dim=-1) # top-k selection
    4. out = sparse_gather(v, idx) # reads only k values, linear cost

    The step that genuinely needs optimizing is the one in the middle.

    3. Core Idea: Move Selection into Latent Space

    One validated direction is Latent Sparse Attention. The key is not making top-k faster, but making selection stop happening in the original token dimension altogether.

    It can be understood as four parts:

    1. Compressed representation. The key/value of a long sequence is compressed into a set of latent vectors (latent slots) far smaller than N, with compression ratios ranging from tens to over a hundred times. This is not simple average pooling but a learnable aggregation, so each latent vector carries a continuous span of history.
    2. Scoring in latent space. The query computes similarity only against these M latent vectors (M ≪ N), reducing complexity to O(N·M) and turning the quadratic cost into something close to linear.
    3. Two-stage retrieval. First select the top-m latent slots, then run a fine-grained top-k within the subset of original tokens those slots cover. The first stage is coarse, the second fine, and the total cost is far below global scoring.
    4. Working with the hybrid skeleton. Local layers handle fine-grained modeling over short distances, global layers use the latent index for long-range retrieval, and linear layers carry most routine token mixing. With that division of labor, the global layers are also called less often.

    The benefits compound. A single layer’s prefill can be more than 20x faster at 10 million tokens, and models with a larger structural gap can exceed 70x, since the original indexing overhead accounts for a larger share. Meanwhile, because the tokens that ultimately participate in attention are still real tokens, accuracy loss stays small: performance on several long-text retrieval, multi-hop QA, and long-document summarization tasks remains close to the original model.

    4. Why Accuracy Holds Up

    The latent index does not hurt accuracy for three reasons:

    • Retrieval is two-stage. The coarse pass only has to avoid missing the right region; the fine pass handles precise localization. Tolerance for error is split across two layers.
    • Compression is content-adaptive. Latent vectors are learned from data rather than cut on a fixed grid, so information-dense passages can be allocated more slots automatically.
    • Local layers act as a fallback. Nearby information always participates at original resolution, unaffected by compression.

    Two engineering points need attention. First, compatibility between compression block boundaries and positional encoding: relative positions inside a block need to be recalibrated. Second, consistency between training and inference: if latent indexing is enabled at inference but was not used during training, some continued training or distillation is usually needed to align the distributions.

    5. Rollout Recommendations

    • Measure before optimizing. Use monitoring, alerting, and logging services to collect a per-layer time breakdown, confirm that indexing really does exceed attention computation, and only then decide the scope of the change.
    • Change layer by layer. Replace only the few global layers first and leave the rest untouched: lowest risk, highest return.
    • Capacity and parallelism. The compressed latent states are small and can sit on elastic resources in a container platform alongside the batch, combined with tensor or sequence parallelism to split long sequences.
    • Accuracy regression. Build a long-text evaluation set covering retrieval, aggregation, and multi-hop tasks, and track recall as a first-class metric over time.
    • Cost perspective. Faster prefill directly reduces time to first token and compute consumption, with the clearest gains in long-document batch processing.

    6. Conclusion

    At 10 million tokens, the central tension has moved from “too much to compute” to “too slow to find.” Migrating the selection process from the original token space into latent space, and replacing global scoring with coarse-plus-fine two-stage retrieval, is currently the most cost-effective engineering solution. For teams that need to balance latency, cost, and accuracy under extreme context, this path is worth validating first.