Sparse Attention at 10 Million Tokens: How Latent-Space Retrieval Delivers a 22x Prefill Speedup

    As context windows move from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to finding which keys to attend to. This article breaks down the cost structure of prefill and decoding, explains why traditional block-sparse indexing still scales quadratically, and shows how latent-space sparse attention compresses keys into a fixed set of latent states to make retrieval near-linear. It covers reported speedups, why accuracy is preserved, and practical guidance for layered design, KV cache reuse, hybrid linear attention, capacity planning, and regression testing.

    Introduction: The Context Length Race Enters the 10 Million Token Era

    Long context has shifted from a differentiating feature to a default specification of infrastructure tooling. Million-token context is now a standard configuration across several general-purpose LLM services, and hybrid architectures combining sparse and linear attention are widely adopted. The industry has converged on one idea: instead of having every query vector scan the entire token history, select only a small set of the most relevant keys for computation.

    That approach has been validated repeatedly at the million-token scale. But as context pushes toward 10 million tokens, an initially negligible cost starts to spiral. Take a single global attention layer: at 10 million tokens, 98% of prefill time is not spent on attention computation at all, but on the indexing step that decides which tokens to look at.

    The nature of the problem has therefore changed. Sparse attention has already proven that attending to a small subset is enough to preserve accuracy; what actually blocks ultra-long context is that finding that subset still grows quadratically with context length.

    1. Cost Breakdown: Where Attention Overhead Actually Goes

    In standard full attention, every query computes relevance against all preceding keys. With context length T, prefill cost is O(T²) and each decoded token costs O(T). Going from one million to 10 million tokens increases attention computation roughly 100x.

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

    This works under one premise: the model genuinely needs very few keys. Existing validation shows that at 128k tokens, letting each query attend to only its 512 most relevant keys (about 0.8% of all keys) still retains roughly 98% of full-attention accuracy on long-context benchmarks.

    But this hides a paradox: for the indexer to know which 512 keys are most relevant, it must first score every key. Common cost-reduction tactics in the industry include lowering scoring precision, compressing dimensions, and aggregating multiple keys into a single representative. These only change constant factors, however; indexing complexity remains O(T²). A 10x increase in context means a 100x increase in indexing overhead, and the indexer ends up consuming nearly all the time.

    2. The Breakthrough: Moving Retrieval into Latent Space

    Recent research on sub-quadratic attention for ultra-long context offers a new answer: latent-space sparse attention. The core idea is not to keep optimizing scoring, but to change the space in which retrieval happens.

    The key observation is that keys are highly redundant in distribution, and the information that actually determines relevance can be compressed into a low-dimensional representation. The flow becomes: first encode the entire key sequence into a set of fixed-length latent states, let the query match only against those latent states, then perform fine-grained ranking over the original keys once a candidate region is located.

    Illustrative pseudocode:

    1. # Traditional block sparse: scoring complexity O(T^2 / block)
    2. scores = q @ keys.T # score all keys
    3. topk = scores.topk(k)
    4. # Latent-space sparse: compress first, then retrieve
    5. latent = encoder(keys) # O(T), built once
    6. coarse = q @ latent.T # O(T * m), m = number of latent states
    7. region = coarse.topk(blocks) # candidate blocks
    8. topk = refine(q, keys[region]) # rerank candidates only

    Because the number of latent states m is far smaller than T and can be built in linear time, overall complexity drops from quadratic to near-linear. That is where “sub-quadratic” comes from.

    3. Results and Accuracy: Why 22x Faster Without Losing Quality

    Public results show that at the 10 million token scale, one hybrid-architecture model achieved a 22.7x prefill speedup on a single attention layer, while a dense model achieved 72.4x, with accuracy on multiple long-context tasks remaining close to the original models. The difference in speedup mainly comes from the models’ original indexing implementations: the heavier the existing index, the larger the gain from replacement.

    Accuracy is preserved for three reasons. First, latent-space compression retains global distribution information, avoiding the “local view” error of block sparse methods. Second, two-stage retrieval (coarse filtering plus fine ranking) keeps final scoring in the original representation. Third, the sparsity ratio already has ample redundancy: 0.8% of keys preserves about 98% accuracy.

    4. Engineering Recommendations

    1. Layered design: use latent-space retrieval for global layers and keep sliding-window attention for local layers, balancing long-range and short-range coverage.
    2. Cache reuse: latent states can be updated incrementally alongside the KV cache, so no rebuild is needed during decoding.
    3. Mix with linear attention: linear layers provide a low-cost global receptive field, while sparse layers handle precise retrieval.
    4. Capacity planning: prefill is the main source of gains, so inference services should enable this first for long-document summarization, codebase understanding, and similar scenarios.
    5. Accuracy guardrails: run long-context benchmark regressions before launch, and monitor both retrieval recall and task accuracy.

    Conclusion

    In the 10 million token era, the bottleneck has moved from “slow to compute” to “slow to find.” Latent-space sparse attention migrates retrieval from the original key space to a compressed latent space, turning quadratic indexing into near-linear indexing and providing a practical sub-quadratic path for ultra-long context. The real takeaway for developers: when optimizing long context, measure the share of indexing overhead first, then decide where to optimize.