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

    As context windows scale into the millions, sparse attention has become the default way to keep long-context inference affordable. But at 10 million tokens, the bottleneck shifts: roughly 98% of prefill time in a global attention layer goes to indexing—deciding which tokens to attend to—rather than to the attention math itself. This article explains that shift from compute-bound to index-bound behavior, introduces Latent Sparse Attention (LSA), which moves retrieval into a compressed latent space, and covers its reported speedups, why accuracy holds, and how to roll it out in production.

    Introduction: When Context Reaches the 10 Million Token Scale

    Over the past two years, long context has moved from an optional feature to a default specification for flagship models. Million-token context is now standard in the official services of several cloud providers, and the industry has since begun exploring hybrid attention architectures: some layers keep global attention to preserve information losslessly, while others adopt sparse or linear attention to compress overhead. This route has been validated repeatedly at the million-token scale, and the core consensus is that each query does not need to scan the entire token history—it only needs to select a few of the most relevant segments to participate in the computation.

    But as context pushes on to 10 million tokens, an originally unremarkable cost starts to spiral out of control. Take one global attention layer in a hybrid-architecture model that supports million-token context: when running the prefill stage at the 10 million token scale, roughly 98% of the time is not spent on the attention matrix computation, but on the indexing step of “deciding which tokens to look at.”

    This means 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 truly blocks ultra-long context is that the cost of “finding that small part” still grows quadratically with context length.

    1. The Bottleneck Shifts: From Compute-Bound to Index-Bound

    To understand this change, split the attention layer into two stages.

    The first stage is selection: finding the top-k most relevant historical tokens for each query token. A naive implementation has to compute the similarity between the query and all historical keys, with a complexity of O(N²·d), where N is the sequence length and d is the head dimension.

    The second stage is aggregation: a weighted sum over only the selected k tokens, with a complexity of O(N·k·d). Since k is usually far smaller than N, this stage is linear and its cost is manageable.

    At the million-token scale, the cost of both stages is still acceptable; at the 10 million scale, the N² term completely overwhelms the N·k term. The direct engineering consequence is that the GPU’s compute units sit largely idle, because the indexing stage is a memory-access and irregular-access-intensive task that cannot fully utilize the tensor cores. In other words, sparsification saved compute, but it did not save the time spent on “addressing.”

    2. The Core Idea of Latent Sparse Attention

    A recent paper jointly published by a startup research team in London and a technical university in Zurich proposes Latent Sparse Attention (LSA). Its key insight is: do not perform retrieval in the original token space—move retrieval into the latent space.

    It contains three main points.

    1. Latent-space compression. Project historical keys and values into a low-dimensional latent representation, so redundancy along the sequence-length dimension is heavily compressed and the candidate pool for retrieval shrinks from N to a smaller scale tied to the compression rate.
    2. Coarse localization plus fine-grained reading. First do coarse filtering in the latent space to locate a small number of candidate blocks, then read the tokens within those blocks at original precision. Chaining the two stages brings the indexing complexity down from roughly quadratic to linear or near-linear.
    3. Orthogonal to hybrid architectures. LSA only replaces the “selection” step and does not change the mathematical form of attention, so it can be layered on top of existing sparse/linear hybrid layers without retraining the backbone.

    Illustrative pseudocode:

    1. # Traditional top-k sparse attention: retrieval in the original space
    2. scores = q @ K.transpose(-1, -2) # [B, H, N, N] quadratic
    3. idx = scores.topk(k, dim=-1).indices
    4. out = weighted_sum(q, K, V, idx)
    5. # Latent sparse attention: compress, coarse-filter, then fine-read
    6. Kc = compress(K) # [B, H, M, d_c], M << N
    7. coarse = q @ Kc.transpose(-1, -2) # [B, H, N, M] near-linear
    8. blocks = coarse.topk(b, dim=-1).indices
    9. idx = gather_within_blocks(K, blocks) # precise localization only within candidate blocks
    10. out = weighted_sum(q, K, V, idx)

    3. Performance and Accuracy: Where the Gains Come From

    Public results show that at the 10 million token scale, this class of methods speeds up the prefill of a single global attention layer by about 22.7x (using a million-context hybrid-architecture model as the baseline), while delivering up to 72.4x speedup on another type of medium-sized model that uses only conventional attention, all while maintaining accuracy close to the original model across multiple long-text tasks.

    The difference in the multipliers is not accidental, but determined by the baseline structure: the hybrid architecture has already sparsified most of its layers, leaving the remaining global layers as the weak link, so the gains after optimization are significant; the full-attention baseline has no sparsification at all, so the indexing cost accounts for a larger share and the speedup ratio is therefore larger. This points to an important engineering judgment—the speedup ratio is a relative quantity, and evaluation should focus on absolute latency and throughput rather than a single multiplier.

    Accuracy is preserved thanks to the recall design of the two-stage retrieval: the coarse-filtering stage keeps enough candidate blocks so that the probability of the true top-k tokens falling into the candidate set approaches 1; the fine-reading stage still runs at original precision, avoiding low-dimensional approximation directly contaminating the output.

    4. Engineering Recommendations

    1. Roll out in phases. Enable it first in scenarios with long prefill and short decode, where the gains are most obvious; keep the original path for short requests to avoid the fixed overhead introduced by compression.
    2. Treat the compression rate as a tunable knob. A higher compression rate makes indexing faster but raises recall risk, so evaluate recall against your business corpus rather than looking only at end-to-end metrics.
    3. Tune block size and k jointly. Too small a block inflates the number of candidate blocks, while too large a block brings the fine-reading cost back up; a two-dimensional grid search near the target sequence length is recommended.
    4. Coordinate with caching strategies. Prefix caching and chunked prefill can further amortize the indexing cost; in an inference service built from container platforms and message queues, long requests should be routed to the instance pool with LSA enabled.
    5. Observability first. Bring indexing time, candidate hit rate, and the similarity distribution before and after compression into your logging service and monitoring alerts—only then can you pinpoint the real reason a “speedup falls short of expectations.”
    6. Guard accuracy. Before launch, run regression tests on three task types—long-text retrieval, multi-hop question answering, and long-document summarization—and set clear similarity thresholds.

    5. Limitations and Outlook

    Latent-space compression is sensitive to distribution shift, and cross-domain long documents may require recalibrating the projection; under extremely short contexts, the compression overhead may not pay off; in addition, there is no unified evaluation standard for the recall rate of coarse filtering, so cross-paper comparisons should be made cautiously. Future directions include adaptive compression rates, latent-space retrieval that is consistent between training and inference, and deeper coordination with linear attention layers.

    For developers, the most important shift in mindset is this: the optimization focus for ultra-long context has moved from “computing fast” to “finding accurately and finding cheaply.” Designing indexing as a first-class citizen is the fundamental skill of inference services in the 10 million token era.