10M Token Context: The Key Leap That Makes Sparse Attention 22x Faster

    As context windows scale toward 10 million tokens, the bottleneck in sparse attention shifts from computing attention to finding the relevant tokens. This article breaks down the cost structure of full and sparse attention, explains how Latent Sparse Attention moves relevance search into a fixed-dimensional latent space to achieve near-linear indexing, and outlines the conditions for preserving accuracy, engineering considerations, and evaluation methods for verifying sub-quadratic scaling.

    1. The Problem: When Context Grows, the Bill Moves

    Over the past two years, long context has shifted from an optional feature to a default specification. Million-token context is becoming standard across many model services, and 10M-token context is now being pushed to the front. The core technical choice supporting this trend is highly consistent: instead of having each query traverse all historical tokens, only a few of the most relevant keys are selected to participate in the computation.

    This approach has been repeatedly validated at the million-token scale. But when the length grows another tenfold, an originally unremarkable overhead starts to spiral out of control. Take a global attention layer as an example: during prefill at 10M tokens, roughly 98% of the time is not spent on attention itself, but on the indexer 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 subset” is enough to preserve accuracy. What actually blocks ultra-long context is the cost of “finding that small subset,” which still grows quadratically with context length.

    2. Cost Breakdown: Attention Is Cheap, Retrieval Is Expensive

    The cost structure of standard full attention is clear: with context length T, prefill computation is roughly O(T²), and decoding each token costs about O(T). Going from 1M to 10M length increases attention computation by about 100x.

    Sparse attention divides the work as follows: a lightweight indexer first selects the k most relevant keys for each query, then the actual attention computes only over those k keys, reducing the attention body to O(Tk). This idea holds under one premise: the model really does need only a few keys. Existing validation shows that at 128k length, letting each query attend to only its 512 most relevant keys (about 0.8% of all keys) still retains roughly 98% of full-attention accuracy on long-context benchmarks.

    But a paradox hides here: for the indexer to know which 512 keys are most relevant, it must first score every key. Common industry practices include lowering scoring precision, compressing dimensions, or merging multiple keys into a block, but these only shrink the constant factor. They cannot change the quadratic nature of “the number of scoring operations grows with T, and every query has to score once.”

    A schematic complexity comparison helps convey the gap (with k fixed):

    1. Full attention: O(T^2)
    2. Block sparse + indexer: O(T^2 / b) # b is block size; constant-factor optimization only
    3. Latent-space sparse: O(T * d + T * k) # d is latent dimension, d << T

    3. The Core Idea: Move “Finding Relevance” into Latent Space

    A newly proposed class of methods can be summarized as Latent Sparse Attention. The key is not to make the indexer faster, but to change the medium in which the indexer operates: instead of pairwise comparison in the original token dimension, the long sequence is first compressed into a set of low-dimensional “latent representations,” and relevance retrieval is then performed in latent space.

    The logic chain breaks into four steps:

    1. Dimensionality reduction: map each (or each block of) key to a latent vector of fixed dimension d, where d is independent of sequence length.
    2. Latent-space scoring: the query is projected into the same latent space and dotted with the latent vectors to approximate relevance.
    3. Candidate recall: select the top-k candidates in latent space, then map them back to original token positions.
    4. Exact attention: perform the real attention computation only on the selected k original keys.

    Because the scoring in step 2 happens over a fixed dimension d, the indexing overhead changes from “growing quadratically with T” to “growing nearly linearly with T.” This is the source of the leap from quadratic to sub-quadratic.

    Schematic pseudocode:

    1. # Pseudocode: expresses structure only, not a concrete API
    2. def latent_sparse_prefill(Q, K, V, d, k):
    3. # 1) Build latent representations (jointly trained with the model or via low-rank projection)
    4. K_lat = project_to_latent(K, dim=d) # [T, d]
    5. Q_lat = project_to_latent(Q, dim=d) # [T, d]
    6. # 2) Latent-space scoring and recall (near-linear)
    7. scores = Q_lat @ K_lat.T # [T, T] but dimension is d, so the constant is tiny
    8. idx = topk(scores, k=k) # each query selects k
    9. # 3) Exact attention only on candidates
    10. out = []
    11. for i in range(T):
    12. sel = idx[i]
    13. out.append(softmax(Q[i] @ K[sel].T) @ V[sel])
    14. return stack(out)

    4. Why Accuracy Is Preserved

    Latent-space retrieval does not significantly degrade accuracy because of three conditions:

    • Latent representations aligned with the task: the projection matrix is not randomly fixed but jointly optimized with the model’s training objective, so that “proximity in latent space” approximates “high relevance in the original space.”
    • Recall can compensate: k does not need to be large, but candidate recall must be stable. Common approaches include multi-probe/multi-hash or hierarchical clustering to reduce the probability of “missing the truly relevant key.”
    • Exact layer as a fallback: the final attention is still computed on the original keys. Latent space is only responsible for “nomination,” not “finalization,” so the approximation error is confined to the recall stage.

    5. Engineering Implementation Notes

    • Memory and bandwidth: the latent vectors are T×d. When d is on the order of tens to one hundred, this is far smaller than the original KV’s T×head_dim, significantly easing memory-access pressure.
    • Coordination with blocking strategies: coarse filtering can be done at the block level with latent representations, then token-level re-ranking within blocks, forming two-level recall.
    • Training/fine-tuning cost: if the model does not have a built-in latent projection, a lightweight alignment training is needed. In practice, the backbone can be frozen and only the projection and recall modules trained.
    • Decoding stage: prefill builds the candidate index via latent-space recall, which can be reused during decode to reduce the per-step O(T) constant.
    • Observability: it is recommended to monitor “recall hit rate,” “the proportion of truly high-relevance items in top-k,” and “indexing time share per layer” to avoid the optimization drifting off course.
    • Baselines: compare full attention, block sparse, and latent-space sparse under identical conditions.
    • Metric combination: long-context understanding benchmark accuracy + prefill latency + peak memory + recall hit rate.
    • Length sweep: plot latency curves at 128k / 1M / 4M / 10M to verify genuine sub-quadratic behavior.
    • Ablation studies: vary the latent dimension d, the candidate count k, and the number of recall probes to observe the accuracy–speed tradeoff.

    7. Conclusion

    When context reaches the ten-million scale, the focus of optimization shifts from “computing faster” to “finding more cheaply.” The value of Latent Sparse Attention is precisely to free retrieval from the quadratic trap, making order-of-magnitude speedup of ultra-long-context prefill possible. For engineering teams, the path is clear: first align the latent projection, then build two-level recall, and finally use length-sweep curves to verify the sub-quadratic characteristics.