Sparse Attention at 10M Token Context: Why Latent-Space Selection Delivers a 22x Prefill Speedup

    As context windows grow from 1M to 10M tokens, the bottleneck in long-context inference shifts from how much the model can see to how slowly it can find what matters. Public industry data shows that when prefilling a single global attention layer at the 10M token scale, roughly 98% of the time is spent not on attention computation but on the indexer—the step that decides which historical tokens to attend to. This article introduces Latent Sparse Attention, an approach that moves selection into a shared low-dimensional latent space, using one cheap projection instead of repeatedly scoring the full history. It explains why the bottleneck moves, how the method works, what a schematic implementation looks like, key engineering considerations, and how to evaluate the gains, helping developers make the right architectural trade-offs for ultra-long context workloads.

    When the context length grows from 1M to 10M, the bottleneck in long-context inference undergoes a qualitative change: the concern used to be “seeing too much,” but what actually slows the system down now is “searching too slowly.” Public industry data shows that at the 10M token scale, prefilling a single global attention layer spends about 98% of its time not on attention computation itself, but on the indexer—the step that decides which historical tokens to attend to. Sparse attention has repeatedly proven that reading only a small fraction of the history is enough to preserve accuracy; yet when the candidate set grows quadratically with length, the selection step itself becomes the new center of complexity. This article abstracts a general technical route: Latent Sparse Attention. Its core is not to compress KV further, but to move selection into a low-dimensional latent space, replacing repeated scoring over the full history with a single cheap projection. This delivers more than an order-of-magnitude speedup for single-layer prefill at 10M tokens while maintaining accuracy close to the original model. The sections below break down the root cause, the method, a schematic implementation, engineering considerations, and evaluation methodology, to help developers make the right architectural trade-offs in ultra-long context scenarios.

    1. Reframing the Problem: From “Seeing Too Much” to “Searching Too Slowly”

    At the 1M scale, hybrid attention architectures (global sparse + local linear) have become a common configuration for long-context serving: each query no longer traverses the entire history, but selects a few of the most relevant segments to participate in computation. This route has been repeatedly validated in engineering, with controllable accuracy loss and acceptable throughput.

    Pushing the length further to 10M flips the cost structure. The reason is that two overheads grow along different curves:

    • Attention computation: constrained by sparsity, grows roughly linearly with the number of selected tokens;
    • Indexing/selection: with a naive “score every historical token per query, then take Top-K” approach, the cost inflates quadratically with context length.

    This produces a counterintuitive phenomenon: the more aggressive the sparsification, the cheaper attention itself becomes, and the higher the relative share of the selection step—until it consumes almost all the time. This is also why “adding one more layer of sparsity” does not solve the problem: the bottleneck is no longer computation, but retrieval.

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

    The key abstraction of Latent Sparse Attention is this: instead of taking high-dimensional inner products between the query and all historical keys, first project both into a shared low-dimensional latent space, perform similarity evaluation and Top-K selection in that space, then return to the original space for attention using the selection result.

    It consists of three independently replaceable components:

    1. Projection: compresses the query and key into latent vectors of dimension d_latent, where d_latent is far smaller than head_dim;
    2. Selector: computes similarity in the latent space and takes Top-K; it can be combined with block-wise aggregation and coarse-grained clustering to further reduce the candidate scale from token level to block level;
    3. Kernel: runs standard attention only within the selected blocks, keeping the numerical path consistent with the training distribution.

    Schematic pseudocode (expressing structure only, not a specific implementation):

    1. # q, k: [B, H, L, D] latent_proj: Linear(D, d_latent)
    2. ql = latent_proj_q(q) # [B, H, L, d]
    3. kl = latent_proj_k(k) # [B, H, L, d]
    4. # Block aggregation with block size S: coarse block-level filtering first, then fine filtering within blocks
    5. kb = block_mean(kl, S) # [B, H, L/S, d]
    6. scores = einsum('bhld,bhmd->bhlm', ql, kb) / sqrt(d)
    7. idx = topk(scores, k_blocks) # block-level candidates
    8. out = sparse_attn(q, k, v, idx) # computed only within selected blocks

    In terms of complexity, if the original selection is O(L²·D), the latent-space version reduces it to O(L²·d_latent + L·K·D). When d_latent/D is small enough and K is controlled, the selection overhead is significantly amortized.

    3. Why Accuracy Is Preserved

    The effectiveness of sparse attention rests on two empirical facts: attention distributions are highly concentrated (a few historical segments contribute most of the weight), and relevant information is locally clustered (adjacent tokens are semantically related). The latent-space approach additionally exploits a third point: the low-dimensional projection preserves the dominant semantic directions, which is enough to support coarse filtering, while the actual weighting is still done in the original high-dimensional space, avoiding numerical bias from compression.

    Engineering recommendations:

    • Start with a projection dimension of 1/8 to 1/16 of head_dim, combined with distillation to align with the original attention distribution;
    • Use a two-level strategy of “block-level coarse filtering + fine filtering within blocks,” with Top-K increasing with layer depth;
    • Retain the local window and linear attention branches to handle near-field and long-range smooth information.

    4. Engineering Implementation

    • Blocking and memory: use blocks as the minimum scheduling unit, express selection results as a sparse index table, and avoid materializing the full score matrix;
    • Kernel fusion: fuse projection, block aggregation, Top-K, and sparse attention to reduce HBM round trips;
    • Caching strategy: cache the latent vectors kl and block means for prefix history; incremental decoding only updates new blocks;
    • Observability: track “selection time share,” “average number of candidate blocks,” and “hit rate” with monitoring and alerts to locate bottleneck shifts;
    • Elastic scaling: container platforms deploy in tiers by concurrency and context length, object storage holds long-session state, and message queues smooth out request peaks.

    5. Evaluation Methodology and Judging the Gains

    Public research reports show that at 10M tokens, for prefilling a single global attention layer, the latent-space sparse approach achieves about a 22x speedup relative to a mature sparse baseline, and up to tens of times faster for another sparse configuration; meanwhile, accuracy is close to the original model across a range of long-context tasks. For deployment, it is recommended to build your own evaluation:

    1. Baseline alignment: compare prefill latency and peak memory under the same length and the same sparsity budget;
    2. Accuracy regression: cover retrieval, aggregation, multi-hop, and long-file code understanding;
    3. Stability: observe latency variance across different length tiers to confirm whether the complexity curve has truly been flattened.

    6. Conclusion

    In the era of 10M tokens, the competitive focus has shifted from “how much can be seen” to “how fast the right content can be found.” Latent Sparse Attention offers a clear path: reduce the dimensionality of selection, block the candidates, and leave computation to the parts that are actually selected. For developers, this means trading a controllable accuracy cost for an order-of-magnitude prefill speedup in ultra-long context scenarios—an approach that also applies to general use cases such as long-repository understanding in AI coding tools and ultra-long event-chain analysis in log services.