Sparse Attention Gets 22× Faster at 10M Tokens with Latent-Space Indexing

    Latent Sparse Attention (LSA) addresses the hidden cost of sparse attention: finding the relevant keys can remain nearly as expensive as dense attention. By performing query-key scoring in a much lower-dimensional latent space, LSA reduces indexing overhead while preserving high-dimensional attention for the final Top-k candidates. Experiments at a 10M-token context show up to 22× faster prefill for one sparse-attention model and 72× for another 27B-parameter open-source model, with more than 98% of full-attention accuracy on 128K-token RULER evaluations.

    From “Read Everything” to “Find the Relevant Parts”: Where Attention Costs Move

    When a large language model processes long documents, full attention requires every query to calculate similarity against every historical key. If the context length is T, attention computation during prefill has a complexity of O(T²). During decoding, generating each new token requires O(T) work.

    As the context window grows from 1 million to 10 million tokens, the attention computation required for a single prefill operation increases by roughly 100×. This has become one of the main bottlenecks in long-context inference.

    Sparse attention offers a practical way to address this problem. Instead of allowing every query to interact with every key, a lightweight indexer dynamically selects the k keys most relevant to each query. The full attention calculation is then restricted to this small subset.

    In theory, this reduces the attention component to O(Tk) or less, enabling substantial gains for extremely long contexts.

    However, the strategy of “attending to only a few keys” introduces a hidden engineering cost. The indexer still has to determine which keys are relevant. Its own computation can become a new bottleneck.

    The Indexer’s “Quadratic Curse”

    Consider a global attention layer in a mainstream large language model. During prefill with a 10-million-token context, approximately 98% of the computation time is spent not on attention-weighted aggregation, but on the indexer calculating relevance scores between every query and every key.

    Sparse attention allows the model to “read” only a small portion of the sequence, but finding that portion may still require scanning the entire history. Because this global scan grows linearly with sequence length for every query, the overall computation graph retains the footprint of quadratic complexity.

    At million- and especially ten-million-token scale, the supposedly lightweight “find” stage can cost more than the “read” stage. This substantially reduces the practical benefit of sparsity.

    The problem exposes a fundamental tension in sparse attention:

    The attention operation can be sparse, but the addressing process may remain dense.

    To identify the keys most relevant to a query with high precision, the system must score all historical keys. In essence, the addressing step becomes another quadratic operation.

    Latent Sparse Attention: Performing Search in a Low-Dimensional Space

    Latent Sparse Attention (LSA) offers a solution to this problem. Its central idea is straightforward:

    If the entire history must be screened before sparse attention is performed, carry out that expensive scoring step in a much smaller latent space.

    1. Core Principle: Dimension Reduction and Scoring Decoupling

    In conventional sparse attention, the indexer typically computes query-key similarity in the same high-dimensional feature space used for attention. LSA instead applies lightweight linear projections or small multilayer perceptrons (MLPs) to map the original query and key vectors into a very low-dimensional latent space.

    For example, a head dimension of 512 can be projected to 16 dimensions. The indexer then scores all historical keys in this compressed space at a much lower cost and selects the Top-k candidates. Only those candidates are mapped back to the original high-dimensional space for standard attention-weighted aggregation.

    This design separates “scoring” from “reading.” Although the indexer still performs work that grows linearly with sequence length, its operating dimension is much smaller. At a 10M-token context, this significantly reduces execution time and removes the indexing bottleneck.

    2. Performance: 22× Speedup While Preserving Accuracy

    In a series of controlled experiments, LSA improved the prefill speed of an individual attention layer by approximately 22× at a 10M-token context for a model using a hybrid sparse-attention architecture.

    For another open-source model with 27 billion parameters, the speedup reached 72×.

    Importantly, these gains did not require sacrificing model accuracy. On long-context understanding benchmarks such as RULER, LSA retained more than 98% of full-attention accuracy at a 128K-token context.

    LSA is also compatible with existing sparse-attention implementations. It does not require a broad redesign of the original attention-head structure and can replace the existing indexer within a sparse-attention module. The candidate-set size k can also be adjusted dynamically, allowing deployments to balance accuracy and performance according to their requirements.

    Technical Details and Engineering Considerations

    Developers looking to reproduce or adapt the LSA approach should pay attention to several implementation details.

    1. Choosing the Projection Dimension

    The projection dimension is a critical hyperparameter in latent-space design.

    If the dimension is too small, excessive compression can reduce retrieval recall and hurt model accuracy. If it is too large, the indexer loses much of its computational advantage.

    Experiments indicate that, for typical model configurations, compressing the original head dimension to approximately one-quarter to one-eighth of its original size provides a reasonable balance between accuracy and performance.

    2. Training the Indexer

    The latent-space indexer is not a manually defined heuristic. It must be trained end to end.

    A two-stage training strategy is recommended:

    1. Train the projection layers separately. Keep the original attention mechanism unchanged while training the projection parameters to preserve query-key relative-distance information with high fidelity.
    2. Perform joint fine-tuning. Fine-tune the projection layers together with the rest of the model so that the latent representation adapts to updates in other model weights and delivers the best performance on the final task.

    3. Combining LSA with Hierarchical Attention

    For contexts containing tens of millions of tokens, it is not necessary for every attention layer to use global sparse attention.

    A common design is a hierarchical hybrid architecture:

    • Lower layers near the input use sliding-window attention to capture local semantics.
    • Only selected deeper layers retain global attention.
    • LSA is applied to those global layers to reduce their indexing cost.

    This structure further reduces computation while helping the model balance local details and long-range dependencies.

    4. I/O Optimization in Production Implementations

    When implementing LSA with CUDA kernels or integrating it into an inference framework, memory bandwidth can become a major constraint.

    The key matrix for a 10M-token context is extremely large, and the indexer may repeatedly access it from device memory. A block-wise retrieval strategy is therefore recommended:

    1. Filter candidates at a coarse block level.
    2. Re-rank keys within the selected blocks at a finer granularity.

    This approach reduces memory traffic and minimizes time spent waiting on I/O.

    From Attention to Retrieval: The Future of Longer Contexts

    LSA reflects a broader shift in how long-context processing should be understood. At extremely long sequence lengths, attention is increasingly becoming a retrieval problem.

    Once the context reaches a certain scale, the model’s primary challenge is not necessarily to apply complex transformations to every piece of information. It is to retrieve the information relevant to the current token from a massive external knowledge base or historical memory, both accurately and efficiently.

    From an information-theoretic perspective, the explicit indexer is essentially an approximate maximum inner product search (MIPS) system. By projecting vectors into a lower-dimensional space, LSA separates retrieval from the original representation space and avoids the high cost of inner-product calculations in a high-dimensional space.

    This direction suggests several possible paths for future long-context systems. If retrieval is the central operation, strict inner-product search could potentially be replaced with more efficient approximate nearest-neighbor (ANN) methods. Techniques such as product quantization (PQ) could also be incorporated into indexer design to further control the computational growth of extremely long contexts.

    Conclusion

    A context window of tens of millions of tokens is becoming more than a marketing claim. It is increasingly relevant to high-value applications such as financial analysis, codebase understanding, and multi-document reasoning.

    Latent Sparse Attention shows that, for extremely long inputs, the main performance bottleneck is shifting from how deeply the model reads to how quickly it can find the right information.

    By constraining indexer computation to a low-dimensional space, LSA delivers speedups of more than 22× in the reported 10M-token setting and provides a clear direction for the next generation of long-context architectures.

    Hybrid designs based on low-dimensional addressing and high-dimensional reading may become a standard approach for models with billions or tens of billions of parameters that need to process inputs ranging from millions to tens of millions of tokens.