Sparse Attention at 10 Million Tokens: Key Practices for 22x Faster Prefill

    As million-token context windows become a default feature, the bottleneck in long-context inference is shifting from how much attention computes to how fast it can select the right tokens. This article explains why sparse attention still struggles at the 10-million-token scale, where an indexer can consume about 98% of prefill time, and how Latent Sparse Attention moves candidate retrieval into a compressed latent space to make selection nearly linear. It covers the two-stage retrieve-then-compute design, why accuracy holds when top-k recall is high, and practical guidance on layer design, index reuse, monitoring, and elastic resources.

    Sparse Attention at 10 Million Tokens: Key Practices for 22x Faster Prefill

    Long Context Is Becoming the Default

    Over the past year, long context has shifted from a flagship differentiator to a baseline capability. Million-token context is already the default in several model services, and models that support it are no longer rare. The competitive focus has moved from whether a model can support long context to whether inference over long context is cheap and fast enough.

    For developers, this means two things. First, applications can hand an entire manual, a whole code repository, or a full day of meeting notes to the model in one pass, without complex chunking and retrieval stitching. Second, the cost and latency profile changes completely: the longer the context, the heavier the load on the prefill stage, and the harder time to first token (TTFT) becomes to control.

    Sparse Attention Solves “Computing Too Much,” Not “Searching Too Slowly”

    The core difficulty of long context is that attention cost grows quadratically with sequence length. The mainstream approach is sparse attention: instead of scanning every historical token, each query attends to only a few of the most relevant ones. This approach has been repeatedly validated at the million-token scale, with controllable accuracy loss.

    But at the 10-million-token scale, an otherwise minor cost spirals out of control. Consider the global attention layers of a hybrid-attention model that supports million-token context. During prefill at 10 million tokens, roughly 98% of the time is spent not on attention computation itself, but on the indexer that decides which tokens to look at.

    The nature of the problem has changed. Sparse attention has shown that attending to a small subset is enough to preserve accuracy; what actually blocks ultra-long context is that the cost of finding that subset still grows quickly with context length. In other words, the compute has been reduced, but selection cost has become the new dominant term.

    Latent Sparse Attention: Making the Search Cheap Too

    A recent paper from a startup research team and university collaborators introduces Latent Sparse Attention. Instead of further optimizing how attention is computed, it rethinks how candidates are selected: retrieval over candidate tokens moves from the original high-resolution representation into a compressed latent space, where a low-dimensional, low-cost representation performs coarse filtering before returning to the original representation for fine-grained attention.

    The reported gains are substantial: at the 10-million-token scale, prefill for a single attention layer is more than 20x faster, with speedups reaching tens of times in some model configurations, while maintaining accuracy close to the original model across a range of tasks.

    It can be understood as two-stage retrieval:

    1. # Pseudocode: coarse filtering in latent space + fine computation in original space
    2. latent = compress(hidden_states) # Build a low-dimensional index once
    3. scores = query_latent @ latent.T # Low-dimensional scoring at much lower cost
    4. topk = select_topk(scores, k) # Select a few candidates
    5. out = attention(q, k[topk], v[topk]) # Exact attention over candidates only

    The key point is that the compressed index is reusable, the scoring dimensionality is low, and the candidate set is small. Together, these bring selection cost down from quadratic to nearly linear.

    Why Accuracy Holds

    The risk of latent-space coarse filtering is missing tokens that are truly relevant. The method mitigates this in two ways. First, the compressed representation retains enough information for relevance ranking; coarse filtering only needs high recall, not exact ordering. Second, the fine computation stage still runs on the original representation, so once a candidate enters the top-k, attention weight computation is identical to a standard implementation. Accuracy therefore depends mainly on top-k recall rather than the fidelity of the compression itself.

    In practice, treat k as a tunable knob: a larger k improves recall and stability but reduces the gain; a smaller k is faster but needs validation against the specific task.

    Implementation Recommendations

    • Layered design: use sparse or latent-space retrieval for global layers and keep sliding windows for local layers, balancing long-range coverage and local detail.
    • Index reuse: the compressed index can be updated incrementally during decoding, avoiding a rebuild at every step.
    • Monitor first: use monitoring and alerting to track TTFT, the share of prefill time, and top-k hit rate, and determine whether the bottleneck is in the indexer.
    • Elastic resources: ultra-long-context prefill is bursty, so container platforms and message queues can help smooth peaks and enable asynchronous processing.
    • General cloud capabilities: object storage can hold long documents, and log services can record retrieval hit distributions. Both are general-purpose categories with free choice of provider.

    Conclusion

    In the 10-million-token era, long-context optimization has shifted from computing less to selecting faster. Latent Sparse Attention offers a viable path that brings selection cost close to linear, delivering tens-of-times prefill speedups while preserving accuracy. For developers, the real takeaway is not a specific number but a reusable methodology: first determine whether the bottleneck is in computing or in selection, then choose the optimization direction.