Sparse Attention in Latent Space: 22x Faster Prefill at 10 Million Tokens

    As context windows grow from millions to tens of millions of tokens, the bottleneck of sparse attention shifts from computing attention to finding which tokens to attend to. This article breaks down the hidden cost of index scoring, explains how Latent Sparse Attention (LSA) moves retrieval into a fixed-dimension latent space to push indexing below quadratic complexity, and covers engineering practices for layered hybrid attention, caching, recall fallbacks, observability, and elastic resources, plus how to evaluate accuracy across task types and context lengths.

    Sparse Attention in Latent Space: 22x Faster Prefill at 10 Million Tokens

    1. The First Hurdle of Ultra-Long Context Has Moved

    Over the past two years, long context has shifted from an experimental feature to a default specification. Million-token context is becoming standard in many model services, and the industry commonly relies on hybrid architectures that combine sparse attention with linear attention: instead of having every query scan the entire token history, each query selects only a few of the most relevant segments to compute over.

    This approach has been validated repeatedly at the million-token scale. But as context keeps pushing toward 10 million tokens, an overhead that once seemed negligible starts to spiral. Take a global attention layer as an example: at the 10-million-token scale, most of the prefill time is not spent on the attention computation itself, but on the indexing step that “decides which tokens to look at.”

    The nature of the problem has therefore changed. Sparse attention has long proven that “looking at only a small fraction” is enough to preserve accuracy. What actually blocks ultra-long context is the cost of “finding that small fraction,” which still grows quadratically with context length.

    2. The Hidden Bill of Sparse Attention

    2.1 A Quick Look at the Cost Structure

    In standard full attention, every query computes relevance against all preceding keys. With a context length of T, prefill costs roughly O(T²), and decoding each token costs roughly O(T). Going from one million to 10 million tokens inflates the prefill attention computation by about 100x.

    The division of labor in sparse attention works like this: a lightweight indexer first picks the k most relevant keys for each query, then the real attention computes only over those k keys, compressing attention itself down to O(Tk).

    2.2 The Premise Holds, but the Cost Moves

    This approach rests on the premise that the model truly needs only a few keys. Industry validation shows that at the hundred-thousand-token scale, letting each query attend to only the few genuinely most relevant keys (less than about one percent of all keys) still preserves over 90% of full-attention accuracy on long-context benchmarks.

    But a paradox hides here: for the indexer to know which keys are most relevant, it must first score every key. Existing engineering solutions mostly “save” in three directions:

    • Lower scoring precision, replacing high-precision dot products with low-bit approximations;
    • Dimension compression, projecting keys into a lower-dimensional space before comparison;
    • Block sparsity, aggregating several adjacent keys into a single representative before scoring.

    These techniques ease the constant factors but do not change the order of magnitude: index scoring still traverses the entire key history, and the overall complexity remains close to quadratic.

    An illustrative complexity comparison:

    1. Full attention: O(T^2)
    2. Naive sparse attention: O(T^2) indexing + O(T*k) attention
    3. Target form: o(T^2) indexing + O(T*k) attention

    3. Latent Sparse Attention: Moving Retrieval into a Low-Dimensional Space

    A recent paper from a startup research team in collaboration with universities proposes Latent Sparse Attention (LSA). Its core idea is not to keep compressing scoring precision, but to change the space in which retrieval happens: first maintain a continuously updated low-dimensional representation in latent space, then perform relevance retrieval and candidate localization in that space.

    At the 10-million-token scale, the method speeds up prefill for a single attention layer by more than 20x, with speedups reaching tens of times on some small and mid-sized models, while maintaining accuracy close to the original model across multiple long-context tasks.

    3.1 Three Key Designs

    • Latent-space compression: map historical keys and values into fixed-dimension latent representations, so retrieval no longer grows linearly with history length;
    • Incremental index maintenance: when new tokens arrive, update only the latent state, avoiding a full global index rebuild;
    • Two-stage localization: first coarse-filter candidate blocks in latent space, then precisely compute a small number of keys at original precision, balancing recall and accuracy.

    3.2 Why It Drops Below Quadratic

    The key is decoupling retrieval scale from context length. The latent representation has a fixed dimension, so the retrieval cost of a single query is roughly constant, and the overall indexing overhead drops from O(T²) to a near-linear accumulation close to O(T), bringing it into the sub-quadratic range. This is also where “more than 20x faster at 10 million tokens” comes from: the longer the context, the more pronounced the savings.

    4. Engineering Implementation Notes

    • Layered hybrid: enable latent-space retrieval only for global layers, and keep window attention for local layers to control complexity and memory usage;
    • Caching strategy: latent states can stay resident alongside the key-value cache, and paged memory management can help reduce fragmentation;
    • Recall fallback: for queries with low retrieval confidence, fall back to a larger candidate set to prevent accuracy drops on long-tail tasks;
    • Observability: instrument indexing latency, recall rate, and candidate hit rate in logging, monitoring, and alerting to pinpoint bottlenecks;
    • Elastic resources: training and inference workloads can run on a container platform, with long-context samples archived in object storage for easier reproduction and evaluation.

    5. Recommendations for Accuracy Evaluation

    Do not rely on a single benchmark. It is recommended to cover three task types: single-hop retrieval, multi-hop reasoning, and global aggregation; and to build scaling curves across different context lengths to observe how the accuracy decay slope behaves as length grows. If accuracy stays roughly flat when length doubles, retrieval recall is stable; if there is a cliff, prioritize checking the latent-space dimension and candidate block size.

    6. Conclusion

    The focus of the ultra-long-context race is shifting from “computing fast” to “finding accurately and cheaply.” Latent Sparse Attention offers a viable path to push indexing cost into the sub-quadratic range. For engineering teams, it is worth validating its recall and latency behavior on their own data distribution early, so the architecture is ready for 10-million-token context.