The Key to 22x Faster Sparse Attention at 10M Token Contexts

    As language models push context windows from one million to ten million tokens, sparse attention remains the standard way to keep compute manageable, but a new bottleneck has emerged: the indexer that decides which tokens to attend to. This article explains why that selection step scales quadratically and dominates prefill time at extreme context lengths, then introduces Latent Sparse Attention (LSA), which moves candidate selection into a low-dimensional latent space to reduce indexing cost from O(n²) to near-linear. It covers the three-step mechanism, complexity comparison, reported speedups of roughly 22.7x and 72.4x at 10M tokens with preserved accuracy, and practical guidance on measuring bottlenecks, tuning latent dimension and k, managing memory, integrating with hybrid architectures, and building accuracy regression baselines.

    The Key to 22x Faster Sparse Attention at 10M Token Contexts

    1. Background: Cost Structure Changes Once Contexts Pass 10M Tokens

    Over the past two years, mainstream large models have gradually turned 1M (one million) token context into the default specification of official services. By 2025, million-token context had shifted from a “demo feature” to “standard configuration,” and scenarios such as long-document question answering, cross-repository code understanding, and long-session memory began to be designed around millions of tokens by default.

    The key technical choice supporting this shift has been highly consistent: instead of having each query traverse all historical tokens, only a few of the most relevant tokens are selected to participate in computation. This is the basic idea of sparse attention. It has been repeatedly validated at the million-token scale: as long as the selection is accurate, precision is almost unaffected, while computation can be reduced significantly.

    But when the context keeps expanding to 10 million (10M) tokens, an originally unremarkable overhead begins to spiral out of control.

    Take a model with global attention layers as an example. At 10M token scale, during prefill (the stage that processes the entire input at once), measurements show that roughly 98% of the time is not spent on the matrix operations of attention itself, but on the indexer that “decides which tokens to look at.” In other words, the real compute hog is not attention, but “finding where attention should look.”

    The nature of the problem therefore changes completely:

    • Sparse attention has long proven that “looking at only a small portion” is enough to preserve precision;
    • What truly blocks ultra-long contexts is that “finding that small portion” itself still grows quadratically with context length.

    2. Complexity Perspective: Why the Indexer Becomes the Bottleneck

    The compute and memory overhead of standard attention scales as O(n²) with sequence length n. Sparse attention reduces the “computation” term to O(n·k), where k is the number of tokens each query actually attends to (usually far smaller than n). This step yields enormous gains.

    But many sparse schemes introduce a new quadratic term in the “selection” stage:

    1. total cost ≈ selection cost + computation cost
    2. ≈ O(n²) + O(n·k) # naive approach: every query scores against all history

    When n = 10M and k is a few thousand, O(n·k) is relatively manageable, while the O(n²) selection cost overwhelms everything. This explains why “98% of time spent on the indexer” is not an implementation bug but an inevitable result at the methodology level.

    Three common mitigation approaches in engineering each have their limits:

    1. Chunking + local windows: split the sequence into chunks and select only within a chunk or between adjacent chunks. Simple to implement, but sacrifices long-range dependencies.
    2. Compressed summaries (summary/pivot tokens): compress history into a few representative tokens before scoring. This reduces n, but compression itself loses information, and compression quality sets the upper bound.
    3. Low-rank/hash approximate scoring: use approximate nearest-neighbor structures to accelerate retrieval. High engineering complexity, with recall and latency requiring repeated tuning.

    All of these optimize “how to search faster in the original token space,” but none break out of the premise that “candidate set size = n.”

    3. Core Idea: Move “Selection” into Latent Space

    A recent study jointly released by a London startup and a Zurich university proposes Latent Sparse Attention (LSA). Its key judgment is: do not perform retrieval in the original token space, but first construct a low-dimensional latent space and let “selection” happen there.

    It can be understood in three steps:

    Step one, build latent representations. Compress the key/value of a long sequence into a latent vector sequence via a set of learnable projections. The length remains n, but each vector’s dimension is significantly smaller than the original head dimension. This step is a linear transformation costing O(n·d).

    Step two, score and select in latent space. The query is likewise projected into latent space and dot-producted with the latent sequence to get relevance scores, then top-k is taken. Because the dimension is reduced and scoring is a single linear scan, the selection cost drops from O(n²) to nearly O(n·d_latent).

    Step three, return to the original space for sparse attention. Full attention is executed only on the selected k original tokens, ensuring precision does not degrade due to compression.

    Illustrative pseudocode:

    1. # n: sequence length, d: original dimension, dl: latent dimension, k: number selected
    2. latent = proj_k(K) # [n, dl] linear compression
    3. score = (proj_q(Q) @ latent.T) # [n, n] but each dot product is only dl dims, tiny constant
    4. idx = topk(score, k) # each query selects k
    5. out = sparse_attention(Q, K, V, idx) # compute only k, precision aligned with original model

    The complexity comparison can be written intuitively as:

    1. naive sparse: O(n²) selection + O(n·k) computation
    2. LSA: O(n·dl) selection + O(n·k) computation # dl << n

    In one sentence: LSA does not reduce “how much to look at,” but lowers “how to find it” from quadratic to near-linear.

    4. Results and Precision: Why Speedups Reach 22x or Even 72x

    Public results show that at 10M token scale, a model with a hybrid attention architecture achieves roughly 22.7x prefill speedup for a single global attention layer; switching to another model of different scale and architecture, the speedup reaches about 72.4x. Meanwhile, across a range of long-context tasks, precision stays close to the original model.

    The reason the two numbers differ so much is that the “indexer proportion” itself varies by model:

    • The more global attention layers, the larger the head dimension, and the more conservative the k, the higher the indexer proportion, and the more dramatic LSA’s speedup;
    • If a model is dominated by local window attention, the indexing overhead proportion is low, and the speedup naturally falls back.

    This also gives a practical rule of thumb: speedup ≈ 1 / (1 − indexer time proportion). When the proportion reaches 98%, the theoretical ceiling is on the order of 50x, and the measured 22–72x is entirely within a reasonable range.

    Precision holds because compression is used only for “candidate screening,” while the final computation is still done on the original representations. This is like replacing an expensive “full precise computation” with a cheap “coarse filter”: as long as the coarse filter’s recall is high enough, the final result is nearly identical to full attention.

    5. Engineering Implementation Notes

    If you want to evaluate such schemes in your own inference pipeline, focus on the following:

    1. Measure first, optimize second. Use monitoring alerts and logging services to collect per-stage prefill timing, confirm whether the indexer is truly the bottleneck, and avoid optimizing in the wrong direction.
    2. The latent dimension dl is a key hyperparameter. Too small gives insufficient recall and drops precision; too large degrades back to the original overhead. Start grid search from 1/8 to 1/4 of the head dimension.
    3. Scheduling strategy for k. A hybrid strategy of “fixed k + increasing by layer” can be used: shallow layers focus on local with small k; deep layers need global with large k.
    4. Memory and bandwidth. The latent sequence needs to be additionally resident, so plan capacity alongside the KV cache; when doing elastic scaling on a container platform, count latent memory into the single-card budget.
    5. Coordination with linear attention/hybrid architectures. In hybrid architectures, enable latent-space selection only for global layers and keep local layers unchanged, for maximum gain and minimal change.
    6. Accuracy regression baseline. Build a regression set with tasks like long-document retrieval, multi-hop question answering, and cross-file code completion, and run it on every tuning pass to prevent “faster but quietly dropping points.”

    6. Conclusion

    In the era of ten-million-token contexts, the competitive focus of sparse attention has shifted from “computing fast” to “finding fast.” By migrating candidate screening to a low-dimensional latent space, Latent Sparse Attention compresses the originally quadratic indexing overhead to near-linear, achieving over 22x prefill speedup per layer at 10M tokens while preserving precision. For teams building ultra-long-context capabilities, this points to a clear engineering path: first use observability to locate indexing overhead, then replace full precise computation with latent-space coarse filtering, and finally hold the line with strict accuracy regression. On platforms such as Baidu AI Cloud, this kind of optimization can be combined with general capabilities like object storage, message queues, container platforms, logging services, and monitoring alerts to form an operable, observable long-context inference solution.