Latent Sparse Attention: 22× Faster Long-Context Inference at 10M Tokens

    This article explains why the indexer becomes the new bottleneck as LLM context windows scale from millions to tens of millions of tokens, and how Latent Sparse Attention (LSA) merges retrieval and attention into a single step over a compressed latent space—achieving up to 22.7× (and in one case 72.4×) speedups per attention layer at 10M-token prefill while maintaining accuracy. It also covers practical takeaways for engineers building ultra-long-context applications.

    Latent Sparse Attention: 22× Faster Long-Context Inference at 10M Tokens

    1. The Long-Context Race Enters a New Phase: From “Can See” to “Can Afford to See”

    Over the past year, the arms race in long-context capability has clearly accelerated. Several leading models have made million-token context windows a default specification, and developers can now feed entire technical documents, full code repositories, or hours of meeting transcripts into a model in one pass. Behind this lies a shared technical choice: instead of letting every query attend to all historical tokens, the model selects only a small set of the most relevant tokens to “look at”—an approach known as sparse attention.

    This route has been validated repeatedly at the million-token scale: as long as the selected tokens are sufficiently relevant, model accuracy is barely affected while compute drops significantly. But as context lengths push toward ten million tokens, a previously minor overhead spirals out of control—the indexer that decides “which tokens to look at” becomes the new performance bottleneck.

    2. The Core Problem: Attention Is Sparse, but the Index Is Still Dense

    To understand this bottleneck, consider the mainstream sparse attention workflow:

    1. Scoring: a lightweight indexer computes relevance scores between each query and all historical keys;
    2. Selection: the Top-K most relevant key/value pairs are picked;
    3. Attention: standard attention is computed only over the selected K tokens.

    The compute cost of step 3 is proportional to K—typically hundreds to a few thousand tokens, far smaller than the context length N—so it is highly efficient. But step 1 is dense: every query must be compared against all N keys, giving O(N²) complexity. At N = 1M, the indexer might account for only a few percent of total latency; at N = 10M, the indexing cost grows quadratically—a hundredfold increase—while attention compute grows only linearly with K. The two become completely unbalanced. Measured data shows that in the global attention layers of a certain hybrid sparse architecture, over 90% of prefill time at 10M tokens is spent on the indexer, while actual attention computation takes less than 2%.

    The nature of the problem has therefore changed. Sparse attention long ago proved that “looking at only a small portion” is enough to preserve accuracy; what now blocks ultra-long context is that “finding that small portion” still grows quadratically with context length. The optimization target must shift from “reducing attention compute” to “reducing indexing compute.”

    3. Latent Sparse Attention: Merging “Finding” and “Looking” into One Step

    To address this contradiction, a research team proposed a new mechanism called Latent Sparse Attention (LSA). Its core idea can be summarized in one sentence: instead of searching for relevant tokens in the raw token sequence, first compress the history into a compact latent space, then perform both retrieval and attention within that space—“finding” and “looking” happen in a single step.

    3.1 Basic Structure

    LSA’s key design consists of three parts:

    • Latent compression: the length-N KV (key/value) sequence is mapped through a learnable compression function into a latent representation sequence much shorter than N. The number of latent representations is decoupled from N—it can be fixed or grow sublinearly with N;
    • Attention within the latent space: queries no longer interact with every raw key, but attend directly to the latent representations. The attention weights naturally perform “relevance routing,” eliminating the need for a separate Top-K indexer;
    • Residual-style readback: to avoid information loss from compression, the weighted aggregation of latent representations can carry sufficiently fine-grained information, and some designs add a local branch to supply precise details of nearby tokens.

    Pseudocode illustration:

    1. def latent_sparse_attention(query, kv_history, compressor):
    2. # 1. Compress the full KV history into a fixed number of latent representations
    3. latent_k, latent_v = compressor(kv_history) # length reduced from N to M, M << N
    4. # 2. Attend directly in latent space, no explicit Top-K indexing needed
    5. attn_weights = softmax(query @ latent_k.T / sqrt(d))
    6. output = attn_weights @ latent_v
    7. return output

    Compared with the two-stage pipeline of traditional sparse attention (O(N²) scoring followed by O(NK) attention), LSA’s complexity depends on the number of latent representations M. When M is fixed or sublinear, the overall complexity drops to near-linear, fundamentally eliminating the quadratic term.

    3.2 Why Accuracy Holds

    A natural question is: doesn’t compression lose information? Two points support the design.

    First, sparse attention itself has shown that attention weights are naturally highly concentrated—the contribution of the vast majority of historical tokens to the current query approaches zero—so full KV sequences contain enormous redundancy, leaving theoretical room for compression. Second, the latent representations are trained end-to-end: the compressor learns to prioritize retaining “information future queries are likely to care about,” which fits the task distribution better than hand-crafted heuristic indexing (such as fixed sliding windows or hash bucketing). The paper reports that LSA achieves accuracy essentially on par with the original model across a range of tasks, including long-context retrieval, document QA, and code understanding.

    4. Performance Gains: The Ripple Effect of Compressing Indexing Overhead

    According to publicly reported research data, at 10M-token prefill, LSA speeds up a single attention layer of a model using a hybrid sparse architecture by about 22.7×, and speeds up an attention layer of another mainstream open-source model by up to 72.4×—the latter’s indexer originally accounted for a larger share of time, so the gain is greater. Note that these figures are per-attention-layer speedups; end-to-end gains depend on the proportion of global attention layers in the model, FFN compute, and communication overhead, so real-world impact must be calculated against the specific model architecture.

    Beyond raw compute, LSA brings two engineering benefits:

    • Lower memory pressure: there is no need to maintain an index score matrix over the full history, further compressing the peak memory of indexing-related O(N) intermediate tensors;
    • Decoding benefits: during decode, every new token must also interact with the history. Latent-space retrieval keeps per-step decoding cost from continuously growing with generated length, making throughput more stable for long-output scenarios such as lengthy report generation or multi-turn agent tasks.

    5. Implications for Engineering Practice

    For teams building ultra-long-context applications, this research suggests several actionable directions:

    1. Profile before optimizing: at the ten-million-token scale, always measure the time split between the indexer and attention computation first—blindly optimizing attention kernels may only touch a few percent of the total cost;
    2. Watch the “retrieval-as-computation” fusion trend: embedding relevance selection directly into attention, rather than treating it as a separate upstream module, is a general paradigm for eliminating quadratic bottlenecks; similar ideas can be transferred to the coarse-ranking stage of RAG (retrieval-augmented generation);
    3. Use elastic cloud compute for validation: prefill at ultra-long context demands extremely high memory and compute. Leveraging cloud GPU instances, object storage, and inference acceleration frameworks to quickly spin up evaluation environments—scaling up and down on demand—is a pragmatic, low-cost way to validate new attention mechanisms.

    6. Conclusion

    From one million to ten million tokens, the main challenge of long context has evolved from “attention is too expensive” to “indexing is too expensive.” By compressing the retrieval process into a compact latent space, Latent Sparse Attention decouples the cost of “finding relevant tokens” from context length, achieving order-of-magnitude speedups while preserving accuracy. As context windows continue to expand, this kind of “retrieval-and-computation integrated” architectural design is poised to become a standard component of ultra-long-context inference—and is well worth continued attention from every developer focused on inference performance optimization.