Summary (Overview)
- Key Contribution: AttentionIndex is a novel system that accelerates learned sparse attention by routing queries over an inverted-file (IVF) index of indexer keys, followed by refinement with the native indexer score, rather than exhaustively scoring every key in the prefix.
- Performance Gains: At one million tokens, AttentionIndex delivers 1.3–1.8× the prefill throughput of exhaustive selection on GLM-5.3 and DeepSeek-V4-Flash, while recovering 17.0 and 10.0 percentage points more of the exhaustive top-k compared to HiSA at matched throughput.
- Accuracy Improvements: AttentionIndex improves long-context benchmark accuracy by up to 18.4 percentage points over HiSA at the same candidate budget.
- Three Novel Mechanisms: (1) similarity-based clustering rather than contiguous-block routing, (2) causal incremental index maintenance with immediate insertion and periodic refits, and (3) learned routing representatives trained offline to better predict native indexer scores.
- Problem Identification: The paper demonstrates that key selection (not attention computation) dominates long-context prefill, taking 53–58% of prefill time at 1M tokens in production models.
Introduction and Theoretical Foundation
Background
Long-context inference has become a defining workload for large language models, with agents, code assistants, and document analysis routinely processing hundreds of thousands to millions of tokens per request. At these lengths, dense attention is prohibitively expensive, leading production models to adopt learned sparse attention.
Learned Sparse Attention
DeepSeek Sparse Attention (DSA) adds a lightweight learned indexer to sparse attention layers. The indexer scores all keys in the prefix, and the main attention operates only on the highest-scoring entries. The native indexer score for query token and earlier token is:
where and weights of the indexer heads derive from token , and each token contributes a single indexer key shared by all heads.
The Key Selection Bottleneck
While sparse attention bounds the cost of attention computation, the indexer still scores every key. For a context of tokens, scoring and top-k selection each require work per query and work across prefill, whereas attention over selected entries requires only work per query. At 1M tokens, indexer scoring and top-k selection take 53% of prefill time on DeepSeek-V4-Flash and 58% on GLM-5.3.
Limitations of Contiguous-Block Routing
Two-stage selection methods like HiSA route queries to contiguous blocks of keys ranked by mean-pooled representatives. However, contiguous token entries need not be similar in indexer space. As context grows, recall declines sharply at fixed candidate budgets:
| Context | GLM-5.3 HiSA8K (LongBench-v2) | GLM-5.3 HiSA8K (RULER) | DeepSeek-V4-Flash HiSA4K (LongBench-v2) | DeepSeek-V4-Flash HiSA4K (RULER) |
|---|---|---|---|---|
| 16K | 83.9 | 81.7 | - | - |
| 32K | 73.4 | 68.3 | 87.4 | 82.0 |
| 64K | 59.3 | 55.9 | 80.3 | 64.7 |
| 128K | 46.6 | 48.2 | 59.3 | 50.6 |
| 256K | 41.8 | 41.4 | 46.0 | 41.8 |
Inverted-File (IVF) Indexing Principle
IVF indexes speed up approximate nearest-neighbor search by partitioning vectors into clusters (commonly via k-means) and restricting candidate evaluation to selected clusters. At query time, IVF ranks cluster representatives, selects a subset of clusters, and evaluates vectors within those clusters. However, three constraints complicate IVF application to learned indexers:
- Incremental updates: New tokens must be added cheaply during prefill/decode
- Causality: Every query must see an index built only from its own prefix
- Non-inner-product scores: The native indexer score is not a simple inner product, so cluster means are poor proxies for member scores
Methodology
Design Overview
AttentionIndex replaces exhaustive selection with routing over an IVF index of indexer keys, followed by refinement with the native indexer score. The design has three main components:
1. Routing over Similarity Clusters
For each request and indexed layer, AttentionIndex maintains an IVF index over indexer keys. Each cluster stores:
- An inverted list of member key IDs
- A routing representative
A query scores every representative with the native indexer score (Equation 1) and ranks clusters. It then fills a candidate budget of keys: sink keys and unclustered open-window keys take reserved slots, with the top-ranked clusters' lists filling the rest. Refinement scores candidates exactly and passes the top- to the unchanged sparse attention kernel.
Each query scores about entries instead of , where is the number of clusters (approximately 128 keys per cluster on GLM-5.3).
2. Causal Maintenance of a Growing Index
AttentionIndex separates immediate insertion from lazy reorganization:
- Open window: New keys enter an open window and are included directly in candidates of later queries (searchable before clustering)
- Sealing: Every keys (1,024 on GLM-5.3), the window is clustered into ~8 clusters of ~128 keys using size-capped k-means
- Refitting: Every tokens (16,384 on GLM-5.3), the entire prefix is regrouped into a new base with more clusters as the prefix grows
Causality is maintained by versioning: each seal or refit produces a new index version whose lists, representatives, and window metadata become visible together, and a query uses a version only if every key that built it lies in the query's prefix.
3. Incremental Refits
Refits reuse the previous base instead of clustering from scratch:
- Warm-start: Initialize from previous base's nonempty means plus new centers sampled from recent keys
- Bound-based acceleration: Keep for every key its assignment, an upper bound on distance to its center, and lower bounds to competing centers (Elkan, 2003; Drake & Hamerly, 2012)
- Only newly added keys and keys whose bounds no longer certify their assignment search all centers
- Distance work is proportional to instead of (where is new centers and is keys needing full search)
4. Learned Routing Representatives
Membership uses geometric distance (cheap to update), but routing needs to predict native indexer scores. A small encoder shared by all clusters of a layer predicts a correction to the cluster mean :
The encoder uses permutation-invariant summaries: mean, logarithm of cluster size, and mean/max-pooled learned features. Training minimizes cross-entropy between:
where counts reference keys in cluster , counts causally visible members, is the native indexer score of , and is a training scale. The encoder learns to rank clusters by reference keys per candidate slot.
Empirical Validation / Results
Experimental Setup
- Models: GLM-5.3 (2,048 token keys per query) and DeepSeek-V4-Flash (512 compressed entries, compression stride of 4)
- Datasets: LongBench-v2, RULER, and InfiniteBench
- Hardware: Eight NVIDIA B200 GPUs with 8-way tensor parallelism
- Baselines: Full DSA (exhaustive selection) and HiSA (contiguous-block routing)
Indexer Retrieval Quality
AttentionIndex achieves higher mean recall than HiSA on all three datasets at every evaluated budget. At a 24K budget on LongBench-v2:
- GLM-5.3: recall improves from 67.16% to 89.70%
- DeepSeek-V4-Flash: recall improves from 75.88% to 90.66%
AttentionIndex achieves higher recall with smaller budgets: its 24K results exceed HiSA's 64K results on GLM-5.3 (62.5% fewer candidate slots).
Throughput Analysis
At 1M tokens, AttentionIndex reaches:
- 1.6–1.8× the throughput of Full DSA on GLM-5.3
- 1.3–1.6× the throughput of Full DSA on DeepSeek-V4-Flash
At comparable throughput (within 5%), AttentionIndex gains:
| Method | Budget | Tput | Recall | Budget | Tput | Recall |
|---|---|---|---|---|---|---|
| 512K tokens | ||||||
| Full DSA | - | 0.698 | 100.0 | - | 0.833 | 100.0 |
| HiSA | 16K | 0.987 | 63.1 | 24K | 1.002 | 85.2 |
| AttentionIndex | 16K | 1.000 | 86.4 | 16K | 1.000 | 89.5 |
| 1M tokens | ||||||
| Full DSA | - | 0.548 | 100.0 | - | 0.608 | 100.0 |
| HiSA | 24K | 1.048 | 69.6 | 24K | 0.971 | 76.5 |
| AttentionIndex | 16K | 1.000 | 86.6 | 16K | 1.000 | 86.5 |
Decoding Latency Under Load
AttentionIndex achieves TPOT speedups of 1.40–1.45× over Full DSA, compared with 1.54–1.65× for HiSA24K.
End-to-End Accuracy
At a matched 24K budget, AttentionIndex improves accuracy over HiSA on all benchmarks:
| Dataset | Full DSA | HiSA 16K | HiSA 24K | AttentionIndex 16K | AttentionIndex 24K |
|---|---|---|---|---|---|
| GLM-5.3 | |||||
| InfiniteBench | 83.0 | 75.0 | 78.6 | 80.4 | 83.3 |
| RULER | 81.8 | 55.2 | 62.6 | 73.6 | 77.5 |
| LongBench-v2 | 63.8 | 60.4 | 61.0 | 60.4 | 61.7 |
| DeepSeek-V4-Flash | |||||
| InfiniteBench | 81.16 | 80.46 | 80.19 | 81.20 | 82.03 |
| RULER | 77.83 | 58.59 | 67.27 | 74.92 | 76.14 |
| LongBench-v2 | 63.82 | 60.82 | 63.02 | 61.63 | 63.42 |
Largest gains on RULER: 14.9 points on GLM and 8.87 points on DeepSeek-V4-Flash, recovering approximately 78% and 84% of HiSA's gap to Full DSA.
Ablation: Periodic Refitting
Every tested refit interval improves recall over sealing alone. At the serving interval of 16K:
- GLM recall rises from 0.788 to 0.883 at 24K budget (+9.49 points)
- DeepSeek-V4-Flash adds 8.29 points at 24K budget
Ablation: Learned Centroids
Learned representatives improve recall by 0.55–5.01 percentage points on GLM layers, with TTFT overhead of only +0.1% to +1.5%.
Theoretical and Practical Implications
Theoretical Significance
-
Key selection is the bottleneck: The paper provides empirical evidence that in production learned sparse attention, key selection rather than attention dominates long-context prefill, reframing the optimization target for sparse attention systems.
-
Similarity grouping > positional grouping: The results demonstrate that grouping keys by indexer-space similarity rather than positional contiguity substantially improves the recall-candidate-budget tradeoff, validating the IVF principle for learned indexers.
-
Causal index maintenance is feasible: The paper shows that incremental index construction can be integrated into the forward pass while preserving causality, with maintenance costs below the scoring work saved.
Practical Implications
-
Production deployment: AttentionIndex is implemented in SGLang and evaluated on production models (GLM-5.3, DeepSeek-V4-Flash), demonstrating practical viability.
-
Compatibility: The system leaves the sparse attention kernel unchanged, requiring only a swap of the candidate producer, making it easy to integrate into existing serving stacks.
-
Accuracy-recall relationship: The results show that improved indexer recall does not always produce proportional accuracy gains (e.g., LongBench-v2), suggesting model capability may be a limiting factor for certain reasoning-heavy tasks.
Conclusion
AttentionIndex accelerates learned sparse attention by maintaining a causal IVF index within each request and refining routed candidates with the native indexer score. Key findings:
- At a matched 24K candidate budget, AttentionIndex improves recall and task accuracy over HiSA on both GLM-5.3 and DeepSeek-V4-Flash
- Delivers 1.3–1.8× the prefill throughput of exhaustive selection at one million tokens
- Three key mechanisms: similarity-based clustering, causal incremental maintenance (sealing + refits), and learned routing representatives
Future work: Optimizing per-step decoding cost remains an open direction. The paper also notes that larger batch sizes would better amortize routing overhead and potentially close the throughput gap with HiSA during decoding.
Related papers
- What Limits Recursive Reasoning Models: Optimization, Architecture and Test-Time Scaling
Recursive reasoning performance is driven primarily by optimization choices—gradient horizon, physical batch size, and stabilized state updates—rather than architectural hierarchy, yielding a 13.6M-parameter model that doubles OOD accuracy on arithmetic.
- Not All Loops Cost the Same: Phase-Dependent Depth for Serving Looped Transformers
LoopDuet shows that asymmetric loop depths for prefilling versus decoding—with prefilling shallower—boost throughput by up to 19% and quality by 6.04 EM points without retraining.
- Library of Layers (LoL): Adaptively Ordering Transformer Layers at Runtime
Library of Layers lets a router dynamically reorder transformer layers per input, matching dense, looped, and sparse MoE baselines while enabling interpretable, controllable routing paths.