Latent Sparse Attention: Subquadratic Indexing for Ultra-Long Context
As context windows grow toward tens of millions of tokens, sparse attention’s indexer—not the attention calculation itself—becomes the dominant prefill cost. This article explains the cost structure behind that bottleneck and introduces Latent Sparse Attention (LSA), which moves candidate retrieval into a low-dimensional latent space to achieve subquadratic indexing. It also covers LSA’s design trade-offs, measured speedups, engineering implications, and remaining limitations.
Background: Ultra-Long Context Is Becoming a Default Requirement
Large model context windows have expanded rapidly over the past year. What began with support for hundreds of thousands of tokens has moved toward million-token contexts as a default configuration across multiple providers. Long-text processing has shifted from a nice-to-have feature to a foundational model capability. Some newly released models have begun to combine sparse attention and linear attention at the architecture level, so that each query no longer traverses the entire history but instead selects a small number of the most relevant tokens for computation.
This approach has been repeatedly validated at the million-token scale. However, as context sizes continue to move toward tens of millions of tokens, a previously minor overhead begins to spiral out of control. Measured data shows that when performing prefill at 10 million tokens, roughly 98% of the time in a single global attention layer is not spent on the attention computation itself, but on the indexer that decides which tokens to look at.
The nature of the problem therefore changes. Sparse attention has already demonstrated that “looking at only a small subset” is enough to preserve accuracy. What actually blocks ultra-long context is that the process of “finding that small subset” still grows quadratically with context length.
The Cost Structure of Sparse Attention and Its Hidden Bill
First, consider the cost structure of attention. In standard full attention, every query computes relevance against all previous keys. When the context length is T, prefill computation is O(T²), and decoding each token costs O(T). As context grows from 1 million to 10 million tokens, the attention computation for prefill alone increases by 100×.
The idea behind sparse attention is to divide the work:
- Indexer: a lightweight module that selects the k most relevant candidates from all keys for each query.
- Sparse attention: the actual attention computation is performed only on those k keys, reducing cost to O(Tk).
This idea depends on one premise: the model truly needs only a small number of keys. Relevant validation shows that at 128k tokens, letting each query attend only to about 0.8% of the keys that are truly most relevant still preserves 98% of full-attention accuracy on long-context benchmarks.
But there is a paradox here: for the indexer to know which k keys are most relevant, it must first score every key. Common block-sparse approaches reduce the indexer’s burden by lowering scoring precision, reducing scoring dimensions, or compressing multiple keys into a block. These methods can reduce constants, but they cannot change the fact that index scoring is fundamentally O(T²). When T reaches tens of millions, even a small constant makes indexing the absolute bottleneck.
LSA: Moving Indexing into Latent Space
A recent study proposes a method called Latent Sparse Attention (LSA). Its core idea is: do not have the indexer score every key in the original token space one by one; instead, first compress keys into a low-dimensional latent space and perform retrieval there.
Core Mechanism
LSA can be broken down into three steps:
- Latent space projection: through a learnable projection, each key representation is compressed into a very low dimension. Because the compressed vector size is much smaller than the original key dimension, the cost of computing relevance between a query and compressed keys drops substantially.
- Coarse-grained retrieval: in latent space, each query performs a lightweight scoring pass against all compressed keys to quickly filter candidate blocks. The complexity of this step is proportional to the compressed dimension rather than the original dimension. More importantly, with blocking and hierarchical design, the overall retrieval complexity can be made subquadratic.
- Exact computation: full attention computation is performed on the original keys within candidate blocks, ensuring that final accuracy is not affected by latent-space approximation.
An intuitive analogy: rather than flipping through every page in a library, first consult a highly condensed catalog card, identify the target shelf, and then read the original text closely. The catalog card is small enough that lookup cost is almost negligible, while what is finally read is still the original text, with no loss of accuracy.
Key Design Trade-offs
Latent-space compression inevitably introduces information loss. LSA controls this risk through several design choices:
- Used for retrieval only, not for computation: latent vectors only handle scoring and filtering. Attention weights are still computed from original keys and values, so approximation error does not directly enter the output.
- Joint optimization during training: the projection matrix is trained jointly with the main model so that latent-space retrieval results align as closely as possible with the true attention distribution, avoiding cases where “what should be seen is not selected.”
- Adjustable block granularity: larger blocks mean fewer retrieval steps but more candidate redundancy; smaller blocks do the opposite. In practice, a trade-off is needed between the two.
Measured Results and Engineering Implications
Experimental results show that at the 10-million-token scale:
- For models using hybrid sparse architectures, LSA can speed up prefill in a single global attention layer by about 22×.
- For full-attention models at mainstream open-source scale, because indexing overhead accounts for a larger share, speedup can exceed 70×.
- On multiple long-context evaluation tasks, accuracy is basically on par with the original model.
The engineering implications can be understood on three levels:
- Training side: lower prefill computation directly reduces the time and compute cost of training on ultra-long texts, making training samples at the 10-million-token level economically feasible.
- Inference side: batch processing throughput for long documents, code repositories, and multi-turn conversations improves significantly. This is especially valuable for scenarios that need to ingest massive context at once, such as full-repository code understanding and long-range document analysis.
- Architecture insight: it reveals a more general principle—the bottleneck of sparsification often lies in “selection” rather than “computation.” Making the selection process itself sparse and hierarchical is a key path toward ultra-long context.
Limitations and Outlook
LSA is not without costs. Latent-space projection requires additional training, and post-adaptation to existing models faces difficulties in distribution alignment. Very-low-dimensional compression still needs robustness validation on “needle-in-a-haystack” tasks that require precise localization. In addition, how to maintain the same advantages during decoding, rather than only during prefill, is a problem that remains to be addressed.
It is reasonable to expect that as context scales continue to expand, the problem of “retrieval as the computational bottleneck” will become more prominent. Moving attention retrieval into a low-dimensional latent space and completing candidate filtering with subquadratic complexity is likely to become a standard component of next-generation ultra-long-context architectures. For enterprise scenarios that need to process ultra-long documents and large-scale code in the cloud, combining such techniques with infrastructure such as object storage and containerized inference services will help move million- and even 10-million-token applications from experimentation into production.
