The Key to 22x Faster Sparse Attention at 10M Token Context

    This article examines why sparse attention alone fails to scale to 10 million token contexts: the indexer that decides which tokens to attend to becomes the quadratic bottleneck, consuming roughly 98% of prefill time in a global attention layer. It explains the cost structure of scoring, selection, and aggregation, then introduces Latent Sparse Attention (LSA), which moves retrieval into a low-dimensional latent space. Reported single-layer speedups, accuracy results, and a practical engineering checklist for deployment are included.

    1. The First-Order Bottleneck of Ultra-Long Context: From Computing Attention to Finding Attention

    Over the past two years, long-context capability has moved rapidly from 128K to 1M, and it has become the default specification for many flagship models’ official offerings. Hybrid attention architectures, which alternate global attention layers with linear attention layers, have also become a common industry approach: global layers handle precise recall, while linear layers compress history at low cost.

    But as context pushes toward the 10 million token range, an originally unremarkable cost starts to spiral out of control. Take a single global attention layer doing prefill at 10M tokens: roughly 98% of the time is not spent on attention computation at all, but on the indexer that decides which tokens to look at.

    This changes the nature of the problem:

    • Sparse attention has been repeatedly validated: attending to only a small fraction of tokens is enough to preserve accuracy.
    • What actually blocks ultra-long context is that the cost of finding that small fraction still grows quadratically with context length.

    In other words, sparsification solves the computation volume but not the retrieval volume.

    2. Why the Indexer Becomes a Quadratic Bottleneck

    A typical sparse attention layer has three steps: scoring (deciding relevance), selection (taking Top-K), and aggregation (running attention only over the selected K tokens). The cost structure of the first two steps is worth breaking down:

    1. Scoring: O(N^2 * d) # every query interacts with all historical keys
    2. Selection: O(N * K logN) # Top-K sorting/filtering
    3. Aggregation: O(N * K * d) # the actual sparse attention

    Here N is the context length, d is the head dimension, and K is the number of retained tokens. When N grows from 1M to 10M, the aggregation term grows only linearly, while the scoring term grows 100x. The attention compute that was saved gets eaten by the extra indexing overhead, and can even invert into a net loss.

    There are three additional amplifiers in engineering terms:

    1. Memory wall: scoring requires repeatedly reading K/V into on-chip cache; the larger N is, the closer bandwidth pressure comes to a hard constraint.
    2. Insufficient parallelism: a very small K makes the aggregation-stage operator “thin” and hard to keep the compute units fed.
    3. Dynamic branching: the Top-K selection result depends on data, which compresses the room for static-graph and operator-fusion optimizations.

    3. The Core Idea of Latent Sparse Attention (LSA)

    A recent paper jointly released by a London startup and a technical university in Zurich proposes Latent Sparse Attention (LSA). Its key judgment is: do not perform retrieval in the original token space; instead, move the task of “finding relevant tokens” into a low-dimensional latent space.

    It can be understood as a three-stage funnel:

    • Stage 1: Compressed representation. Project K/V into low-dimensional latent vectors (similar to low-rank projection / latent variable representation), so that scoring no longer depends on the full head dimension.
    • Stage 2: Latent-space retrieval. The query computes similarity only against compressed entries in the latent space, reducing the candidate pool from N to M, which is tied to the number of latent slots (M ≪ N).
    • Stage 3: Exact aggregation. Run real attention only over the small set of selected tokens in the original K/V, preserving output accuracy.

    Illustrative pseudocode:

    1. # Prefill stage: build the latent-space index once
    2. latent = proj_down(K) # [N, r], r much smaller than d
    3. index = build_index(latent) # build a reusable compressed index
    4. # Per-query retrieval: cost drops from O(N*d) to O(M*r)
    5. cand = index.topk(proj_down(Q_t), k=M) # candidate set size M << N
    6. out = softmax(Q_t @ K[cand].T) @ V[cand] # exact aggregation in the original space only

    The core benefit: the quadratic term is shifted from “scoring” to a one-time index build, and index construction can be offline, cacheable, and reused across requests.

    4. Measured Gains and Accuracy

    Data reported in the paper (single-layer prefill, 10M token context):

    Model scale type Single attention layer speedup
    Medium-scale dense model ~22.7x
    Larger-scale dense model ~72.4x

    Accuracy remained close to the original model across a series of long-context tasks. It is worth stressing that this is a single-operator-level speedup; end-to-end gains depend on the proportion of global layers, whether index construction is reusable, and whether I/O becomes the new bottleneck. End-to-end numbers are typically lower than the single-layer figure, but the magnitude is still substantial.

    5. Engineering Deployment Checklist

    1. Locate the bottleneck first: use operator-level profiling to confirm the indexer’s share, and avoid blind rework in scenarios where attention computation is not the bottleneck at all.
    2. Make the index reusable: bind the latent-space index to the request session and cache it; the gains are largest across multi-turn conversations.
    3. Guard accuracy: set up a three-part regression of perplexity + long-context retrieval tasks + needle-in-a-haystack style localization tests.
    4. Budget memory and bandwidth: the compressed representation introduces additional resident memory, which must be planned together with the KV cache strategy.
    5. Serving infrastructure: ultra-long-context inference typically needs a container platform for elastic scaling, object storage to hold session state, and logging plus monitoring/alerting for full-chain observability; on Baidu AI Cloud, these capabilities can be combined as general cloud product categories.

    6. Conclusion

    In the 10M token era, the core tension has shifted from “attention cannot be computed” to “relevant tokens cannot be found.” The value of LSA is that it swaps the retrieval space, turning a dynamic cost that grows quadratically with length into an amortizable, cacheable one-time cost. For developers, the real action item is not swapping out a model, but re-examining the complexity ledger of the “index” stage in their own pipeline.