Sparse Attention at 10 Million Tokens: The Indexing Breakthrough Behind a 22x Speedup
Long-context models are moving from million-token to ten-million-token windows, and the bottleneck is shifting from attention computation to token selection. This article explains why the indexing cost of sparse attention grows quadratically, how Latent Sparse Attention moves relevance scoring into a compressed latent space to bring that cost close to linear, why accuracy holds up, and how to evaluate the approach in your own inference stack. Reported results show roughly 22.7x and 72.4x prefill speedups for a single attention layer at ten-million-token scale, plus a practical engineering checklist covering baseline measurement, prototype validation, kernel fusion, accuracy regression, and capacity planning.
1. Ultra-Long Context Is Rewriting the Cost Structure
Over the past two years, long context has shifted from a differentiating feature to a baseline specification. Million-token windows are becoming the default configuration for mainstream model services, and hybrid attention architectures—stacking global attention layers alternately with linear attention layers—are now widely adopted. Instead of scanning the entire history for every query vector, each query selects only a few of the most relevant segments to compute over.
At the million-token scale, this route has been validated repeatedly: accuracy is essentially unchanged, while memory and compute stay manageable. Push the context to ten million tokens, however, and an overhead that once looked negligible starts to spiral.
Consider one global attention layer in a ten-million-token-context model. During the prefill phase at that scale, roughly 98% of the time is spent not on the attention operator itself, but on the indexer that decides which tokens to look at.
The nature of the problem therefore changes. Sparse attention has long proven 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 quadratically with context length.
2. Why Indexing Cost Grows Quadratically
To understand the math, break the prefill phase apart. Let the sequence length be N. Each query must first be scored for relevance against every historical position, and that scoring step is on the order of N squared. Only afterward does attention aggregate over the selected k positions, at a cost of roughly N times k.
At the million-token scale, the N-squared term is absorbed by a highly optimized scoring kernel and its share is unremarkable. At ten million tokens, the N-squared term grows by two orders of magnitude while N times k grows only linearly, so the indexer goes from supporting role to lead.
Three engineering factors amplify the effect:
- Scoring must read the entire key-value cache, so bandwidth pressure rises linearly with N while compute utilization drops because the kernel becomes memory-bound.
- Block granularity introduces quantization loss: larger blocks make selection coarser, smaller blocks raise scheduling overhead.
- The index result is itself a sparse pattern of length N, and writing it back and synchronizing it across a multi-device split adds communication cost.
An illustrative cost comparison (pseudocode, showing order of magnitude only):
# Traditional sparse attention: score everything, then aggregate sparselyscores = q @ K.T # O(N^2), the main bottleneck at ten-million-token scaleidx = topk(scores, k) # selection cost proportional to Nout = sparse_aggregate(q, K, V, idx) # O(N * k)
3. Latent Sparse Attention: Moving the Search into a Lower-Dimensional Space
A recent paper from a joint team at a startup research lab and a university proposes Latent Sparse Attention. Its core idea is to move the relevance judgment out of the original high-dimensional key space and into a compressed latent space.
The approach has three steps:
- Learn a set of low-rank projections, offline or online, that compress each position’s key into a latent vector with far fewer dimensions than the head dimension.
- Perform block-level relevance scoring and filtering inside the latent space. The lower scoring dimension yields a constant-factor speedup, and combined with blocking and approximate retrieval, it pushes complexity from quadratic down to near-linear.
- Run exact attention aggregation in the original space only for the selected blocks, so output quality is not contaminated by compression error.
The key is the division of labor: coarse filtering in the latent space, exact computation in the original space. Compression affects only candidate generation, not the final numerical path, so accuracy loss is confined to the possibility of missing a relevant block—and block-level redundancy plus overlapping candidates substantially reduce that probability.
The paper reports that at ten-million-token scale, prefill for a single attention layer achieves roughly 22.7x and 72.4x speedups over existing sparse attention methods while maintaining comparable accuracy. Note that these are single-layer, single-stage speedups; end-to-end gains depend on the indexer’s share of runtime, the number of layers, and the parallelism strategy.
4. Why Accuracy Holds Up
Sparse attention accuracy depends on two conditions: the attention distribution is concentrated enough, and the selection granularity is fine enough. The latent-space approach makes an engineering tradeoff on both:
- The low-rank projection preserves the directions of greatest variance in the key vectors, and those directions typically dominate the similarity ranking.
- Block-level filtering with overlapping windows is effectively a second recall pass for boundary samples.
- Linear attention layers handle global information aggregation, so global layers only need to fill in local detail, leaving more room for error.
The practical recommendation is to set budgets per layer: finer granularity in lower layers, coarser in upper layers. Raise the candidate count for retrieval and long-document question answering workloads, and tighten it moderately for summarization and code completion.
5. Adoption Path and Engineering Checklist
To evaluate a similar approach in your own inference stack, proceed in this order:
- Baseline measurement: quantify how much of prefill time the indexer consumes, and confirm whether an “index-dominated” problem actually exists.
- Prototype validation: replace the scoring path in a single layer, then compare candidate recall against differences in the final logits.
- System optimization: fuse the latent-space scoring kernel with block scheduling to reduce write-back of intermediate tensors.
- Accuracy regression: cover three workload types—long-document retrieval, multi-turn conversation, and repository-level code completion.
- Capacity planning: combine elastic scaling from your container platform, log services, and monitoring alerts to build a dashboard of percentile metrics for token length versus latency.
For cloud deployment, general-purpose building blocks can carry the load: object storage for long-text corpora, a message queue to smooth traffic spikes, a container platform for elastic inference replicas, and monitoring alerts with percentile thresholds on time-to-first-token and throughput.
6. Conclusion
The real barrier at ten-million-token context is not whether you can compute it, but whether you can select accurately and fast. Moving the relevance judgment into a lower-dimensional latent space is currently a viable path for pulling indexing cost back from quadratic to near-linear. For developers, measuring the indexer’s share first and then deciding optimization priorities is often more effective than switching models outright.
