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

    As context windows race toward 10 million tokens, sparse attention is becoming a necessity, but the indexer that decides which keys to attend to can become the real bottleneck. This article breaks down the cost structure of attention at extreme scale, explains why full scoring in the original token space undermines the savings from sparsity, and introduces Latent Sparse Attention: compressing long sequences into a compact latent space for sub-quadratic coarse filtering, followed by exact reranking. It covers the three-stage pipeline, complexity analysis, sample pseudocode, relationships to block-sparse and linear attention, reported speedups of roughly 22.7x and 72.4x on prefill, and practical guidance on compression ratio, candidate count, low-precision indexing, KV cache integration, and accuracy-latency gating.

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

    1. The Context Length Race Enters the 10 Million Token Era

    Over the past two years, long context has shifted from an optional feature to a default specification for flagship models. Million-token context is now widely available in the official services of multiple mainstream models, and the industry’s focus is moving quickly toward 10 million tokens. The demand behind this is real: understanding an entire code repository, reviewing very long documents and contracts, preserving complete multi-turn conversation history, and aggregating information across hundreds of source materials.

    But context length is not free. It amplifies two kinds of cost at once: the attention computation itself, and the scheduling overhead of “deciding where attention should look.” The industry has largely reached a consensus that having every query traverse all historical tokens is neither necessary nor economical, making sparsification an inevitable direction. The real question is: when the scale grows by another order of magnitude, will the cost structure of sparsification itself collapse?

    2. The Overlooked “Hidden Bill”: The Indexer Becomes the New Bottleneck

    2.1 A Review of the Attention Cost Structure

    In standard full attention, every query computes relevance against all previous keys. With a context length of T, the prefill stage costs roughly O(T²), and decoding costs roughly O(T) per generated token. Going from one million to ten million tokens increases prefill attention computation by roughly 100x in theory.

    2.2 The Division of Labor in Sparsification

    Mainstream sparse approaches use a “two-stage” structure:

    • Stage 1: A lightweight indexer scores keys for each query and selects the k most relevant ones.
    • Stage 2: The actual attention is computed only over those k keys.

    The cost of Stage 2 is reduced to O(Tk), which looks very attractive. But if Stage 1 scores every key one by one, its complexity remains on the order of O(T²), so the compute saved in Stage 2 is handed right back to the indexer.

    2.3 A Concrete Runaway Case

    Take a model that supports million-token context and uses a hybrid architecture of sparse and linear attention. In one of its global attention layers, when running prefill at 10 million tokens, roughly 98% of the time is spent not on attention computation but on the indexer. In other words, sparse attention did not fail; what failed was the act of “finding the sparse set” itself.

    2.4 Why “Looking at Less” Works

    Sparsification rests on the premise that the model genuinely needs only a tiny fraction of keys. Existing validation shows that at the scale of over one hundred thousand tokens, letting each query attend to only the roughly 512 keys most relevant to it (typically less than 1% of the total) still preserves about 98% of full-attention accuracy on long-context benchmarks. This indicates that information is highly concentrated: the problem is not “how much to look at,” but “how to find it.”

    3. Reframing the Problem: From Quadratic Computation to Sub-Quadratic Retrieval

    Abstracted out, the core tension in ultra-long-context attention is:

    • Accuracy requirement: You must find the small set of truly most relevant tokens.
    • Cost requirement: The process of finding them must not grow quadratically with T.

    Existing engineering techniques, such as lowering index precision, compressing dimensions, or merging multiple keys into a single block, only “lighten the load” on the indexer without changing its asymptotic complexity. A real breakthrough requires moving the “scoring” work into a lower-dimensional, shorter latent space. This is the core idea of Latent Sparse Attention: instead of performing full scoring in the original token space, first compress the long sequence into compact latent representations, do coarse filtering in the latent space, then return to the original space for fine-grained reranking and attention computation.

    4. How Latent Sparse Attention Works

    4.1 A Three-Stage Pipeline

    • Compression: Split the long sequence into blocks and compress them into low-dimensional latent vectors via a learnable projection, significantly shortening the sequence length.
    • Coarse filtering: Use low-precision, low-dimensional dot products in the latent space to recall candidates, sharply reducing complexity.
    • Reranking and computation: Score candidate keys precisely in the original space, take the top-k, and run attention.

    4.2 Complexity Analysis

    Let the compression ratio be c (every c tokens are compressed into 1 latent vector). The latent-space length is roughly T/c, and coarse filtering costs roughly O(T²/c). Combined with constant-factor optimizations from low precision and low-dimensional inner products, the actual time reduction far exceeds the theoretical ratio. Reranking runs only over the candidate set, so its overhead is controllable. Overall, this shifts from “quadratic full scoring” to “sub-quadratic retrieval + constant-level reranking.”

    4.3 Illustrative Pseudocode

    1. # Conceptual illustration, not a specific implementation
    2. def latent_sparse_attention(Q, K, V, block=64, dim=32, topk=512):
    3. # 1) Compression: project blocks into the latent space
    4. K_latent = compress(K, block=block, dim=dim) # [T/block, dim]
    5. # 2) Coarse filtering: recall candidate blocks via low-precision, low-dim inner products
    6. scores = low_precision_matmul(Q @ proj, K_latent.T)
    7. cand_blocks = topk(scores, k=num_candidate_blocks)
    8. # 3) Reranking: score precisely over candidate original keys
    9. K_cand = gather(K, cand_blocks)
    10. idx = topk(Q @ K_cand.T, k=topk)
    11. # 4) Sparse attention
    12. return softmax(Q @ K[idx].T) @ V[idx]

    4.4 Relationship to Block-Sparse and Linear Attention

    Latent Sparse Attention is complementary to block-sparse methods: block sparsity addresses “storage and memory-access continuity,” while latent-space coarse filtering addresses “candidate localization.” Compared with linear attention, it retains precise retrieval capability, making it suitable for scenarios that require accurate recall. It can also be combined with a linear branch to form a hybrid architecture.

    5. Results and Accuracy Validation

    In public descriptions, this method speeds up prefill for a single attention layer of a certain hybrid-architecture model by roughly 22.7x at 10 million tokens, and speeds up a certain dense model by roughly 72.4x, while maintaining accuracy close to the original models on long-context benchmarks and across multiple task types. For engineering, three validations are recommended:

    • Recall: How well the candidate set covers the true top-k.
    • End-to-end accuracy: Relative loss on long-context benchmarks.
    • First-token latency and throughput: Whether prefill speedup actually translates into service-level metrics.

    6. Engineering Recommendations

    1. Compression ratio and candidate count are the core hyperparameters and require grid search per task.
    2. The indexer is best stored in low precision with block-based access to reduce bandwidth pressure.
    3. Combine with paged key-value caching and prefix reuse to further amortize long-context costs.
    4. Gate releases on both “accuracy and latency” metrics to avoid sacrificing recall for speed.

    7. Conclusion

    In the 10-million-token era, the deciding factor for sparse attention is not “computing fast” but “finding accurately and cheaply.” Moving retrieval into the latent space and replacing full scoring with sub-quadratic coarse filtering is currently one of the most engineering-valuable directions. For teams that need to balance accuracy and cost under ultra-long context, this approach is worth validating first.