Skip to main content
Back

Tsinghua Cuts IndexCache Indexer Cost by 75% on GLM-5 Long Contexts

A new sparse attention trick prunes 75 percent of DeepSeek-style indexer work, delivering up to 1.82x prefill and 1.48x decode speedups at 200K context.

Pro

Paper, Full Access
  • IndexCache removes up to 75 percent of lightning indexer computations in DeepSeek-style sparse attention models.
  • Delivers 1.82x prefill and 1.48x decode speedup on a 30B DSA model at 200K context.
  • Key insight: adjacent layers pick 70 to 100 percent of the same top-k tokens, making most indexer work redundant.
  • Layers split into Full (run own indexer) and Shared (reuse nearest Full layer's cache) with one conditional branch.
  • Training-free variant uses greedy LM-loss search; training-aware uses multi-layer KL distillation to a centroid.
  • Confirmed on 744B GLM-5 with 1.3x speedup and no quality loss on long-context benchmarks.

Sparse attention has quietly become the default recipe for long-context inference in frontier models like DeepSeek-V3.2 and GLM-5. But the mechanism that decides which tokens to attend to still has a hidden cost that grows quadratically with context length. A team from Tsinghua and Z.ai has now shown that most of that work is redundant, and a simple caching trick can strip out three quarters of it without hurting quality.

The method, called IndexCache, targets the lightning indexer inside DeepSeek Sparse Attention (DSA). On a 30B DSA model, it removes 75 percent of indexer computations with negligible quality degradation, achieving up to 1.82x prefill speedup and 1.48x decode speedup compared to standard DSA, and the same trick carries over to the 744B GLM-5.

Why the indexer became the bottleneck

To understand what IndexCache is fixing, you need to know how DSA actually works. DSA's lightning indexer along with sparse attention presents challenges in continuous batching and paged attention, but the core idea is simple: instead of every query attending to every past token, a cheap scorer picks the most relevant ones first. The mechanism works in two stages. In the first stage, a lightweight lightning indexer runs compressed query and key projections to produce a relevance score for every token block in the context. The projections are low-rank, so this step is fast: roughly 1-5 percent of the compute of a full attention pass. The output is a sorted list of block scores, one per position group. In the second stage, the model loads only the top-K blocks from GPU HBM and runs standard attention over the sparse selection.

The catch is that while the main attention drops from O(L squared) to O(Lk), the indexer itself is still O(L squared) and runs at every layer. Across N layers that is O(NL squared) work that scales quadratically with context. Profiling a 30B DSA model shows the indexer's share of latency rises sharply with context length, especially during prefill, dominating the attention budget at very long sequences.

The key observation: layers see the same tokens

The authors' starting point is an empirical curiosity. When they measured the pairwise top-k index overlap across all 47 layers of a DSA model, they found that adjacent layers share 70 to 100 percent of their selected tokens, and the overlap heatmap reveals distinct clusters of layers with mutually high agreement. In other words, most indexer computations across the stack are picking essentially the same tokens as their neighbors.

Prior work on cross-layer sharing exploited similar redundancy in full-attention models by designating a few anchor layers to compute full attention while intermediate layers reused their top-k. That trick does not carry over to DSA, because DSA has no full attention anywhere to serve as an oracle. IndexCache asks a different question: can the indexer itself be shared across layers?

How IndexCache works

The design is deliberately minimal. Layers are partitioned into two roles:

  • F (Full) layers run their own indexer, compute a fresh top-k, and cache it.
  • S (Shared) layers skip the indexer entirely and reuse the cached top-k from the nearest preceding F layer.

The only change to the inference loop is a single conditional branch. The cached indices are held in a temporary buffer that gets overwritten at each F layer, so there is no extra GPU memory beyond what standard DSA already allocates. The interesting question is which layers to make F and which to make S. The paper proposes two answers.

Training-free IndexCache works on any off-the-shelf DSA checkpoint. A naive alternating pattern like FSSSFSSS turns out to hurt quality noticeably, because indexer importance is not uniform across the stack. Instead, the authors run a greedy search: start with all layers as F, then repeatedly flip the layer whose conversion to S causes the smallest increase in language modeling loss on a small calibration batch. This bakes an implicit ordering of "expendable" versus "critical" layers directly into the pattern.

Training-aware IndexCache goes further by modifying training. Each retained indexer is distilled against the averaged attention distribution of every layer it will serve, using a multi-layer KL loss. The authors show that this multi-layer objective is mathematically equivalent, gradient for gradient, to distilling against the centroid of the target layers' attention distributions. The retained indexers therefore learn a consensus top-k that generalizes across the block they cover, and the sharing layers learn to work with inherited indices.

What the numbers look like

On the 30B DSA model (a variant of GLM-4.7-Flash) served with SGLang on an H100 node, the training-free version already recovers full quality at 1/4 retention:

ContextDSA prefillIndexCache 1/4 prefillDSA decode (tok/s)IndexCache 1/4 decode (tok/s)
10K0.57s0.45s73.591.0
60K3.38s2.59s67.089.5
120K8.57s5.66s63.088.0
200K19.5s10.7s58.086.0

Across nine long-context and reasoning benchmarks including MRCR v2, GraphWalks, LongBench v2, RULER, AIME 2025, GPQA-Diamond, and LiveCodeBench, the searched 1/4 pattern lands within 0.3 points of the original DSA on the long-context average and actually beats it slightly on AIME (92.6 vs 91.0) and GPQA (78.6 vs 77.6), suggesting the pruning acts as a mild inference-time regularizer for reasoning tasks.

The training-aware version removes an interesting quirk of the training-free approach: pattern sensitivity vanishes. Once the model is retrained with the multi-layer distillation loss, even a plain uniform pattern matches the full-indexer baseline, because S layers learn to adapt to inherited indices and F-layer indexers learn to generalize across their served block. Ablating the cross-layer loss drops the long-context average from 51.6 to 49.8, confirming the distillation objective does real work.

Where it holds up and where it does not

IndexCache scales. Preliminary results on the 744B GLM-5 (40B active) show the searched 1/2 pattern actually exceeds the baseline (78.7 vs 78.4 long-context average) and the 1/4 pattern stays within 0.4 points, translating into at least 1.3x speedup in both prefill latency and decode throughput at contexts beyond 100K.

The method has clear limits. Push retention below 1/4 (say, 1/8) and even the searched pattern shows non-negligible degradation, with the long-context average dropping to 46.1. And a seemingly natural alternative that the authors tried and reported as a negative result, using cosine similarity between attention outputs to pick the pattern via dynamic programming, performs no better than uniform interleaving. The reason is instructive: similarity is a local metric that misses how small mismatches propagate across layers, while LM loss captures the global effect directly.

Why this matters

The broader takeaway is that the cross-layer sharing principle that used to require a full-attention oracle now works on models that never compute full attention at all. As DeepSeek-V3.2 and GLM-5 push sparse attention into production, per-layer indexer cost is the next thing to squeeze, and IndexCache does it with a one-line change to the inference loop. Anyone deploying long-context DSA-style models, particularly at 100K+ contexts where the indexer dominates latency, has a straightforward path to a meaningful speedup without touching the core attention kernel.

The paper does not release code or checkpoints, so applying training-free IndexCache today means implementing the greedy search and the F/S branch yourself, both of which are conceptually simple. Training-aware adoption will require rerunning the DSA continued pre-training pipeline with the multi-layer distillation loss, which the authors indicate they plan to apply to GLM-5 in future work.