GLM-5 / GLM-5.1 / GLM-5.2 / GLM-5.3 (MoE + DSA)

View as Markdown

GLM-5, GLM-5.1, GLM-5.2, and GLM-5.3 are Z.ai’s open-weight Mixture-of-Experts language models with Multi-head Latent Attention (MLA) and Dynamic Sparse Attention (DSA). GLM-5.3 uses the same base model and GlmMoeDsaForCausalLM architecture as GLM-5.2, with its gains coming from post-training.

TaskText Generation
ArchitectureGlmMoeDsaForCausalLM
GLM-5.3 decoder78 layers, 6,144 hidden size, 256 routed experts
GLM-5.3 context length1,048,576 tokens in the model configuration; validated here at 4,096 tokens
HF Orgzai-org

Key Features

GLM-5 family models in NeMo AutoModel support:

  • Mixture-of-Experts (MoE) with 256 routed experts, top-8 routing, and one shared expert in the GLM-5.2/5.3 configuration. The first three layers use dense feed-forward networks.
  • IndexShare DSA for GLM-5.2 and GLM-5.3. Shared DSA layers reuse the previous full layer’s top-k sparse-attention selection.
  • Optional cuDNN DSA and FlashMLA sparse attention on SM90 or later through backend.attn: cudnn.
  • Optional TileLang kernels for the DSA indexer and sparse MLA path through backend.attn: tilelang.
  • Packed-sequence training and distributed execution with FSDP2, expert parallelism, HybridEP dispatch, and optional context parallelism.

Available Models

  • GLM-5 (GlmMoeDsaForCausalLM)
  • GLM-5.1 (GlmMoeDsaForCausalLM): Updated weights
  • GLM-5.2 (GlmMoeDsaForCausalLM): IndexShare DSA with cuDNN and TileLang backends
  • GLM-5.3 (GlmMoeDsaForCausalLM): Same base architecture as GLM-5.2; updated post-training

Example HF Models

Example Recipes

RecipeDescription
glm_5.3_tulu3_4k_cudnn_100step.yamlFull-parameter GLM-5.3 SFT on Tulu3 with packed 4K sequences, cuDNN DSA, HybridEP, and EP64
glm_5.2_tulu3_32k_tilelang_cp8.yamlGLM-5.2 SFT on Tulu3 with packed 32K sequences, CP8, TileLang DSA, and EP64
glm_5.2_tulu3_4k_tilelang_100k.yamlGLM-5.2 SFT on Tulu3 with packed 4K sequences and TileLang DSA
glm_5.2_tulu3_4k_cudnn_100k.yamlGLM-5.2 SFT on Tulu3 with packed 4K sequences and cuDNN DSA + FlashMLA

Validated GLM-5.3 Configuration

AreaValidated configuration
TrainingFull-parameter SFT with FSDP2 and activation checkpointing
Distributed setupEP64 / CP1 with HybridEP dispatch and expert reshard_after_forward: true
AttentioncuDNN DSA with FlashMLA sparse forward
Workloadallenai/tulu-3-sft-mixture, packed 4,096-token sequences
BatchLocal batch size 4; global batch size 256
Scale32 nodes / 256 GPUs
Duration100 optimizer steps

The relevant model and expert-distribution settings are:

distributed:
strategy: fsdp2
ep_size: 64
activation_checkpointing: true
moe:
reshard_after_forward: true
wrap_outer_model: false
ignore_router_for_ac: true
model:
pretrained_model_name_or_path: zai-org/GLM-5.3
backend:
attn: cudnn
dispatcher: hybridep
gate_precision: float32

Install and Run

Clone and install NeMo AutoModel from source:

git clone https://github.com/NVIDIA-NeMo/Automodel.git
cd Automodel
uv sync --locked --all-groups --all-extras

The cuDNN backend also requires FlashMLA’s flash_mla_sparse_fwd, which is not published as a complete source distribution on PyPI. Install the tested revision with its submodules:

git clone --recursive https://github.com/deepseek-ai/FlashMLA.git /tmp/FlashMLA
git -C /tmp/FlashMLA checkout b7643bd54521f563b839b98289b5cd048c062ba2
git -C /tmp/FlashMLA submodule update --init --recursive
uv pip install --no-build-isolation /tmp/FlashMLA

The published GLM-5.3 recipe requires 32 nodes with 8 GPUs per node. Launch it through the cluster launcher from inside the repository:

uv run automodel examples/llm_finetune/glm/glm_5.3_tulu3_4k_cudnn_100step.yaml \\
--nproc-per-node=8 \\
--wandb.enable=true

Use the Slurm Launcher Guide to configure the multi-node launch. The published recipe is a distributed full-model workflow.

Numerical Validation

Hugging Face Logit Parity

The first four GLM-5.3 layers were compared with the Hugging Face reference. Representative loaded weights matched their source tensors exactly.

MetricResult
Logits relative L2 error0.639%
Top-1 token agreement96.61%

100-Step Training

The full 32-node / 256-GPU configuration completed all 100 optimizer steps. Throughput statistics exclude the first 10 warmup steps.

MetricResult
Step 0 loss1.33347
Step 99 loss0.53756
Mean loss, steps 10-990.55548
Mean throughput, steps 10-9941,664 tokens/s

The run completed without non-finite metrics or critical rank errors.

Current Scope

  • The published GLM-5.3 path covers full-parameter SFT with cuDNN DSA, FlashMLA, HybridEP, and EP64 at 4K sequence length.
  • GLM-5.3 context-parallel and TileLang configurations were not validated by this recipe. Use the GLM-5.2 recipes above for the established CP8 and TileLang paths.
  • The cuDNN sparse-attention path requires SM90 or later, cuDNN Frontend, and FlashMLA.

See the LLM Fine-Tuning Guide and the Large MoE Fine-Tuning Guide for dataset and training configuration details.

References