Sparse Attention at 10 Million Tokens: Why the Indexer Becomes the Bottleneck and How Latent Space Delivers a 22x Speedup
As context windows scale from millions to tens of millions of tokens, sparse attention removes the quadratic cost of attention itself but exposes a new dominant cost: the indexer that decides which tokens to attend to. This article breaks down the three stages of a sparse attention call, explains why scoring still grows quadratically and is memory-bandwidth bound, and walks through Latent Sparse Attention (LSA), which moves retrieval into a low-dimensional latent space to cut complexity to roughly O(n*m + n*k). It also covers the design choices that preserve accuracy, engineering considerations for production, and the reported single-operator speedups of about 22.7x for a hybrid architecture model and 72.4x for a dense model at 10 million tokens.
1. Background: How Longer Contexts Change the Cost Structure
Over the past two years, long context has moved from an experimental feature to a default specification. Million-token context windows are now standard in many general-purpose LLM services, and the industry has begun pushing toward tens of millions of tokens. The core idea behind this progression is not new: instead of having every query scan all historical tokens, only a small set of the most relevant tokens participates in the computation. This “attend to a small subset” approach has been validated repeatedly at the million-token scale, controlling the quadratic growth of attention computation while keeping accuracy close to dense attention.
But as the context grows to the tens-of-millions range, an overhead that used to be unremarkable starts to spiral. Take one global attention layer in a hybrid architecture model: at 10 million tokens during the prefill stage, roughly 98% of the time is spent not on the attention computation itself, but on the indexer that decides which tokens to look at.
This changes the nature of the problem. Sparse attention has already shown that looking at less does not hurt accuracy. What actually blocks ultra-long context is that “finding the small subset worth looking at” still grows quadratically with context length.
2. Breaking Down the Bottleneck: Why the Indexer Dominates
To understand the significance of this speedup, split a sparse attention call into three stages:
- Scoring: estimate the relevance between each query and all historical tokens;
- Selection: pick the top-k indices from the scores;
- Aggregation: compute a weighted sum over only the selected k tokens.
In dense attention, the second stage barely exists, and the first and third together form the O(n²) bulk. Sparsification reduces the third stage to O(n·k), but if the first stage still scores pair by pair in the original token space, its complexity remains O(n²). When n grows from 10⁶ to 10⁷, this term grows 100x, and the indexer goes from supporting role to lead.
Two engineering factors amplify the problem:
- Memory-bandwidth bound: scoring is a typical memory-bandwidth-intensive operation, leaving compute units largely idle;
- Dynamic branching: top-k selection introduces data-dependent branches that compilers and hardware pipelines struggle to parallelize.
3. The Core Idea: Move Relevant-Token Retrieval into Latent Space
A recent paper from a startup research organization and university collaborators proposes Latent Sparse Attention (LSA), which moves the indexing process from the original token space into a low-dimensional latent space:
- A set of learnable latents compresses the historical context into a representation far shorter than the raw token count;
- the query first performs a small-scale similarity computation against the latents to obtain candidate blocks or clusters;
- fine-grained top-k selection happens only within the candidate set, and aggregation is completed over the original tokens.
The intuition: instead of searching for one sentence by scanning every book in an entire library, you first consult a compressed index card, locate a few shelves, and then search only those shelves. Complexity drops from O(n²) to roughly O(n·m + n·k), where m is the number of latents and m ≪ n.
The paper reports that at 10 million tokens, for the prefill stage of a single global attention layer, the hybrid architecture model is about 22.7x faster and a dense model tier is about 72.4x faster, while maintaining accuracy close to the original model across multiple tasks. Note that this is a single-operator-level speedup; the end-to-end gain depends on how much of the full network that operator represents.
Illustrative pseudocode:
# Pseudocode: expresses the flow only, not a real APIlatents = compress(context, num_latents=m) # Build the latent-space index oncecoarse = query @ latents.T # O(n*m) coarse filteringblocks = topk(coarse, k=blocks_per_query) # Candidate blocksidx = fine_topk(query, context, blocks) # Fine ranking within candidatesout = weighted_sum(query, context[idx]) # Aggregate over selected tokens only
4. Why Accuracy Holds: Three Key Design Choices
- Separate coarse filtering from fine ranking: the latent space handles recall only, not final weights, so recall errors are corrected by the subsequent fine ranking;
- Consistency between training and inference: the latents and the indexing path must participate in training, so the model learns to write information into a retrievable latent space rather than bolting it on afterward;
- Coordination with hybrid architectures: linear attention handles local and short-range dependencies while the global sparse layer handles long-range retrieval, so the two mechanisms share the load instead of overloading a single one.
5. Engineering Notes for Production
- Operator fusion: fuse scoring, selection, and aggregation into a single kernel to reduce round trips of intermediate tensors;
- Chunking and pipelining: build the latent index by chunks, and reuse the same index structure across prefill and decoding;
- Memory and bandwidth budgeting: latents carry a persistent overhead, so capacity planning must account for batch size and sequence length;
- Accuracy regression: build a long-context evaluation set that emphasizes needle-in-a-haystack retrieval and multi-hop reasoning;
- Cloud deployment: elastic scaling, model distribution, and full-chain observability can rely on general-purpose container platforms, object storage, logging services, and monitoring and alerting capabilities, avoiding lock-in to a specific vendor’s interfaces.
6. Conclusion
In the era of tens of millions of tokens, the competitive focus is shifting from “can it be computed” to “can the part that needs computing be found quickly.” The value of latent sparse attention is that it pushes indexing complexity from quadratic back to near-linear, offering a reusable optimization pattern for ultra-long-context inference. For developers, the real takeaway is not a specific number but an analysis framework: first identify the dominant cost, then decide whether to optimize computation, memory access, or indexing.
