Sparse Attention at 10 Million Tokens: The Critical Path to a 22x Speedup

    As context windows scale from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from the attention computation itself to the indexer that decides which tokens to attend to. This article explains why that indexer becomes a new quadratic cost, and how Latent Sparse Attention moves relevance scoring into a low-dimensional latent space to achieve subquadratic complexity. It covers the cost structure of standard and sparse attention, the core idea behind latent-space scoring, why low-dimensional selection preserves accuracy, and practical guidance for deployment, including workload fit, block-sparse coordination, memory bandwidth, accuracy regression, and gradual rollout. Reported results include roughly 72x and 22x prefill speedups on specific models, with the caveat that real-world performance depends on your own testing.

    Introduction: At 10 Million Tokens, the Bottleneck Moves

    Over the past two years, long-context capability has shifted from an experimental feature to a default specification. Context windows at the million-token level are now a baseline configuration for several model providers, and hybrid architectures that combine sparse and linear attention have become a routine choice for mainstream models. These designs share the same premise: instead of having every query scan all historical tokens, each query selects only a few of the most relevant keys for computation.

    That premise has been validated repeatedly at the million-token scale. But as context length pushes toward ten million tokens, an overhead that once seemed negligible starts to spiral. In one global attention layer, for example, roughly 98% of prefill time at the ten-million-token scale is spent not on attention itself, but on the indexer that decides which tokens to look at.

    The nature of the problem has therefore changed. Sparse attention has long shown that attending to a small subset is enough to preserve accuracy. What actually blocks ultra-long context is that finding that small subset still costs quadratic growth with respect to context length.

    1. Where the Hidden Bill of Sparse Attention Comes From

    Start with the cost structure of attention. In standard full attention, every query computes relevance against all previous keys: with context length T, prefill cost is O(T²), and decoding each token costs O(T). Going from one million to ten million tokens increases prefill attention computation by roughly 100x.

    Sparse attention divides the work: a lightweight indexer first picks the k most relevant keys for each query, and the actual attention then computes only over those k keys, reducing attention itself to O(Tk).

    This approach rests on one assumption: the model truly needs only a few keys. Industry validation shows that at 128k tokens, letting each query attend to only the 512 most relevant keys (about 0.8% of all keys) still preserves roughly 98% of full-attention accuracy on long-context benchmarks.

    But a paradox hides here: for the indexer to know which 512 keys are most relevant, it must first score every key. Common mitigations include lowering scoring precision, compressing dimensions, and aggregating multiple keys into a block. These reduce the constant factor but do not change the order of magnitude: the number of scoring operations still grows with T². The indexer itself becomes the new quadratic bottleneck.

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

    A recent paper titled “Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention,” jointly proposed by a startup in London and a technical university in Zurich, takes the core idea of moving relevance judgment from the original token space into a latent space.

    The key observation is that judging whether two tokens are relevant does not necessarily require their full high-dimensional representations. Keys and queries can first be projected into a low-dimensional latent space, where scoring and Top-k selection are performed; the original indices are then used to fetch the actual keys for attention. Because scoring and ranking happen in the low-dimensional space, the cost of the indexing stage drops from growing with T² to growing nearly linearly with T, achieving subquadratic complexity overall.

    Illustrative pseudocode (structure only, not a specific implementation):

    1. # 1) Low-dimensional projection: reduce the cost of scoring
    2. q_latent = proj_q(q) # [T, d_latent], d_latent << d_head
    3. k_latent = proj_k(k) # [T, d_latent]
    4. # 2) Latent-space scoring + Top-k selection (subquadratic)
    5. idx = topk(score(q_latent, k_latent), k=k) # [T, k]
    6. # 3) Use the original indices to fetch the actual key/value for attention
    7. attn = sparse_attention(q, k[idx], v[idx])

    The paper reports that at ten million tokens, the method speeds up prefill for a single attention layer of a 27B-class model by roughly 72x, and speeds up another model using a hybrid attention architecture by roughly 22x, while maintaining accuracy close to the original model across multiple long-context tasks. Note that such numbers are results under specific models, specific hardware, and specific implementations; engineering deployment should rely on your own stress tests.

    3. Why Low-Dimensional Scoring Does Not Hurt Accuracy

    A natural question is whether the keys selected in the low-dimensional space are still the most relevant keys in the original space. The paper and subsequent discussion offer three explanations:

    1. Relevance judgment is inherently low-rank. The associations that actually matter in the attention matrix tend to concentrate in a few directions, and many dimensions in the high-dimensional representation contribute little to “who to select.”
    2. Two-stage decoupling. The indexing stage only pursues recall, not exact ranking; as long as the Top-k covers the truly important keys, the subsequent full-dimensional attention automatically completes fine-grained weighting.
    3. Error can be compensated. After the projection matrices are jointly trained with the model or lightly fine-tuned, the ranking consistency between low-dimensional scoring and full-dimensional scoring improves significantly.

    4. Key Points for Engineering Deployment

    • Prioritize suitable scenarios: the biggest gains come from offline batch processing and document-level understanding tasks with a high prefill share, extremely long context, and large per-request token counts.
    • Coordinate with block sparsity: low-dimensional scoring can be combined with block-level aggregation to further compress the indexing constant.
    • Balance memory and bandwidth: at ten million tokens, read/write bandwidth for the KV cache often becomes a hidden bottleneck and needs to be addressed together with paged caching, quantization, and other techniques.
    • Guard accuracy: run regression on long-context benchmarks before launch, focusing on recall for “needle in a haystack” retrieval tasks and multi-hop reasoning tasks.
    • Gradual rollout: enable the feature for ultra-long requests first, then ramp up gradually based on hit rate and latency percentiles.