Repository navigation
feat(glm5): align Megatron DeepEP training with SGLang rollout - #2262
Merged
Merged
Conversation
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.
|
How is 25% calculated? Can you provide a reproducible and testable startup configuration (especially for SGLang)? @zhuzilin |
Contributor
Author
by the e2e step time of the above run (updated in the above post).
you can check the added ci, there is one test for e2e mismatch, and one for layerwise no-diff. |
1 task done
This was referenced Sep 2, 2026
Draft
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.
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:
The relevant DeepEP and DeepGEMM changes are: