Latent Sparse Attention: Breaking the Indexing Bottleneck for 10M-Token Contexts

    This article explains why indexing becomes the dominant cost as context windows scale to 10 million tokens and introduces Latent Sparse Attention (LSA), which performs top-k scoring in a low-dimensional latent space before exact attention in the original space. It covers the method’s design, a pseudocode comparison, reported prefill speedups of 22.7x and 72.4x on two models, and engineering lessons on profiling hidden quadratic costs, tiered precision, and dimension reduction for retrieval-style subtasks.

    1. The Evolution of Ultra-Long Contexts and the Emerging Bottleneck

    1.1 From Million-Token to 10M-Token Contexts

    Context windows in large models have expanded rapidly in recent years. Early windows were measured in tens of thousands of tokens; one million tokens has since become the default specification for several mainstream models; and some models are now moving toward 10 million tokens. Long-context capability has shifted from a selling point to infrastructure.

    Behind this shift is a shared technical consensus: each query should no longer traverse all historical tokens. Instead, it should select only a small number of the most relevant tokens to attend to.

    This sparsification route has been repeatedly validated at the million-token scale. Whether through block-based top-k selection, hierarchical indexing, or hybrid architectures that combine sparse attention with linear attention, the core idea is the same: first perform coarse filtering, then exact computation, trading a controllable retrieval cost for savings in attention computation.

    1.2 The Problem Changes at the 10M-Token Scale

    However, as context length continues to 10 million tokens, an overhead that was once easy to ignore begins to spiral out of control. Take a typical global attention layer as an example. Measured data shows that when performing prefill at 10 million tokens, roughly 98% of the time is not spent on attention computation itself, but on the indexer that decides which tokens to attend to.

    This number reveals a fact that had been obscured: sparse attention solves the quadratic complexity of attention computation, but indexing itself may introduce a new quadratic overhead.

    Consider the logic. The workflow of conventional sparse attention is roughly as follows:

    1. 1. Compute relevance scores between the current query and all historical tokens
    2. 2. Select the top-k tokens by score
    3. 3. Perform the actual attention computation only on the selected tokens

    The cost of step 2 scales with the total number of tokens N, or even higher; if computed per query, it can reach O(N²). Step 3 is the part compressed to O(N·k). When N is in the millions, indexing overhead is still acceptable. But when N reaches 10 million, indexing cost grows far faster than attention computation itself and becomes the dominant cost.

    The nature of the problem therefore changes. Sparse attention has long shown that “looking at only a small subset” is enough to preserve accuracy. What truly blocks ultra-long contexts is that “finding that small subset” still grows quadratically with context length.

    2. LSA: Moving Indexing into Latent Space

    2.1 Core Idea

    To address this bottleneck, a recent research effort proposed a method called Latent Sparse Attention (LSA). Its core insight is: since full-dimensional token representations are too “heavy,” build a lightweight index in a low-dimensional latent space.

    LSA can be summarized in three steps:

    1. Dimensionality reduction projection: Map high-dimensional key vectors through a learnable linear projection into a very low-dimensional latent space, for example from 128 dimensions to 32 dimensions or even lower.
    2. Latent-space scoring: Project the query into the same latent space and quickly compute relevance scores against all tokens in the low-dimensional space. Because the dimension is substantially reduced, the matrix multiplication cost of this step drops sharply.
    3. Exact computation in the original space: Select top-k tokens based on latent-space scores, then return to the original high-dimensional space to perform standard attention computation.

    In pseudocode:

    1. # Conventional sparse attention: index scoring in high-dimensional space, costly
    2. scores = Q @ K.T # O(N * d), where d is high-dimensional
    3. topk_idx = scores.topk(k)
    4. # LSA: index scoring in low-dimensional latent space, sharply lower cost
    5. scores_latent = (Q @ Wq) @ (K @ Wk).T # O(N * d_latent), d_latent << d
    6. topk_idx = scores_latent.topk(k)
    7. attn_out = softmax(Q @ K[topk_idx].T / sqrt(d)) @ V[topk_idx]

    The key point is that the projection matrices Wq and Wk are learnable parameters optimized during model training or lightweight fine-tuning, so that latent-space scores approximate the ranking of high-dimensional scores as closely as possible. Research shows that top-k selection in attention is not sensitive to the absolute precision of scores; the ranking only needs to be approximately correct. This leaves room for aggressive dimensionality reduction.

    2.2 Why Latent-Space Scoring Is “Good Enough”

    There is a useful theoretical intuition here: attention filtering is essentially a retrieval problem, and retrieval tasks require far less representational precision than generation tasks. Just as recommender systems use a coarse-ranking model to select a candidate set and then a fine-ranking model to refine it, LSA uses low-dimensional “coarse ranking” to select candidate tokens, while high-dimensional “exact computation” is responsible for final output quality. As long as the recall of coarse ranking is high enough, end-to-end accuracy will not be harmed.

    In addition, low-dimensional projection naturally has a denoising effect: many components in high-dimensional keys contribute little to relevance judgments, and compression effectively learns a compact representation oriented toward the retrieval task.

    2.3 Hardware Friendliness

    Another advantage of LSA is that it fits modern acceleration hardware well. Low-dimensional scoring can be organized into regular matrix multiplications, fully utilizing tensor core throughput. By contrast, many earlier sparse attention schemes rely on extensive irregular gather/scatter operations or per-query branching logic, resulting in low actual GPU utilization. This is also why some schemes look better in theoretical complexity but run slowly in practice: algorithmic complexity is not equivalent to hardware efficiency.

    3. Measured Results and Engineering Implications

    3.1 Speedup Data

    Experimental results show that in a 10 million-token prefill scenario:

    • For a model using a hybrid sparse attention architecture, a single global attention layer was accelerated by about 22.7x.
    • For another medium-scale open-weight model, the speedup was about 72.4x.
    • On a range of tasks such as long-text understanding and retrieval-based question answering, accuracy remained basically on par with the original model.

    The large difference comes from how different models implement their indexers: the heavier the indexer itself, the more acceleration space is released when it is replaced by LSA.

    3.2 Implications for the Industry

    For engineering teams, this work offers three broadly applicable lessons:

    1. Identify the “hidden quadratic”: When optimizing a system, do not focus only on the computation that nominally dominates, such as attention itself. Profile first to find the real hotspot. In ultra-long-context scenarios, indexing, positional encoding, and KV-cache management can all become new bottlenecks.
    2. Design for tiered precision: Decouple “what to find” from “what to compute.” Use low-cost approximation for the former and high-precision computation for the latter. This is a common design pattern for long-context systems, RAG, vector retrieval, and many other systems.
    3. Dimension reduction is design, not compromise: For retrieval and filtering subtasks, aggressive low-dimensional compression can often trade a very small accuracy cost for order-of-magnitude performance gains.

    4. Outlook

    As context length moves toward 10 million and even 100 million tokens, indexing and retrieval efficiency will become one of the main battlegrounds for long-context architectures. Latent Sparse Attention demonstrates that the bottleneck is not unbreakable. The key is to reduce the cost of “finding” from quadratic in context length to lightweight computation that scales linearly. It is foreseeable that more attention variants will emerge, deeply coupling retrieval theory, quantization and compression, and hardware characteristics, pushing ultra-long contexts from merely working to running fast and being affordable.