TAAFT
Free mode
100% free
Freemium
Free Trial
Prompts Deals

IndexCache

THUDM / IndexCache

IndexCache: Accelerating Sparse Attention via Cross-Layer Index Reuse

54 5 Language: null Updated: 3mo ago

README

# IndexCache ### Accelerating Sparse Attention via Cross-Layer Index Reuse [![arXiv](https://img.shields.io/badge/arXiv-2603.12201-b31b1b.svg)](https://arxiv.org/abs/2603.12201) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![SGLang](https://img.shields.io/badge/SGLang-patch-green.svg)](https://github.com/sgl-project/sglang) [![vLLM](https://img.shields.io/badge/vLLM-patch-green.svg)](https://github.com/vllm-project/vllm) *Tsinghua University & Z.ai*

This repository provides a patch for SGLang and vLLM that enables IndexCache inference acceleration for models using DeepSeek Sparse Attention (DSA), including DeepSeek-V3.2 and GLM-5.

TL;DR: IndexCache eliminates up to 75% of indexer computations in DSA through cross-layer index reuse โ€” achieving up to 1.82ร— prefill speedup and 1.48ร— decode speedup with negligible quality degradation. One if/else branch, zero extra GPU memory.

๐Ÿ” Motivation

In DSA, the lightning indexer selects the top-k most relevant tokens at each layer to make attention sparse. While cheap per-FLOP, it runs independently at every layer with O(Lยฒ) complexity. At long context lengths, it becomes the dominant bottleneck:

At 200K context, the indexer consumes 81% of prefill time.

๐Ÿ’ก Key Insight

We measured pairwise top-k index overlap across all 47 DSA layers and found that adjacent layers share 70โ€“100% of their selected tokens:

Cross-layer top-k overlap heatmap. Most indexer computations are redundant.

โš™๏ธ Method

IndexCache partitions layers into Full (F) layers that retain their indexer and Shared (S) layers that reuse the nearest F layer's cached indices:

We propose two complementary approaches:

Approach Description Requires Training?
Training-free Greedy search selects which indexers to remove based on LM loss on a calibration set โœ—
Training-aware Multi-layer distillation trains each retained indexer to serve all layers it covers โœ“

Both retain only 1/4 of indexers with negligible quality degradation.

๐Ÿ“Š Results

30B DSA Model โ€” Speedup (H100)

Baseline IndexCache (1/4) Speedup
Prefill (200K) 19.5s 10.7s 1.82ร—
Decode (200K) 58 tok/s 86 tok/s 1.48ร—

9 benchmarks virtually unchanged โœ…

GLM-5 (744B) โ€” Production Validation

~1.2ร— E2E speedup with negligible degradation across 10 benchmarks (long-context + reasoning).


๐Ÿš€ Quick Start

Step 1: Clone SGLang / vLLM

git clone https://github.com/sgl-project/sglang.git
cd sglang
git checkout b638b25b

This patch is built and tested against commit b638b25b. It may apply cleanly to newer versions, but if you encounter conflicts, use this specific commit.

For vLLM:

git clone https://github.com/vllm-project/vllm.git
cd vllm
git checkout 4508532fb

Step 2: Apply the patch

git apply /path/to/indexcache.patch # /path/to/indexcache_vllm.patch for vllm patch

Step 3: Launch with IndexCache

Configure via --json-model-override-args for SGLang or --hf-overrides for vLLM. Two options (take SGLang for example):

Option A โ€” Uniform interleaving

Every N-th layer keeps its indexer:

python -m sglang.launch_server \
    --model-path zai-org/GLM-5-FP8 \
    --json-model-override-args '{"index_topk_freq": 2}' \
    ...  # your other args (tp, dp, etc.)

index_topk_freq=2 โ†’ every 2th layer is Full, rest are Shared (50% indexers removed).

Specify per-layer F/S assignment:

python -m sglang.launch_server \
    --model-path zai-org/GLM-5-FP8 \
    --json-model-override-args '{"index_topk_pattern": "FFSFSSSFSSFFFSSSFFFSFSSSSSSFFSFFSFFSSFFFFFFSFFFFFSFFSSSSSSFSFFFSFSSSFSFFSFFSSS"}' \
    ...  # your other args

Each character maps to one DSA layer: F = Full (runs indexer), S = Shared (reuses cached indices).

Default behavior: When neither parameter is set, all layers run their indexer โ€” identical to standard DSA.

Configuration Reference

Parameter Type Default Description
index_topk_freq int 1 Keep indexer every N layers. 1 = disabled, 4 = keep 1/4
index_topk_pattern string null Per-layer F/S pattern. Overrides index_topk_freq if set

Which to use?

  • index_topk_freq: 4 โ€” Simple, good default. Best with training-aware models.
  • Custom pattern โ€” Optimal for training-free deployment. The example above is the greedy-searched pattern for the GLM-5 model.

โœ… Supported Models

Model Architecture Supported
DeepSeek-V3.2 DeepseekV32ForCausalLM โœ…
GLM-5 (744B) GlmMoeDsaForCausalLM โœ…

Any model using DSA indexer benefits from this patch.


๐Ÿ“ Citation

@article{bai2025indexcache,
  title={IndexCache: Accelerating Sparse Attention via Cross-Layer Index Reuse},
  author={Bai, Yushi and Dong, Qian and Jiang, Ting and Lv, Xin and Du, Zhengxiao and Zeng, Aohan and Tang, Jie and Li, Juanzi},
  journal={arXiv preprint arXiv:2603.12201},
  year={2025}
}

License

This patch is released under the Apache 2.0 License, consistent with SGLang.

0 AIs selected
Clear selection
#
Name
Task