add glm5.2 indexshare - #4832
Open
notabee wants to merge 53 commits into
Open
Conversation
…store pristine deepseek.py
…branches, and FLOP calculation
… layers to donor layer indexers for GLM-5.2
…available checkpoint keys
…ayer_index_reuse for XProf/XPlane profiling
…or abstract scanned layers
…full 78-layer forward and backward passes
notabee
requested review from
RissyRan,
darisoy,
gagika,
gobbleturk,
igorts-git,
jiangjy1982,
michelle-yooh,
parambole,
richjames0,
shralex and
shuningjin
as code owners
August 11, 2026 12:54
notabee
requested review from
Lumosis,
gpolovets1,
jrplatin,
mailvijayasingh,
mitalisi and
patemotter
as code owners
August 18, 2026 08:35
notabee
force-pushed
the
feat/glm5.2-indexshare
branch
from
August 18, 2026 08:37
a01f09f to
340a7a2
Compare
…tion tokenization
notabee
force-pushed
the
feat/glm5.2-indexshare
branch
2 times, most recently
from
August 21, 2026 18:57
7fd619d to
322c827
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds full end-to-end support for GLM-5.2 (744B Mixture of Experts) featuring Cross-Layer IndexShare for Dynamic Sparse Attention (DSA) across training, checkpoint conversion, and inference.
Background & Context
GLM-5.2 is a 744B MoE architecture with 78 layers ($3 \text{ dense} + 75 \text{ MoE}$ ), 256 routed experts + 1 shared expert (Top-8 routed tokens per token), and Multi-Head Latent Attention (MLA) augmented with a Dynamic Sparse Attention (DSA) Lightning Indexer.
In standard DSA implementations, every transformer layer independently computes indexer query/key projections (
wq_b,wk_b) and Top-k indexer scores. However, attention distributions exhibit strong cross-layer similarity across adjacent decoder stages. GLM-5.2 introduces Cross-Layer IndexShare, utilizing anFSSSperiodic pattern (1 Full layer followed by 3 Shared layers) where:Key Changes
src/maxtext/configs/models/glm5.2-744b.ymlwith native support foruse_index_share=true,index_share_pattern="FSSS", andprune_shared_indexers=true.src/maxtext/models/glm5.py(GLMDenseLayer,GLMMoELayer,GLMGenericLayer) to threadlayer_idxandcached_indexer_state._apply_layers_sequentiallyinsrc/maxtext/layers/nnx_decoders.pyto thread(carry_y, cached_indexer_state, layer_idx)throughjax.lax.scanwith invariant concrete tensor structures for HBM stability.src/maxtext/layers/attention_mla.pywithjax.lax.conddispatching to conditionally run full indexer calculations onzai-org/GLM-5.2safetensors to MaxText format into_maxtext.py, automatically pruning 74.4% of indexer weights on shared layers.tests/end_to_end/tpu/glm5/glm5.2-744b/1_test_glm5.sh(Checkpoint Conversion).tests/end_to_end/tpu/glm5/glm5.2-744b/2_test_glm5.sh(Pre-Training & Generation).Benefits
Tests
1. Checkpoint Conversion (Step 1)
2. Distributed Pre-Training & Verification on TPU v7x (32 Chips / 64 Devices)
python3 -m maxtext.trainers.pre_train.train src/maxtext/configs/base.yml \ base_output_directory="gs://maxtext-glm5-europe-west4/GLM-5.2/training_logs" \ run_name=glm52_pretrain_verify \ model_name=glm5.2-744b \ scan_layers=true \ use_indexer=true \ use_index_share=true \ index_share_pattern="FSSS" \ prune_shared_indexers=true \ indexer_sparse_training=true \ tokenizer_type=huggingface \ tokenizer_path=zai-org/GLM-5.2 \ dataset_type=synthetic \ per_device_batch_size=1 \ max_target_length=4096 \ ici_expert_parallelism=4 \ ici_fsdp_parallelism=16 \ steps=103. Autoregressive Generation & Decoding
python3 -m maxtext.inference.decode src/maxtext/configs/base.yml \ model_name=glm5.2-744b \ tokenizer_type=huggingface \ tokenizer_path=zai-org/GLM-5.2 \ load_parameters_path="gs://maxtext-glm5-europe-west4/maxtext-glm-5.2-bf16-converted-final-78l/0/items" \ scan_layers=true \ use_indexer=true \ use_index_share=true \ index_share_pattern="FSSS" \ prune_shared_indexers=true \ prompt="The capital of France is"Checklist
gemini-reviewlabel.