Fix GLM4-MoE HF export and RL vLLM reload compatibility#1886
Open
mansimov wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
Open
Fix GLM4-MoE HF export and RL vLLM reload compatibility#1886mansimov wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
mansimov wants to merge 1 commit intoPrimeIntellect-ai:mainfrom
Conversation
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.
Summary
This PR fixes a set of GLM4-MoE compatibility issues found while running the small-scale MoE flow (
mini_moe -> SFT warmup -> RL):scripts/mini_moe.pyverify path no longer unexpectedly requiresacceleratePrimeRL -> HFexport now writes fused routed-expert keys expected by currenttransformershead_dim(needed for vLLM/transformers config compatibility)/update_weightsreload worksRoot Cause
There were two key format mismatches:
transformersGLM4-MoE expects fusedkeys (
gate_up_proj,down_proj)/update_weights) stillfailed on fused GLM4-MoE expert keys during RL filesystem weight broadcasts
Changes
scripts/mini_moe.pyverify(...), then move to CUDA for parity checkstransformersfrom_pretrained()requiringacceleratedue totorch.device("cuda")context interactionsrc/prime_rl/trainer/models/glm4_moe/converting_glm4_moe.pyconvert_tt_to_hfto export fused routed expert tensors:model.layers.<i>.mlp.experts.gate_up_projmodel.layers.<i>.mlp.experts.down_projsrc/prime_rl/trainer/models/glm4_moe/configuration_glm4_moe.pyhead_dimvalues in checkpointconfig.jsonsrc/prime_rl/trainer/rl/broadcast/filesystem.pyoutputs/weights/step_*HF-compatible (fused)outputs/run_default/broadcasts/step_*vLLM-reload-compatible (per-expert)Validation
Roundtrip verification
uv run python scripts/mini_moe.py --arch glm4_moe --output-dir outputs/weights/step_200 --verify-onlyHF vs PrimeRLandHF -> PrimeRL -> HFmax logits diffs are small, verification passesRL run with live updates
collective_rpc update_weights_from_pathfailureEnvironment (validated on)
Note
Medium Risk
Touches model weight conversion and checkpoint/broadcast serialization for GLM4-MoE, so a mistake could break loading or live reload in Transformers/vLLM. Scope is localized and adds targeted compatibility shims rather than broad refactors.
Overview
Fixes GLM4-MoE weight format mismatches across HF export, roundtrip verification, and RL vLLM live reload.
GLM4-MoE TT→HF conversion now exports routed experts in the new fused Transformers format (
mlp.experts.gate_up_proj+mlp.experts.down_proj) instead of per-expert keys, andGlm4MoeConfignow tolerates serializedhead_dimvia a property.For RL filesystem broadcasts, GLM4-MoE checkpoints are converted back from fused to per-expert tensors right before saving so vLLM
/update_weightsreload continues to work, andscripts/mini_moe.pyverification avoidstorch.device("cuda")duringfrom_pretrained()(preventing an unexpectedacceleraterequirement) by loading on CPU then moving models/inputs to CUDA.Written by Cursor Bugbot for commit b96a8a8. This will update automatically on new commits. Configure here.