Sparse Attention at 10M Token Contexts: Cutting Indexing Overhead by Up to 72x

    As context windows scale from 128K to 1M and beyond, sparse attention keeps accuracy in check, but the indexing step that decides which tokens to attend to still grows quadratically. This article breaks down why the indexer—not the attention math—becomes the first-order bottleneck at 10M tokens, introduces Latent Sparse Attention (LSA) and its low-dimensional retrieval approach, and outlines a practical workflow for measuring, integrating, and regression-testing these methods in production.

    1. The First-Order Bottleneck in Long Contexts Is Search, Not Compute

    Over the past two years, long-context capability has moved quickly from 128K to 1M, and it is becoming the default specification for mainstream model serving. One of the key technologies behind this shift is sparse attention: instead of having every query traverse all historical tokens, each query selects only a few of the most relevant segments to participate in the computation. At the 1M scale, this idea has been validated repeatedly—accuracy stays largely under control, and performance remains stable on long-document retrieval, summarization, and code understanding.

    But as the context grows to 10 million tokens, an overhead that once seemed negligible starts to spiral. Take one global attention layer in a hybrid-architecture model as an example: during prefill 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 changed. Sparse attention has long proven that “looking at only a small part” is enough to preserve accuracy. What actually blocks ultra-long contexts is that the process of finding that small part still grows quadratically with context length.

    2. Why the Indexer Becomes a Quadratic Bottleneck

    Naive sparse attention can be broken into three steps:

    1. Compute the similarity between the query and all historical tokens (scoring);
    2. Select the Top-K most relevant tokens from those scores;
    3. Perform a weighted sum of attention over only those K tokens.

    Step 3 costs O(N·K) and grows linearly with length, which is very friendly. The problem lies in steps 1 and 2: scoring requires evaluating N tokens one by one, and every query has to repeat this, bringing the overall complexity back to O(N²). When N grows from 1M to 10M, the absolute time of the indexing stage increases by roughly 100x, while the attention computation grows by only 10x. So “search” completely overwhelms “compute.”

    Schematically, the cost structure can be written as:

    1. Total time ≈ indexing overhead O(N² · d_index) + attention overhead O(N · K · d_head)
    2. At N = 10M, the former dominates, accounting for over 95%

    This explains why simply increasing K or optimizing the attention kernel yields limited gains: the optimization target accounts for only 2% of the time.

    3. The Core Idea of Latent Sparse Attention (LSA)

    A recent paper by a startup research lab and a university proposed Latent Sparse Attention (LSA). Its key insight is: do not perform retrieval in the original token space; first project into a low-dimensional latent space and do the “search” there.

    It can be summarized in three modifications:

    • Reduced-dimension retrieval: Compress the query and historical tokens into a unified latent space and evaluate similarity with low-dimensional vectors, substantially reducing the constant factor of the indexing stage;
    • Coarse candidate filtering + fine selection: Quickly narrow down candidate blocks in a highly compressed latent space, then perform fine-grained scoring within those blocks, avoiding one-by-one evaluation of all tokens;
    • Coordination with linear attention: Global layers handle low-frequency, long-range information, while linear/local layers handle high-frequency details, reducing how often global layers are invoked while preserving accuracy.

    The result: at 10M tokens, prefill for a single attention layer is sped up by about 22.7x in one hybrid-architecture model and about 72.4x in another general-architecture model, while maintaining accuracy close to the original model across a range of tasks. Note that this speedup is for “single-layer prefill”; end-to-end gains depend on the proportion of global layers and the engineering implementation.

    4. Engineering: How to Evaluate and Integrate

    For developers, adopting an LSA-style approach can proceed in the following order:

    1. Measure first, then optimize: Use monitoring, alerting, and logging services to collect per-stage prefill timings and confirm whether the indexer is truly the dominant cost (rule of thumb: if it accounts for more than 50%, it is worth reworking).
    2. Layered design: Identify which layers are global and which are local/linear; global layers are the main source of LSA gains.
    3. Keep interfaces stable: Abstract the retrieval module as a replaceable component with unchanged input/output contracts, making canary rollouts and rollbacks easier.
    4. Accuracy regression: Build regression sets for long-document retrieval, multi-hop question answering, and code completion, and watch for the “lost in the middle” problem.
    5. Capacity and cost: Combine elastic scaling on container platforms with object storage for long-text corpora to avoid memory and bandwidth becoming new bottlenecks.
    1. # Pseudocode: two-stage latent retrieval
    2. def lsa_select(q, kv_latent, block_index, k):
    3. # Stage 1: block-level coarse filtering in latent space
    4. cand = block_index.topk(q @ kv_latent.T, k=k * 8)
    5. # Stage 2: fine-grained scoring within candidate blocks
    6. scores = [score(q, kv_latent[i]) for i in cand]
    7. return topk_indices(scores, k)

    5. Conclusion

    The competition over 10M-token contexts is shifting from “can we compute it” to “can we quickly find the part worth computing.” The value of LSA is that it moves retrieval from the original token space to a low-dimensional latent space, pushing the quadratic bottleneck back toward near-linear. For engineering teams, the real payoff is not a single speedup number, but a complete methodology: measure indexing overhead first, then rework retrieval in layers, and finally run accuracy regression. On general-purpose compute and storage capabilities such as those offered by Baidu AI Cloud, this methodology can be reused directly for long-document understanding, code-base question answering, and multi-turn memory scenarios.