Latent Sparse Attention: How to Scale Sparse Attention Indexing to 10-Million-Token Contexts

    As context windows push from 1 million to 10 million tokens, the bottleneck in sparse attention shifts from the attention computation itself to the indexer that decides which tokens to attend to—a cost that still grows quadratically. This article explains why the indexing stage dominates prefill time at extreme context lengths, how Latent Sparse Attention (LSA) moves candidate selection into a compressed latent space, and how decoupling coarse and fine selection with end-to-end training delivers up to 72x single-layer prefill speedups while preserving accuracy. It also shares practical engineering takeaways for teams building long-context applications.

    1. From Millions to Tens of Millions: The New Bottleneck in Sparse Attention

    The race to extend LLM context lengths has accelerated in recent years. In April of this year, a leading model provider made 1-million-token context the default specification for its official service; in August, another provider released a new lightweight model that also supports 1 million tokens and, for the first time in its model family, introduced a hybrid architecture combining sparse attention and linear attention.

    These approaches share a common technical choice: instead of having every query vector scan the full history of tokens, only a small set of the most relevant key-value pairs is selected to participate in the attention computation. This route has been repeatedly validated at the million-token scale—attention accuracy loss stays under control while compute drops substantially.

    However, as context pushes toward 10 million tokens, a previously negligible overhead starts to spiral out of control. Take one global attention layer of a hybrid-architecture model as an example: during prefill at the 10-million-token scale, roughly 98% of the time is not spent on the attention computation itself, but on the indexer—the component that decides which tokens to look at.

    This means the nature of the problem has changed:

    • Sparse attention has long proven that “looking at only a small fraction” is enough to preserve accuracy;
    • What truly throttles ultra-long context is that “finding that small fraction” still grows quadratically with context length.

    In other words, sparsification reduces the “execution cost” of attention but does not solve the “decision cost” of candidate selection. When the token history reaches tens of millions, the selection process itself is a full or near-full similarity scan, and the gains from sparsity are almost entirely offset by indexing overhead.

    2. Why the Indexer Grows Quadratically

    To understand the bottleneck, we first need to break down the typical two-stage sparse attention pipeline:

    1. Stage 1: Candidate selection (Indexing / Routing)
    2. For the current query, compute a lightweight similarity score
    3. against all historical keys, and select the Top-K most relevant positions.
    4. Stage 2: Sparse attention computation
    5. Run the full attention computation only on the K selected positions.

    Stage 2 has complexity O(K·d), where K is typically a constant in the hundreds to thousands, independent of the total length N—highly efficient. But in Stage 1, if every query must be scored against all N historical keys (even using low-dimensional projections or quantized vectors), the complexity is O(N²·d’). At N = 10⁶ this is tolerable; at N = 10⁷, the N² term explodes by a factor of 100, and the indexer completely overwhelms the attention computation itself.

    The industry has tried several mitigation strategies:

    • Block-level or paged selection: score at block granularity to reduce the number of scored objects. The cost is that importance within a block cannot be distinguished, making it easy to miss critical tokens.
    • Hierarchical indexing: select a region first, then blocks, then tokens. This reduces the constant factor, but the lowest-level selection still faces the global scale.
    • Approximate nearest-neighbor structures: such as locality-sensitive hashing or cluster centroids. Theoretically these can reach sub-linear complexity, but their accuracy is unstable on high-dimensional attention representations, and building and maintaining the index carries its own overhead.

    None of these approaches fundamentally changes the fact that “the selection space equals the original token space.” A new method recently proposed by an overseas research team—Latent Sparse Attention (LSA)—offers a different answer: move the selection process into a latent space with lower dimensionality and far fewer entries.

    3. The Core Idea of Latent Sparse Attention

    LSA’s key insight can be summarized in one sentence: indexing does not have to happen at the original token granularity. Its design has three layers:

    3.1 Retrieving with compressed representations instead of raw keys

    Traditional indexers score directly against the key vector of every historical token. LSA first compresses the continuous token sequence into a set of latent tokens, far fewer than N in number, where each latent token summarizes the key information of a span of context. During selection, the query only needs to be scored against these latent tokens, shrinking the candidate space from N to N/r (where r is the compression ratio), and reducing the indexing cost by more than an order of magnitude.

    This follows the same line of thinking as KV cache compression in LLMs: historical information does not need to be retained token by token; coarse-grained, summary-style representations are sufficient to serve the “routing” role.

    3.2 Decoupling coarse selection from fine selection

    LSA does not expect latent-space scoring to get everything right in one step. Its pipeline is:

    1. Use latent tokens for coarse selection, narrowing down to a few candidate regions;
    2. Within each candidate region, return to the original token granularity for fine selection, determining the final Top-K positions that participate in attention;
    3. Run the full attention computation only on those K positions.

    Coarse selection exploits the low-dimensional, low-cardinality latent space to drive the cost of the global scan to a minimum; fine selection ensures the final selected tokens closely match what full scoring would have produced. The overall complexity drops from O(N²) to an O(N·N/r)-level coarse pass plus a very small fine pass—in practice, approximately linear.

    3.3 End-to-end training to avoid “retrieval-attention” objective mismatch

    Hand-crafted hash or clustering indexes often suffer from one problem: the index structure is optimized for geometric proximity, while attention needs the tokens that “contribute most to the output”—two objectives that do not necessarily align. LSA makes the compression and scoring modules trainable, so the latent representations actively learn during training “what kind of summary best selects the correct tokens,” aligning selection quality with downstream task objectives.

    4. Measured Results: Order-of-Magnitude Speedups with Preserved Accuracy

    According to results published by the research team, in prefill scenarios at the 10-million-token context scale:

    • For a single global attention layer of a hybrid-attention-architecture model, LSA delivers roughly a 22.7x speedup;
    • For another dense model at the 27B scale, the single-layer speedup reaches about 72.4x—this model originally used heavier global attention, so its indexing bottleneck was more pronounced and the gains correspondingly larger;
    • Across a range of tasks including long-context retrieval, multi-hop reasoning, and summarization, accuracy remains essentially on par with the original model.

    It is worth emphasizing that both the 22x and 72x figures are measured on a single layer during prefill. They reflect the structural improvement of “eliminating the indexing bottleneck,” not an operator-level micro-optimization. As context continues to grow, the quadratic curve of traditional indexers and the near-linear curve of LSA will diverge even further.

    5. Implications for Engineering Practice

    For developers building long-context applications, LSA’s approach offers several actionable takeaways:

    First, quantify the bottleneck before optimizing. In long-context services, use profiling to break down how prefill time is distributed: how much goes to the attention computation, index scoring, and KV data movement. Many teams assume the bottleneck lies in the attention operator itself, when in fact indexing is the real battleground at the 10-million-token scale. General-purpose observability capabilities—such as the monitoring, alerting, and logging services offered by cloud providers—can quickly reveal where time is spent across stages.

    Second, treat “retrieval granularity” as a tunable parameter. Whether or not you adopt a method like LSA, recognize that selection granularity (token-level, block-level, segment-level, compressed-representation-level) is the central trade-off knob between accuracy and speed. The higher the compression ratio, the faster the indexing—but the recall of coarse selection depends more heavily on representation quality.

    Third, prioritize alignment between the index and task objectives. Purely geometric approximate retrieval structures tend to “focus on the wrong things” on long documents; a trainable—or at least calibratable—scoring mechanism is more reliable.

    Fourth, combine with KV compression and cache reuse. LSA is complementary to KV cache compression and prefix cache reuse: the former solves “whom to find,” while the latter two solve “how much to store” and “how many times to compute.” When deploying inference services on a container platform, all three can be incorporated into a unified memory and compute budget model.

    6. Conclusion

    Sparse attention solved the problem of “looking at less,” but for a time overlooked the cost of “how to find.” By moving candidate selection into a compressed latent space and decoupling coarse selection from fine selection, Latent Sparse Attention compresses the indexing overhead of 10-million-token contexts from quadratic to near-linear, achieving tens-of-times single-layer speedups while preserving accuracy. As ultra-long context becomes standard in scenarios such as agents, codebase analysis, and long-document understanding, “efficiently finding what to look at” will become as central a problem for LLM inference systems as “efficiently computing attention.”