GLM‑5.2 IndexShare
A source-grounded explanation of the shared indexer mechanism used with DSA sparse attention in GLM‑5.2. The core idea: do not recompute the DSA top‑k token indexer in every layer; reuse selected token indices across a small group of layers.
Verified facts
1. What DSA does before sharing
DeepSeek Sparse Attention uses a lightweight indexer to score previous tokens for each query and select the top‑k relevant positions. The main attention then runs only on those selected positions instead of attending to the full prefix.
2. What IndexShare changes
GLM‑5.2 applies IndexShare so that every 4 transformer layers share one lightweight indexer. The first layer in the group computes top‑k indices; the following layers reuse those indices, reducing indexer dot‑product and top‑k work in 3/4 layers.
Layer execution pattern: standard DSA vs IndexShare
Standard DSA
Every layer runs its own indexer.
IndexShare / IndexCache idea
Full layers compute top‑k; shared layers reuse the nearest preceding full layer’s top‑k indices.
indexer_types from config, not hard-code a simplistic pattern.Public config evidence
What is actually shared?
| Item | Shared? | Meaning |
|---|---|---|
| Top‑k token indices | Yes | Shared layers reuse the selected token positions from a preceding full indexer layer. |
| Main sparse attention computation | No | Each layer still computes its own attention output using its own hidden states and parameters. |
| Indexer weights | Effectively fewer active indexer calls | Full layers run the indexer; shared layers skip the indexer forward pass. |
| KV cache | Not reduced by backbone IndexShare | The blog explicitly notes GLM‑5.2’s architecture reduces FLOPs but does not proportionally reduce per-token KV-cache size. |
Why this helps long context
Problem
The DSA indexer still scans/scales with the prefix to choose relevant tokens. At very long context, this selection overhead becomes important.
Observation
IndexCache reports high cross-layer overlap in selected top‑k tokens: consecutive layers often choose similar important token sets.
Optimization
Run the indexer only at selected full layers, cache the top‑k indices, and reuse them in shared layers.
MTP path: IndexShare + KVShare
GLM‑5.2 also applies IndexShare to the MTP layer used for speculative decoding. For multi-step MTP, the indexer is placed at the first step and top‑k indices are reused by following steps. The blog additionally says KVShare is used in the MTP path to reduce training/inference mismatch, with an ablation showing acceptance length improving from 4.56 to 5.47 after adding IndexShare+KVShare, rejection sampling, and end-to-end TV loss.
Implementation checklist
| Check | Why it matters |
|---|---|
Parse model_type=glm_moe_dsa | GLM‑5.2 is not a standard dense attention model. |
Respect indexer_types | Do not run indexer on every layer if the config marks the layer as shared. |
| Cache top‑k indices from full layers | Shared layers need the previous full layer’s selected positions. |
Use index_topk=2048 | This is the released model config value. |
| Do not claim KV-cache reduction | Backbone IndexShare mainly reduces indexer compute, not KV size. |
Sources and what each source supports
| Source | Used for |
|---|---|
| Z.AI / Hugging Face GLM‑5.2 blog | IndexShare definition, 4-layer sharing, 2.9× per-token FLOPs claim, MTP IndexShare/KVShare details. |
| GLM‑5.2 config.json | Actual released config: glm_moe_dsa, index_topk=2048, index_topk_freq=4, indexer_types, 1M context. |
| IndexCache paper | General mechanism: Full layers compute fresh indices; Shared layers reuse nearest preceding Full layer’s top‑k indices; motivation from cross-layer redundancy. |
| GLM‑5 technical report page | GLM‑5 context for DSA architecture and long-context engineering. |
Last checked: 2026‑06‑26. Claims not directly supported above are intentionally avoided.