Latent Sparse Attention: Accelerating Long-Context Inference at 10 Million Tokens

    At 10 million tokens, sparse attention can spend more time selecting relevant keys than computing attention itself. This article explains how Latent Sparse Attention moves key selection into a compressed latent space to reduce indexing costs, examines reported accuracy and attention-layer speedups, and outlines practical considerations for deploying ultra-long-context inference.

    1. Long Context Reaches the 10-Million-Token Scale

    Over the past year, competition over large language model context lengths has accelerated. Several leading model providers have made million-token context windows part of their standard offerings. Some lightweight, cost-oriented models also support 1M-token contexts natively, with architectures that combine sparse and linear attention.

    A common principle behind these designs is selective attention: instead of making every query attend to every historical token, select a small subset of the most relevant keys.

    This approach has been demonstrated repeatedly at the million-token scale. But as context lengths move toward 10 million tokens, a previously secondary cost becomes dominant. Sparse attention has already reduced the cost of attention computation; the bottleneck shifts to the indexer that decides which tokens to attend to.

    In one reported measurement of a block-sparse attention layer, approximately 98% of prefill time at 10M tokens was spent on index scoring and selection rather than attention computation.

    The problem has therefore changed. Sparse attention has shown that attending to a small subset of tokens can preserve accuracy. The challenge is that finding that subset can still have quadratic complexity as context length grows.

    2. The Hidden Cost of Sparse Attention

    Consider the cost structure of standard full attention. Each query computes a relevance score against every preceding key. For a context of length (T):

    • Prefill attention requires (O(T^2)) computation.
    • Decoding each additional token requires (O(T)) attention computation.

    Increasing context length from 1 million to 10 million tokens therefore increases theoretical prefill attention computation by a factor of 100.

    Sparse attention divides the work into two stages:

    1. A lightweight indexer selects the (k) most relevant keys for each query.
    2. The attention operation runs only over those selected keys.

    This reduces the attention computation itself to (O(Tk)).

    The approach depends on the model needing only a small subset of keys. One reported experiment tested a model with several billion parameters at a 128K-token context length. When each query attended only to its 512 most relevant keys, the model retained approximately 98% of full-attention accuracy on major long-context benchmarks.

    This suggests that sparsity itself is not necessarily the main obstacle. The difficulty lies in selecting the right keys efficiently.

    Why a lightweight indexer can still be expensive

    To identify the most relevant 512 keys, an indexer may first need to score every available key.

    Common optimizations include:

    • Using lower-precision scoring.
    • Reducing the dimensionality of the scoring representations.
    • Compressing multiple keys into blocks and scoring those blocks.

    These techniques make the indexer cheaper, but they do not necessarily eliminate the need to scan the full key history. Each query still generates scores across the available context, leaving indexing with quadratic scaling when the compression ratio remains fixed.

    At 1M tokens, low precision and reduced dimensionality may keep the absolute cost manageable. At 10M tokens, the quadratic indexing work can increase by roughly 100 times, while attention over a fixed number of selected keys grows only linearly with the number of queries.

    The result is a reversal: the indexer becomes more expensive than the attention operation it was designed to accelerate.

    This is sparse attention’s hidden bill. The cost has not disappeared; it has moved into selection.

    3. The Core Idea: Move Top-k Selection into Latent Space

    A recently proposed approach called Latent Sparse Attention (LSA) addresses this indexing bottleneck.

    Its central idea is straightforward:

    Instead of scoring every original key individually, compress the keys into a smaller latent representation and perform selection in that latent space.

    The process can be understood in three stages.

    3.1 Compress the context into a latent index

    A conventional indexer scores all keys for every query, producing (O(T^2)) work across prefill.

    LSA takes a different approach. It first aggregates the (T) keys into (m) latent tokens, where (m) is much smaller than (T)—for example, a fixed set of several thousand latent tokens.

    This compression can be understood in terms of attention-based aggregation, pooling, or a learned compression module. With a fixed latent size, its cost scales linearly with context length rather than quadratically.

    An intuitive analogy is a book’s table of contents: instead of searching every page for every question, first consult a compact guide to the material.

    3.2 Perform coarse selection in latent space

    Each query now scores only the (m) latent tokens rather than all (T) original keys.

    The indexer selects the most relevant latent entries and maps them back to corresponding regions of the original key sequence. Across all queries, this changes the scoring cost from (O(T^2)) to (O(Tm)).

    If (m) remains fixed, this scoring stage is linear in (T). More generally, keeping the latent representation sufficiently small provides a route to subquadratic indexing—the motivation behind the phrase “Towards Subquadratic.”

    3.3 Run attention over the selected keys

    Once coarse selection produces a candidate set, fine-grained attention operates only on the selected keys, as in conventional sparse attention.

    The difference is how those candidates were found: through latent-space selection rather than exhaustive scoring of the original key sequence.

    The following pseudocode illustrates the high-level flow:

    1. # 1. Global compression: T keys -> m latent tokens
    2. latent = compress(keys) # [m, d], m << T
    3. # 2. Coarse selection: score the query against m latent tokens
    4. scores = query @ latent.T # O(m) per query
    5. top_blocks = topk(scores, k_blocks)
    6. cand_keys = gather(keys, top_blocks) # Map back to original key regions
    7. # 3. Fine-grained attention: compute only over candidate keys
    8. out = attention(query, cand_keys)

    This is a conceptual sketch: compression, latent selection, and candidate gathering together replace exhaustive key scoring.

    4. Why Latent-Space Selection Can Preserve Accuracy

    Compression inevitably loses information. A natural concern is whether selecting in latent space will miss keys that matter to the final attention output.

    The key is the two-stage structure: coarse retrieval followed by fine-grained attention.

    The latent index does not need to identify the final (k) keys perfectly. Its first responsibility is to place the important keys inside the candidate set—in other words, to maintain high recall.

    Because latent tokens are learnable aggregations of the original keys, the compression process can preserve information useful for retrieval. This resembles the familiar retrieval-system pattern of vector retrieval followed by reranking: the first stage identifies promising candidates, and the second stage evaluates them more precisely.

    The second stage cannot recover a key that was excluded entirely. However, if the coarse stage has sufficiently high recall, the keys that matter most remain available to attention, limiting the effect on final accuracy.

    Reported evaluations across multiple long-context tasks found accuracy close to that of the original sparse-attention models. These results suggest that latent-space selection can reduce indexing costs without materially changing task performance in the evaluated settings.

    5. Performance: Removing the Indexing Bottleneck

    Reducing indexing complexity from quadratic to subquadratic makes the potential benefit larger as context length increases.

    At a 10M-token prefill length, reported results included:

    • Approximately 22× acceleration for an attention layer using a sparse-indexing approach.
    • Up to 72× acceleration for a single attention layer in a general-purpose model with approximately 27 billion parameters.

    These are attention-layer measurements, not end-to-end model speedups.

    The difference between the reported speedups reflects differences in indexer design. A model with a more expensive original indexer has more overhead to remove, so replacing that indexer can produce a larger gain.

    The scaling trend matters as much as the individual measurements. Conventional exhaustive index scoring grows quadratically with context length. Under a fixed-size latent representation, latent-space scoring grows approximately linearly.

    As context grows, the gap between those cost curves widens. The significance is therefore not simply a faster implementation of the same computation. It is a change in how the indexing workload scales.

    6. Practical Considerations for Deployment

    For teams building production systems with ultra-long context windows, several engineering priorities follow.

    6.1 Profile before optimizing

    Do not assume that the attention kernel is the main bottleneck.

    At million-token context lengths, profile prefill to determine how much time is spent on:

    • Attention computation.
    • Index scoring and selection.
    • Key-value cache movement.

    Indexing can become dominant quickly as context length increases. A component that is manageable at 1M tokens may account for most of the runtime at 10M tokens.

    6.2 Separate selection from attention computation

    Treat “which keys to select” and “how to compute attention” as distinct modules.

    This separation makes it easier to evaluate alternative indexers, including latent-space approaches, without tightly coupling every indexing change to the trained attention computation.

    6.3 Measure retrieval recall as well as task accuracy

    End-to-end benchmark accuracy is essential, but it does not explain every failure.

    Also measure top-k retrieval recall: how much the selected key set overlaps with the truly most relevant keys. This provides a more direct way to identify accuracy losses caused by the selection stage.

    High candidate recall is especially important in a coarse-to-fine design, because fine-grained attention can only use keys that survive retrieval.

    6.4 Support the algorithm with appropriate infrastructure

    Ultra-long-context inference stresses memory capacity, bandwidth, and scheduling as well as computation.

    Container platforms, object storage, monitoring, and alerting can help support an elastic inference service. These infrastructure capabilities complement algorithmic improvements and allow teams to focus more of their effort on the indexing and attention pipeline.

    7. Conclusion

    Sparse attention addresses the problem of computing attention over too many tokens, but it can leave another expensive operation intact: finding the tokens worth attending to.

    At 10 million tokens, that selection cost can dominate prefill.

    Latent Sparse Attention points toward a subquadratic indexing path through three stages:

    1. Compress the full key sequence into a compact latent representation.
    2. Perform coarse selection in latent space.
    3. Compute fine-grained attention over the selected keys.

    With a fixed-size latent index, the scoring workload can move from quadratic toward linear scaling while preserving accuracy in the reported evaluations.

    As context windows continue to expand, efficient selection becomes as important as efficient attention. Reducing the cost of finding relevant information is a critical step toward making ultra-long-context inference practical at scale.