Sparse Attention at 10M Token Context: Fixing the Indexer for a 22x Prefill Speedup

    As models move from 1M to 10M token contexts, the bottleneck in sparse attention shifts from computing attention to finding which tokens to attend to. This article explains why the indexer cost grows quadratically, introduces Latent Sparse Attention (LSA) as a low-dimensional retrieval approach, and outlines practical steps for profiling, validation, and deployment. Readers will learn how to attribute the bottleneck, apply LSA-style optimization to global attention layers, and understand the boundaries of single-layer speedups.

    Over the past two years, mainstream large models have gradually made 1M token context a default specification, turning million-token long-text processing from a demo feature into a routine capability. The industry has converged on one approach: instead of having each query traverse all historical tokens, select only a few of the most relevant tokens to participate in computation. This approach has been repeatedly validated at the million-token scale.

    But as the context grows to 10 million tokens, an originally negligible overhead starts to spiral out of control. Take a global attention layer in a hybrid attention model as an example: during prefill (the stage that processes the entire input at once) at 10M tokens, roughly 98% of the time is not spent on the attention computation itself, but on the indexer that decides “which tokens to look at.”

    The nature of the problem has therefore changed: sparse attention has long proven that “looking at only a small subset” is enough to preserve accuracy; what truly blocks ultra-long context is that the cost of “finding that small subset” still grows quadratically with context length.

    2. Why the Indexer Cost Is Quadratic

    The naive sparse attention flow can be abstracted into three steps:

    1. 1. Compute relevance scores between the query and all historical tokens
    2. 2. Select the Top-K most relevant tokens
    3. 3. Compute a weighted sum of attention over only these K tokens

    The third step is linear in cost (dependent on K), but the first step requires scoring every query against every historical token, which is N×N in scale, and the global Top-K selection in the second step also requires traversing all candidates. As a result, even though the attention computation is sparsified, the indexing stage retains the complexity of dense attention.

    At the million-token scale, this quadratic term is masked by constant factors; at 10M tokens, it becomes the dominant term. This is precisely the logic behind gains like “22x faster”: the optimization target is not the attention operator, but the indexer.

    3. Latent Sparse Attention: Moving the Search into a Low-Dimensional Space

    A recent work jointly released by a startup research institution and universities proposes the idea of Latent Sparse Attention (LSA), whose core is to migrate relevance retrieval from the original token space to a compressed latent space:

    • Dimensionality-reduced retrieval: First project the key vectors of historical tokens into a low-dimensional latent representation, then perform scoring and Top-K selection in the low-dimensional space, avoiding full comparison in the original high-dimensional space.
    • Two-stage localization: First coarsely filter a small number of candidate blocks in the latent space, then perform fine ranking on the candidates in the original space, trading controllable accuracy loss for an order-of-magnitude retrieval speedup.
    • Compatibility with hybrid architectures: This idea can serve as a replacement module for global attention layers and be mixed with linear attention, local window attention, and others, without changing the overall model structure.

    The experimental results reported in the paper: at 10M tokens, a hybrid architecture model achieved roughly 22.7x prefill speedup for a single attention layer, while an open-weight model achieved roughly 72.4x speedup, with accuracy comparable to the original model across a series of long-text tasks. It should be emphasized that this is a single-layer, single-stage speedup ratio; the end-to-end gain depends on the proportion of indexer layers among the total number of layers.

    4. Engineering Practice: How to Tell Whether You Have Hit This Bottleneck

    If you are working on long-context inference optimization, you can use the following approach for a quick attribution:

    1. Segmented timing: Break prefill into three separately timed segments—indexing, attention computation, and projection plus MLP—and observe whether the indexing proportion rises with length.
    2. Length sweep: Measure the time of the same layer at 128K / 1M / 4M / 10M; if the indexing time grows noticeably faster than linearly, you have hit the quadratic term.
    3. Accuracy baseline: Fix a set of long-text evaluation sets and record the original model’s outputs as a baseline; any sparsification change must be regression-tested.

    Illustrative pseudocode:

    1. # Illustrates the optimization idea only; not a specific API
    2. def sparse_attention(q, k, v, latent_proj, k_block=64, topk=256):
    3. k_latent = latent_proj(k) # low-dimensional latent representation
    4. block_scores = score_blocks(q, k_latent, k_block) # coarse filtering at much lower cost
    5. cand = select_topk_blocks(block_scores, topk)
    6. return attend(q, k[cand], v[cand]) # fine computation in the original space

    5. Practical Recommendations and Boundaries

    • Prioritize global layers: Local window and linear layers are already linear in complexity with limited gains, so the optimization budget should go to global attention layers.
    • Treat the indexer as a first-class citizen: Traditional profiling habits focus on matrix multiplication, but in ultra-long context scenarios the indexer must be included in the monitoring and optimization list.
    • Validate accuracy layer by layer: The recall loss introduced by coarse filtering must be quantified on specific tasks, especially tasks that require precise retrieval of intermediate details.
    • Cloud deployment perspective: Long-context inference puts enormous pressure on GPU memory and bandwidth; you can combine container platforms for elastic scaling, use monitoring and alerting to track time-to-first-token and throughput, and use logging services to accumulate segmented timing data, forming a closed loop for sustainable tuning.

    Summary: In the 10M token era, the performance bottleneck has shifted from “computing attention” to “finding attention.” Moving retrieval into a low-dimensional latent space is currently one of the most cost-effective directions; whether you can reliably capture the gains depends on first attributing the problem correctly and then validating layer by layer.