Skip to content

Commit 25d960f

Browse files
lucasliebmarimuthu-nv
authored andcommitted
[None][feat] Add AD custom model for GLM-4 MoE family (#231)
* [None][feat] Add AD custom model for GLM-4 MoE family (glm4_moe) Add AutoDeploy custom model implementation for the GLM-4 MoE architecture (model_type: glm4_moe), covering zai-org/GLM-4.6 and zai-org/GLM-4.7. Key architectural features: - GQA attention (96 Q heads, 8 KV heads, head_dim=128) - Partial rotary embeddings (partial_rotary_factor=0.5) - Per-head QK normalization (RMSNorm) - MoE with sigmoid gating, group top-k routing (160 experts, top-8) - First 3 layers dense, rest MoE with shared experts Uses AD canonical ops: torch_attention, torch_rope_with_explicit_cos_sin, torch_moe, torch_rmsnorm. Includes hierarchical unit tests (19 tests): block, layer, full model equivalence against HF reference, plus torch.export test. Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> * [None][feat] Add glm4_moe registry config with reduced layers and expert export limit Add glm4_moe.yaml config for GLM-4 MoE family models (GLM-4.6, GLM-4.7): - num_hidden_layers: 5 (reduce from 92 for CI/testing) - num_moe_experts_for_export: 2 (reduce from 160 for export) Update registry entries for both GLM-4.6 and GLM-4.7 to use the new config. Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> * [None][fix] Fix device mismatch in GLM4 MoE gate buffer for export Fix e_score_correction_bias buffer to not hardcode dtype, and cast to match scores tensor device/dtype in forward. This prevents a device mismatch (cpu vs meta) during the MoE expert reduction pre-trace in export_to_gm. Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> * [None][feat] Use noaux_tc_op for GLM4 MoE gate and split registry configs Address reviewer feedback: - Use torch.ops.trtllm.noaux_tc_op for fused sigmoid + bias + group top-k routing instead of vanilla PyTorch - Move num_hidden_layers out of glm4_moe.yaml, use num_hidden_layers_5.yaml separately in models.yaml entries - Ensure e_score_correction_bias is passed as float32 to noaux_tc_op Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> --------- Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
1 parent 74f4f97 commit 25d960f

5 files changed

Lines changed: 1073 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration for GLM-4 MoE family (GLM-4.6, GLM-4.7)
2+
# 160 experts - reduce for export
3+
transforms:
4+
export_to_gm:
5+
num_moe_experts_for_export: 2

examples/auto_deploy/model_registry/models.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ models:
238238
yaml_extra: ['kimi_k2.yaml']
239239
# --- GLM-4.7 (Dec 2025) ---
240240
- name: zai-org/GLM-4.7
241-
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml']
241+
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml', 'num_hidden_layers_5.yaml', 'glm4_moe.yaml']
242242
# --- DeepSeek V3.2 (Dec 2025) ---
243243
- name: deepseek-ai/DeepSeek-V3.2
244244
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml', 'num_hidden_layers_5.yaml']
@@ -248,7 +248,7 @@ models:
248248
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml', 'num_hidden_layers_5.yaml']
249249
# --- GLM-4.6 (Sep 2025) ---
250250
- name: zai-org/GLM-4.6
251-
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml']
251+
yaml_extra: ['dashboard_default.yaml', 'world_size_8.yaml', 'num_hidden_layers_5.yaml', 'glm4_moe.yaml']
252252
# --- Qwen3-Next (Sep 2025) ---
253253
- name: Qwen/Qwen3-Next-80B-A3B-Instruct
254254
yaml_extra: ['dashboard_default.yaml', 'world_size_4.yaml', 'qwen3Next.yaml']

tensorrt_llm/_torch/auto_deploy/models/custom/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .modeling_exaone import ExaoneForCausalLM
66
from .modeling_gemma import GemmaADForCausalLM
77
from .modeling_gemma2 import Gemma2ForCausalLM
8+
from .modeling_glm4_moe import Glm4MoeForCausalLM
89
from .modeling_glm4_moe_lite import Glm4MoeLiteForCausalLM
910
from .modeling_granite import GraniteForCausalLM
1011
from .modeling_granite_moe_hybrid import GraniteMoeHybridForCausalLM
@@ -35,6 +36,7 @@
3536
"ExaoneForCausalLM",
3637
"GemmaADForCausalLM",
3738
"Gemma2ForCausalLM",
39+
"Glm4MoeForCausalLM",
3840
"Glm4MoeLiteForCausalLM",
3941
"GraniteForCausalLM",
4042
"GraniteMoeHybridForCausalLM",

0 commit comments

Comments
 (0)