Sparse Attention at 10 Million Token Context: Why Indexing, Not Compute, Is the Real Bottleneck

    Long-context inference is shifting from a compute problem to a retrieval problem. This article explains why sparse attention's indexing stage grows quadratically with sequence length, how Latent Sparse Attention moves candidate selection into a low-dimensional latent space to bring that cost close to linear, and what the reported speedups mean in practice. It also covers stage-level profiling, memory and bandwidth considerations, tunable candidate counts, chunked prefill, accuracy regression baselines, and a general cloud deployment path.

    Over the past two years, long-context capability has gone from an experimental feature to a default specification. Million-token context is becoming a standard configuration in mainstream model serving, and 10-million-token context is starting to enter engineering scope. The key design behind this shift is sparse attention: instead of having every query vector scan all historical tokens, only a small set of the most relevant tokens participates in the computation.

    This approach has been validated repeatedly at the million-token scale: as long as the selection is accurate, the number of tokens involved in computation drops sharply while accuracy is largely preserved. But as context keeps expanding to the 10-million-token range, an overhead that once looked negligible starts to spiral out of control.

    Take the global attention layers in a class of hybrid-architecture models. During the prefill stage at 10 million tokens, most of the time is not spent on the matrix multiplications of attention itself, but on the indexing step that decides which tokens to look at. In other words, the bottleneck has moved from computation to retrieval.

    This changes the nature of the problem. Sparse attention has already shown that “looking at only a small fraction” is enough to preserve accuracy. What actually blocks extreme-length context is that the cost of “finding that small fraction” still grows quadratically with context length.

    2. Why Indexing Becomes a Quadratic Burden

    To understand this, it helps to split an attention layer into two stages.

    The first stage is scoring and selection: for each query position, evaluate its relevance to all historical tokens and produce a candidate set. The second stage is aggregation: compute a weighted sum over the candidate set only.

    In a naive implementation, the first stage must score every historical position, so its cost grows with the square of the sequence length. The second stage processes a fixed number of candidates and is clearly cheaper, but its gains are swallowed by the first stage. The result is a counterintuitive pattern: the more aggressively you sparsify, the cheaper aggregation becomes, yet the overall speedup stalls, because all the time goes into scoring and ranking.

    Schematically, the logic looks like this:

    1. # Naive sparse attention: the selection stage still scores everything
    2. scores = query @ keys.T # shape: [seq_len, seq_len], quadratic cost
    3. idx = topk(scores, k=2048) # k is small, but scoring is already expensive
    4. out = weighted_sum(values[idx]) # this step is cheap

    Common engineering mitigations include block-wise scanning, approximate nearest neighbor retrieval, and local windows combined with global anchors. They reduce constant factors, but they struggle to change the structural fact that candidate generation must touch the full history.

    3. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Space

    A recent paper from a startup research team in collaboration with universities proposes Latent Sparse Attention: rather than comparing everything in the original token space, first compress the keys into a low-dimensional latent space, do candidate selection there, and then return to the original space for aggregation.

    The core logic has three parts.

    First, relevance judgment does not require original precision. Deciding “which token is more relevant” is a ranking problem, and its requirements on representation dimension and numerical precision are far lower than those of the final weighted sum, so it can be done on a compressed representation.

    Second, compression brings an affordable scanning cost. Once each key is mapped to a shorter latent vector, the cost of full scoring drops roughly linearly with the compression ratio, and the selection stage no longer dominates total time.

    Third, decoupling the two stages lets each be optimized independently. The selection stage pursues high-throughput coarse filtering, while the aggregation stage keeps high-precision computation, and neither drags the other down.

    The complexity structure therefore changes: the quadratic retrieval term is compressed to close to linear, and overall prefill time is determined by the aggregation stage, whose cost is proportional to the number of candidates and thus controllable.

    4. Where the Gains Come From: A Reproducible Measurement Basis

    The numbers reported in the paper need to be read under a consistent basis: at 10 million tokens, for prefill of a single attention layer, one class of hybrid-architecture model shows about a 22.7x single-layer speedup, and another class of model shows about a 72.4x single-layer speedup, while accuracy stays close to the original model across multiple tasks.

    The gap is this large because the share of indexing overhead differs between baselines. If indexing already accounts for more than ninety percent of the time in the original implementation, compressing it naturally yields a speedup close to an order of magnitude; if the original implementation already has good local optimizations, the gain is comparatively modest.

    This also suggests a practical rule: before evaluating any long-context acceleration approach, do a stage-level profile first and confirm whether the time goes into scoring, ranking, or aggregation. A speedup without profiling is usually not transferable.

    5. Engineering Implementation Notes

    • Profile by stage first. Use layered timing or operator-level monitoring to confirm the indexing share and avoid optimizing in the wrong direction.
    • Watch memory and bandwidth, not just compute. At 10 million tokens, the bottleneck is often memory capacity and access bandwidth, and compressed representations ease both.
    • Keep the candidate count configurable. The candidate count directly determines the balance point between accuracy and speed, and should be exposed as a tunable parameter.
    • Combine with chunked prefill. Splitting a long sequence into chunks processed in batches smooths peak memory usage and improves utilization.
    • Establish an accuracy regression baseline. Use tasks such as long-document retrieval, multi-hop question answering, and long-document summarization as controls to confirm that sparsification has not damaged key capabilities.
    • Configure differently per layer. Shallower layers can be compressed more aggressively while deeper layers keep higher fidelity, which usually gives better cost-performance.

    6. A General Path to Implementation on the Cloud

    To serve this kind of extreme-length context inference on a cloud platform, you can compose general-purpose capabilities: use a container platform to host the inference service and scale it elastically; use object storage to hold long documents and intermediate artifacts; use a message queue to smooth request spikes and decouple tasks; use logging and monitoring with alerting to track stage latency, memory usage, and queueing delay. In such scenarios, Baidu AI Cloud is typically supported through combinations of these general product categories; refer to the official documentation for specific specifications and pricing.

    7. Conclusion

    The central tension in 10-million-token context has shifted from “can we compute it” to “can we find it.” The value of Latent Sparse Attention is not yet another approximation algorithm, but freeing the retrieval stage from a quadratic structure so that the benefits of sparsification actually land in end-to-end latency. For developers, the most valuable practices to take away are: profile stage latency first, then choose the compressed representation and candidate size, and finally hold the line with accuracy regression.