Skip to content

feat(glm5): align Megatron DeepEP training with SGLang rollout - #2262

Merged
zhuzilin merged 5 commits into
mainfrom
zilin/deterministic
Aug 11, 2026
Merged

zhuzilin merged 5 commits into
mainfrom
zilin/deterministic

Conversation

@zhuzilin

@zhuzilin zhuzilin commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Add a deterministic GLM-5 train/rollout alignment path covering Megatron training, SGLang inference, DeepGEMM, DeepEP, DSA sparse attention, and FP8 KV cache.

  • DeepGEMM: replace selected TE dense, indexer, shared-expert, and grouped-MoE forwards with SGLang-compatible batch-invariant block-FP8 kernels while retaining explicit BF16 dgrad and wgrad. Align FP32 router GEMM, SwiGLU, activation quantization, expert M padding, residual/RMSNorm boundaries, and shared-expert accumulation order. Bound peak memory with expert grouping and dead-buffer reuse, with Hopper FP32 and Blackwell UE8M0 scale support.

  • DeepEP: bridge Megatron normal DeepEP training and SGLang low-latency rollout by capturing exact top-k slot order, dispatching compact route metadata, validating receive layouts, and performing ordered FP32 token-owner gather with deterministic backward. Stage oversized low-latency prefill dispatches and request aligned FP8 quantization. Remove the ordinary Megatron all-to-all alignment bridge so DeepEP is the only supported MoE alignment backend.

  • GLM-5 and DSA: align fused q-RMSNorm input, indexer projections, FP8 logits, head weights, RoPE, deterministic top-k order, FlashMLA sparse forward, and Blackwell head padding. Add straight-through FP8-E4M3 KV-cache QAT and support flashmla_sparse over packed FP8 caches by gathering and dequantizing only selected pages.

  • Training integration: keep the DSA indexer frozen while all main-model parameters remain trainable, fail fast for unrecognized indexer layouts, preserve expert boundaries in online weight-transfer plans, canonicalize SGLang MoE-DP arguments, validate incomplete PP routing captures, and add a configurable CI train/rollout logprob threshold.

  • Packaging and CI: add current Megatron and SGLang deterministic patch sets in Docker dependency order, expose slime-hosted JIT kernel sources, add a GLM-5 router GEMM kernel, and register full 8-GPU logprob and exact layerwise alignment gates from the workflow template.

  • Validated with 100 focused tests, clean patch application, a 4096-token logprob MAE of 1.8943116231e-7, and exact zero hidden-state diff for decoder layers 0-5 over 4593 matched tokens per layer.

  • Validated with 750B production level training:

image image

The relevant DeepEP and DeepGEMM changes are:

Add a deterministic GLM-5 train/rollout alignment path covering Megatron training, SGLang inference, DeepGEMM, DeepEP, DSA sparse attention, and FP8 KV cache.

DeepGEMM: replace selected TE dense, indexer, shared-expert, and grouped-MoE forwards with SGLang-compatible batch-invariant block-FP8 kernels while retaining explicit BF16 dgrad and wgrad. Align FP32 router GEMM, SwiGLU, activation quantization, expert M padding, residual/RMSNorm boundaries, and shared-expert accumulation order. Bound peak memory with expert grouping and dead-buffer reuse, with Hopper FP32 and Blackwell UE8M0 scale support.

DeepEP: bridge Megatron normal DeepEP training and SGLang low-latency rollout by capturing exact top-k slot order, dispatching compact route metadata, validating receive layouts, and performing ordered FP32 token-owner gather with deterministic backward. Stage oversized low-latency prefill dispatches and request aligned FP8 quantization. Remove the ordinary Megatron all-to-all alignment bridge so DeepEP is the only supported MoE alignment backend.

GLM-5 and DSA: align fused q-RMSNorm input, indexer projections, FP8 logits, head weights, RoPE, deterministic top-k order, FlashMLA sparse forward, and Blackwell head padding. Add straight-through FP8-E4M3 KV-cache QAT and support flashmla_sparse over packed FP8 caches by gathering and dequantizing only selected pages.

Training integration: keep the DSA indexer frozen while all main-model parameters remain trainable, fail fast for unrecognized indexer layouts, preserve expert boundaries in online weight-transfer plans, canonicalize SGLang MoE-DP arguments, validate incomplete PP routing captures, and add a configurable CI train/rollout logprob threshold.

Packaging and CI: add current Megatron and SGLang deterministic patch sets in Docker dependency order, expose slime-hosted JIT kernel sources, add a GLM-5 router GEMM kernel, and register full 8-GPU logprob and exact layerwise alignment gates from the workflow template.

Validated with 100 focused tests, clean patch application, a 4096-token logprob MAE of 1.8943116231e-7, and exact zero hidden-state diff for decoder layers 0-5 over 4593 matched tokens per layer.
Download the six-layer FP8 Hugging Face fixture and public prompt data into standard container paths instead of relying on personal mounts. Load Megatron and reference weights directly from the same HF checkpoint, while continuing to train all main-model parameters and freeze the indexer.

Print explicit skip reasons for runners without the deterministic GPU stack, and report them from direct pytest entry points.

Fix layerwise dump parsing to pair adjacent cumulative sequence offsets without strict zip length equality, and cover multi-sequence packed dumps with a CPU regression test.

Validated with the full 8-GPU six-layer exact gate: every compared decoder layer matched exactly and train/rollout logprob MAE was 1.9744038582e-7.
Keep the runner HTTP(S) proxy intact until the public Hugging Face model and dataset fixtures have been materialized. The gate still removes proxy variables from the Ray and SGLang child environment after downloads, preserving local worker discovery behavior.
Run both the full train/rollout gate and the layerwise exact gate with stateless Adam so the one-step CI workload does not allocate persistent first- and second-moment states.

Remove CPU optimizer offload, CPU transfer overlap, and precision-aware optimizer flags, which are unnecessary or incompatible with stateless Adam. Keep the indexer frozen and continue training all other model parameters.
@zhuzilin
zhuzilin merged commit a74ae3a into main Aug 11, 2026
61 checks passed
@zhuzilin
zhuzilin deleted the zilin/deterministic branch August 11, 2026 03:46
@gongshaotian

gongshaotian commented Aug 11, 2026 •

Copy link
Copy Markdown

How is 25% calculated? Can you provide a reproducible and testable startup configuration (especially for SGLang)? @zhuzilin

@zhuzilin

zhuzilin commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@gongshaotian

How is 25% calculated?

by the e2e step time of the above run (updated in the above post).

Can you provide a reproducible and testable startup configuration (especially for SGLang)?

you can check the added ci, there is one test for e2e mismatch, and one for layerwise no-diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants