Sparse Attention at 10 Million Tokens: Fixing the Indexing Bottleneck for 22x Speedups

    As context windows scale from millions to tens of millions of tokens, the main cost of sparse attention shifts from computing attention to selecting which tokens to attend to. This article explains why the indexing stage grows quadratically and comes to dominate prefill latency, then introduces Latent Sparse Attention (LSA), which projects queries and keys into a low-dimensional latent space for approximate retrieval before running sparse attention in the original space. It covers reported speedups of 22.7x and 72.4x on a single attention layer, how to interpret those numbers, and practical guidance on measuring your own bottleneck, adopting hybrid architectures, and tracking recall alongside latency.

    1. The Bottleneck Is Shifting in the Era of Ultra-Long Contexts

    Over the past two years, long-context capability has moved from an optional feature to a default configuration in mainstream LLM services. Million-token context windows are now standard in flagship offerings from multiple cloud providers, and the industry keeps pushing the boundary further. The key technical choice behind this trend is highly consistent: instead of having every query vector scan all historical tokens, the model selects only a few of the most relevant segments to participate in computation. This approach has been repeatedly validated at the million-token scale.

    But as the context grows to 10 million tokens, an initially negligible cost starts to spiral. Take one global attention layer in a mainstream open-source model that supports a million-token context. During the prefill stage at 10 million tokens, 98% of the time is spent not on the attention computation itself, but on the indexing step that “decides which tokens to look at.”

    This means the nature of the problem has changed. Sparse attention has already proven that “looking at only a small fraction” is enough to preserve accuracy. What actually blocks ultra-long context is that the process of finding that small fraction still scales quadratically with context length.

    2. Why “Selection” Costs More Than “Computation”

    To understand this counterintuitive result, you need to break sparse attention into its two stages.

    The first stage is retrieval or indexing: the system evaluates the relevance of every historical token to each query, scores them, sorts them, and picks the Top-K. The second stage is the sparse computation: attention weighting is applied only to the selected K tokens.

    At the million-token scale, K is still a tiny fraction of the total length, so the second stage is nearly free and the first stage is only a secondary cost. But when the total length grows to 10 million, the candidate set for the first stage expands tenfold, and the dot-product between queries and keys in the attention mechanism is inherently a quadratic “length × length” structure. Even with optimizations such as chunking and compression, the indexer still has to run approximate nearest neighbor search over a massive candidate set, and that overhead quickly dominates overall latency.

    A common engineering mistake is to bet all optimization effort on “reducing K” or “using a cheaper attention kernel.” But the data shows that when indexing accounts for 98% of the time, optimizing the compute portion yields almost no benefit. You have to attack the indexing stage directly.

    3. Latent Sparse Attention: Moving “Token Selection” into a Low-Dimensional Space

    Recently, a London-based startup research lab and a federal institute of technology in Zurich jointly proposed a method called Latent Sparse Attention (LSA). Its core insight is: don’t do expensive relevance retrieval in the original high-dimensional token space. Instead, first project queries and keys into a low-dimensional latent space, perform approximate retrieval there, then map back to the original space for sparse attention.

    This approach brings three benefits:

    1. Much lower retrieval dimensionality: high-dimensional dot products become low-dimensional dot products, significantly reducing the cost of each scoring operation and making it more amenable to vectorization.
    2. Compressible and clusterable candidate sets: in the latent space, semantically similar tokens cluster more easily, so the system can locate a few clusters first and then select carefully within them, avoiding a full scan.
    3. Natural compatibility with linear attention: the low-dimensional latent space shares the same ideas as the state compression in linear attention, so the two can be mixed and stacked into a hybrid architecture of “global sparse layers + local linear layers.”

    The core flow is illustrated in this pseudocode:

    1. # Original space dimension d, latent space dimension r << d
    2. q_latent = W_q @ q # Project query into low dimension
    3. k_latent = W_k @ k # Project key into low dimension
    4. # Approximate nearest neighbor retrieval in latent space, roughly linear complexity
    5. idx = ANN_index.search(q_latent, topk=K)
    6. # Apply attention only to selected tokens in the original space
    7. attn = softmax(q @ k[idx].T) @ v[idx]

    The key point is that the projection matrices can be trained jointly with the model, so that distances in the latent space preserve the relevance ranking of the original space as much as possible, ensuring that “selection is accurate.”

    4. Measured Gains: Order-of-Magnitude Speedups on a Single Attention Layer

    The reported data in the paper is striking: at the 10-million-token scale, the method speeds up the prefill of a single attention layer in a million-context open-source model by 22.7x, and pushes the speedup to 72.4x on another mainstream open-source model, while maintaining accuracy comparable to the original models across a range of long-context tasks.

    These numbers need to be interpreted correctly from an engineering standpoint:

    • The speedup applies to a “single attention layer,” so end-to-end acceleration will be lower. But attention layers are often the main bottleneck in long-context inference, so the overall gain is still substantial.
    • The large difference in speedup across models indicates that their original indexer implementations vary in efficiency; the more cumbersome the indexer, the greater LSA’s relative benefit.
    • Accuracy preservation is a prerequisite. If retrieval recall is insufficient, sparse attention degrades into “missing key information,” which quickly shows up in tasks like long-document retrieval and multi-hop question answering.

    5. Practical Recommendations

    For teams looking to adopt this kind of technique in ultra-long-context scenarios, here are a few points to focus on:

    1. Measure before optimizing: measure the proportion of time spent in the indexing stage on your own workloads to confirm the bottleneck is truly in “selection” rather than “computation,” and avoid blindly swapping out the attention kernel.
    2. Prioritize hybrid architectures: use latent-space sparse retrieval for global layers and linear attention for local layers, balancing global recall and local precision.
    3. Treat recall as a first-class metric: monitor Top-K recall, end-to-end task accuracy, and latency together to prevent “faster but wrong.”
    4. Combine with general cloud capabilities: use a container platform to host inference services, use monitoring, alerting, and logging services to continuously observe per-layer latency distribution, and use object storage to manage long-context corpora and caches.

    6. Conclusion

    The core tension of 10-million-token context has shifted from “can’t compute” to “can’t find.” By reducing dimensionality for retrieval, Latent Sparse Attention compresses quadratic growth into near-linear growth, providing a reusable engineering path for ultra-long context. For developers, the real lesson is this: when a system enters a new order of magnitude, the bottleneck migrates, and optimization must migrate with it rather than clinging to experience from the previous scale.