fix(grpo): make runtime contracts and GLM router replay fail closed - #27
Closed
Alvorecer721 wants to merge 8 commits into
Closed
fix(grpo): make runtime contracts and GLM router replay fail closed#27Alvorecer721 wants to merge 8 commits into
Alvorecer721 wants to merge 8 commits into
Conversation
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
Owner
Author
|
/ok to test 1c7d48f |
Owner
Author
|
Superseded by #28, which carries the fail-closed runtime-contract and Router Replay gates on the upstream-a952 line (see its handoff for the merge-loss scan). Closing; the branch is retained. |
Alvorecer721
added a commit
that referenced
this pull request
Sep 3, 2026
Claude-Session: https://claude.ai/code/session_018M6M298UPyUhUZDnQDg4pS Signed-off-by: Alvorecer721 <yixuan.xu@ai.ethz.ch>
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.
What does this PR do?
Makes GRPO runtime contracts fail closed and adds a production-scale GLM-5.1 Router Replay (R3) gate with explicit numerical, trace-integrity, learning-signal, and completion checks.
The MoE routing correction itself already exists upstream. The GLM recipe activates it with:
This PR does not introduce a new routing algorithm. It makes the existing integration safe to operate and possible to certify: entrypoints reject incompatible runtime combinations before Ray startup, SingleController rejects unsupported no-op controls, trace validation selects the actual transport contract, and the test harness can no longer report incomplete or stale runs as successful.
Issues
No linked issue.
Why Router Replay is needed
After refit, vLLM and Megatron have the same policy weights, but an MoE model still has a discrete decision inside each layer. Small numerical differences in independently computed router scores can change the final top-k expert when candidates are close. The token then executes a different expert network, creating train-versus-rollout logprob mismatch that is unrelated to a policy update.
R3 records only the expert IDs selected during vLLM generation and replays those IDs in Megatron. Megatron still computes current router scores, gathers current probabilities for the selected experts, executes current expert weights, and computes gradients normally. R3 therefore fixes expert-selection consistency; it does not remove a forward pass or freeze the router.
flowchart LR Refit["Refit the same policy weights"] subgraph Rollout["Rollout / behavior policy: vLLM"] VHidden["Token hidden states"] VScores["vLLM router scores"] VTopK["vLLM top-k selection"] VExperts["Selected experts execute"] VLogprobs["generation_logprobs"] VRoutes["routed_experts<br/>token x MoE layer x top-k"] VHidden --> VScores --> VTopK --> VExperts --> VLogprobs VTopK --> VRoutes end subgraph Transport["NeMo RL rollout payload"] Messages["tokens + masks + generation_logprobs"] Routes["routed_experts<br/>encoded and batch-aligned"] ReplayBuffer["ReplayBuffer or TransferQueue"] Messages --> ReplayBuffer Routes --> ReplayBuffer end subgraph Alignment["Megatron route preparation"] Decode["Decode route tensor"] ParallelMap["Map global MoE layers to local PP layers<br/>and slice token rows for TP/SP/CP"] Validate{"Every route complete and valid?"} Install["Install expert IDs on each<br/>model-owned RouterReplay instance"] Fallback["All -1 row only:<br/>compute Megatron top-k for that row<br/>and emit fallback telemetry"] Decode --> ParallelMap --> Validate Validate -- "yes" --> Install Validate -- "missing sentinel" --> Fallback --> Install end subgraph Training["Policy backend: Megatron"] MWeights["Current Megatron policy weights"] MScores["Current Megatron router scores"] FixedTopK["Use replayed expert IDs<br/>instead of a new top-k decision"] Gather["Gather current scores for<br/>the replayed experts"] Prev["Prev-logprob forward"] PrevLP["prev_logprobs"] Train["Training forward"] Loss["GRPO loss / importance ratio"] Backward["Backward or activation recomputation<br/>replays the same expert IDs"] Update["Update router and expert parameters"] MWeights --> MScores --> FixedTopK --> Gather Gather --> Prev --> PrevLP Gather --> Train --> Loss --> Backward --> Update Install --> FixedTopK FixedTopK --> Backward end Refit --> VHidden Refit --> MWeights VLogprobs --> Messages VRoutes --> Routes ReplayBuffer --> Decode VLogprobs --> Compare["Generation-KL and<br/>token probability-error metrics"] PrevLP --> Compare Independent["Without R3: Megatron independently<br/>selects top-k; a boundary tie can choose<br/>different experts despite matched weights"] MScores -. "R3 disabled" .-> Independent -. "artificial mismatch" .-> CompareRuntime evidence
The completed 80-node GLM-5.1 run used TP2/PP18/EP16 Megatron training, TP32/EP32 vLLM generation, legacy async GRPO, and ten training steps.
3147936)3171492)0.002500.00038760.0022966-0.00270890.0003615-0.00040613,858,2211,291,712abs(delta log p) > 0.57,873(0.204%)4(0.000310%)abs(delta log p) > 1.0570(0.0148%)0abs(delta log p)37.72570.676Job
3171492completed all ten training steps and printedAsync GRPO training complete!. Its final wrapper status was a false red: the old trace checker unconditionally required SingleController/TransferQueue events, although this recipe deliberately used legacy async GRPO and its in-memory ReplayBuffer. The 269,952 route records did contain assignments, replay actions, forward verification, and context-parallel identity evidence.That run is strong routing-correctness evidence but not yet the final learning-quality gate. Only five of ten batches had nonzero reward/advantage/loss because 94.5-100% of responses hit the 1024-token generation cap. The revised recipe increases the envelope to 2048 total / 1536 generated tokens and retains strict requirements instead of weakening them.
Changes
Runtime and configuration contracts
async_grpoblock out of SingleController setup.Trace and completion contracts
legacy-asyncortransfer-queueR3 trace schema.train/lossthroughMAX_STEPS; intermediate chained runs remain valid; original nonzero exit codes are preserved.GLM production gate
0.9, no valid-token error above1.0, and a fraction below1e-4above0.5.0.001, valid R3 route traces, and a clean terminal artifact.Usage
Submit the production-scale gate through the checked-in launcher:
The launcher preserves the complete GLM checkpoint and conversion cache and uses the existing reservation contract.
Validation completed
python -m compileallfor changed Python paths.bash -nfor changed launch/test shell paths.git diff --check.Before this draft is ready for review
Additional information