Manuscript Offprint

arXiv:2611.03768

Multi-layer Indexer: Overlapping Selection and Attention in DeepSeek Sparse Attention

Serdarcan Dilbaz, Arjun Krishna, Kiran Kamble, Daniel M. Bikel

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Sparse attention cuts the cost of long-context inference by making the attention matrix sparse: each query attends only a subset of the sequence, chosen by a fixed pattern or, in recent production LLMs, learned per query. In DeepSeek Sparse Attention (DSA), the attention of DeepSeek-V3.2 and the GLM-5 family, every layer is preceded by a lightning indexer that scores the whole cache and keeps the k=2048k=2048 highest-scoring tokens for the layer to attend. At long context this indexer scan, not the sparse attention it feeds, is where the decode time goes, and attention waits for it at every layer. But adjacent layers select nearly the same tokens, so a layer can attend the selection of the previous indexer layer instead of its own. This removes the dependency: each indexer then runs concurrently with the attention of its layer. The resulting Multi-layer Indexer (MLI) needs no retraining and no new weights. Its default realization changes no kernel, running inside SGLang's production decode graph; an optional fused decode kernel accelerates it further on DeepSeek-V3.2. MLI composes with IndexCache (the cross-layer reuse GLM-5.2 ships as IndexShare): IndexCache drops the indexer from some layers, and MLI hides the scan on the rest. We serve DeepSeek-V3.2 and GLM-5 under IndexCache's protocol at retentions 1/21/2 to 1/321/32 (the fraction of layers that keep an indexer) and contexts 10K to 195K. At equal retention the composition decodes faster than IndexCache: up to 14.5% faster on DeepSeek-V3.2 and 9.8% on GLM-5 at 1/21/2, and 7.9% and 5.1% at 1/41/4, largest where IndexCache keeps the most indexers and growing with context. At retention 1/r1/r it is faster still than IndexCache at 1/2r1/2r while keeping twice the fresh selections: at 128K it reaches 1.32×1.32\times the unmodified model's decode throughput at 1/41/4, above IndexCache's 1.28×1.28\times at 1/s1/s. Its LongBench, RULER and LongBench v2 accuracy stays within a few percentage points of IndexCache's. Code is available at https://github.com/ArjunKrishnak/dsa-multi-layer-indexer.

1 Introduction

Sparse attention cuts the cost of long-context decoding by making the attention matrix sparse: each query attends only a subset of the sequence, chosen by a fixed pattern or learned per query. Recent production LLMs take the learned route, with a lightweight selector that must run before attention; at long context it, not the sparse attention it feeds, is where the decode time goes. DeepSeek Sparse Attention (DSA) [Liu et al., 2025] is the attention mechanism of DeepSeek-V3.2 and of GLM-5, GLM-5.1 and GLM-5.2 [Zeng et al., 2026, Z.ai, 2026a,b]. Consider decoding token tt with LL tokens in the cache. At each layer a lightning indexer with HIH_I small heads scores every cached token n≤Ln \leq L,

It,n=∑h=1HIwt,hReLU⁡(qt,hI⋅kn,hI),(1)I_{t,n}=\sum_{h=1}^{H_I}w_{t,h}\operatorname{ReLU}(\mathbf{q}_{t,h}^I\cdot\mathbf{k}_{n,h}^I), \tag{1}

where It,nI_{t,n} is the indexer's score for query tt and cached token nn, the superscript II marks the indexer's own projections (distinct from the layer's attention), hh indexes its HIH_I heads, and qt,hI,kn,hI\mathbf{q}_{t,h}^I, \mathbf{k}_{n,h}^I are 40th Conference on Neural Information Processing Systems (NeurIPS 2026). Workshop: Long-Context Foundation Models.

low-rank projections of the layer input with wt,hw_{t,h} a per-head weight. The layer keeps the set StS_t of the k=2048k=2048 tokens with the highest score and runs attention over those tokens only. The selection is the sole coupling between the indexer and attention: attention cannot begin until the top-kk is known, and nothing else in the layer depends on it.

The two nevertheless run in sequence. Sparse attention gathers kk keys and its cost is flat in LL; the indexer scans all LL keys. Beyond a few tens of thousands of tokens the scan is the largest term on the attention side of the layer, two thirds of it at 128K (Figure 1). Only the selection dependency forces the order, and adjacent DSA layers select strongly overlapping sets (Section 2), a cross-layer redundancy that reuse methods already exploit [Bai et al., 2026, Yang et al., 2025, Deshmukh et al., 2025], so a layer's attention need not wait for its own selection: an earlier layer's serves.

The cost of the indexer per decode step is a product of two independent factors: how many indexers run, and how long each one is waited for. IndexCache [Bai et al., 2026] reduces the first, keeping the indexer on a fraction 1/r1/r of the layers (Section 2). We reduce the second. The Multi-layer Indexer (MLI) lets layer ℓ\ell attend the selection produced by the previous indexer layer. The indexer of layer ℓ\ell then feeds a later layer, not its own attention, and the two run at the same time (in the idealized limit of Figure 1; the realized speedup is smaller, for reasons we trace in Section 5.2). Every selection is still recomputed at every decode step; nothing is reused across steps. Because the two factors multiply and neither method touches the other's, the two remedies compose: on the layers IndexCache keeps, MLI hides the scan that IndexCache still pays. Like IceFormer's deployable acceleration [Mao et al., 2024], MLI needs no retraining, applies to every DSA model, and leaves the selections unchanged. This is the regime long context forces: KV memory caps how many requests decode together (six at 128K, two at 195K on our node), so very long context is served few-at-a-time, exactly where the indexer scan is exposed; the gain fades only when many short requests pack the batch and saturate memory bandwidth (Section 5.2).

Our contributions are the following.

  • A drop-in schedule that overlaps the indexer with attention. MLI (Section 3) makes a layer's indexer and its attention independent, at any retention and lag depth, so they run concurrently; it needs no retraining and no new weights, runs in SGLang's decode CUDA graph with the production kernels unchanged, and is faster still on DeepSeek-V3.2 with a fused decode kernel (Section 5.3).

  • Faster at equal retention, and one further halving for free. Serving DeepSeek-V3.2 and GLM-5 under IndexCache's protocol (Section 5.1), IndexCache+MLI decodes faster than IndexCache at the same retention: up to 14.5% faster on DeepSeek-V3.2 and 9.8% on GLM-5 at 1/21/2, and 7.9% and 5.1% at 1/41/4; and at retention 1/r1/r it is faster than IndexCache at 1/2r1/2r while attending twice as many fresh selections, so a halving of the indexer budget comes at no speed cost. At 128K it reaches 1.32×1.32\times the unmodified model's throughput at 1/41/4, above IndexCache's 1.28×1.28\times at 1/81/8.

  • A shared-primitive fused kernel, and the case for co-design. On DeepSeek-V3.2 a fused decode kernel runs the sparse attention and the indexer's prefix scan of a shared step in one launch, a per-request win (Section 5.3); it does not help GLM-5, which has fewer index heads per rank. Because the indexer scores the same group bilinear interaction as attention, this is evidence that DSA models should be co-designed around that shared primitive: a direction we argue for and partly realize, not a model we train.

  • The quality cost of staleness is small and recoverable. Across five long-context suites (Section 5.4), attending an older selection stays within a few points of IndexCache at every retention it reports; the arm with twice the fresh selections, now the faster of the two, matches IndexCache on LongBench and LongBench v2 and is within 3 points on RULER (Section 5.6), and distilling only the indexers, applied identically to both methods, recovers little at the mild retentions IndexCache reports but rescues the collapse at aggressive retention (Section 5.5).

References (40)