[feat] Add Qwen3 MoE true-on-policy parity - #30
Open
maocheng23 wants to merge 40 commits into
Open
Conversation
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Yueming Yuan <yym022502@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
- Detach output layer params to prevent MTP gradient flowing to output layer - Add mtp_kwargs interface for flexible MTP label/loss_mask passing - Roll mtp_labels and loss_mask for RL training compatibility Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Yueming Yuan <yym022502@gmail.com>
…yers (#10) - Add is_mtp flag to MoE layers and multi_token_prediction module - Bypass routing replay for MTP layers (MTP uses fresh routing) - Replace rdxa/dev's built-in RouterReplay with miles.utils.routing_replay: - moe_utils.py: use get_routing_replay_compute_topk() wrapper - router.py: use register_routing_replay() for initialization Co-authored-by: Yueming Yuan <yym022502@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Yueming Yuan <yym022502@gmail.com>
After bumping Megatron (rdxa/dev), colocated IPC weight update fails with torch.AcceleratorError: CUDA error: invalid argument during torch.multiprocessing serialization of CUDA tensors. Root cause: Megatron's new TMS hook (PR NVIDIA#3048) alters allocator behavior in training flow, causing allocations via cuMemCreate/cuMemMap which are incompatible with CUDA IPC (_share_cuda_() fails). Fix: resolve mapping.py and dynamic_context.py conflicts to isolate hook side effects so TMS/allocator state remains IPC-compatible during the weight update phase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- merge(): truncate dp_reshardable padding on optimizer/param_state path - load_parameter_state_from_dp_reshardable: tolerate missing 'padding' key - ShardedTensor: relax flattened_range to deprecation warning Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This PR rebases from radixark Megatron fork [miles-20260218](https://github.com/radixark/Megatron-LM/tree/miles-20260218) and resolve conflicts. Upgrade Megatron from Dec 17 (3714d81) to Feb 13 (1dcf0da) PR link: #13 Co-authored-by: Yueming Yuan <yym022502@gmail.com> Made-with: Cursor
…se `--disable-weight-backuper` in miles (#18) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com>
Co-authored-by: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com>
This was referenced May 1, 2026
maocheng23
force-pushed
the
feat/true_on_policy_qwen_moe
branch
from
May 5, 2026 01:51
c63c77f to
9c390a1
Compare
5 tasks
maocheng23
force-pushed
the
feat/true_on_policy_qwen_dense
branch
2 times, most recently
from
May 18, 2026 06:15
9546575 to
57258c8
Compare
Squash merge of the dense true-on-policy Megatron branch. Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
maocheng23
force-pushed
the
feat/true_on_policy_qwen_moe
branch
3 times, most recently
from
May 19, 2026 18:44
ab103f8 to
9c6c2a9
Compare
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: zju-stu-lizheng <lizheng.cs@zju.edu.cn> Co-authored-by: zyxiyy02 <282300612+zyxiyy02@users.noreply.github.com> Co-authored-by: Yi Zhang <1109276519@qq.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- forward.py: single canonical sglang_moe_forward (102 lines) - autograd.py: pure backward wrapper calling shared forward (182 lines) - moe_experts.py: weight-layout adapter only, no forward logic (36 lines) - moe_layer_ext.py: one linear orchestration path (301 lines) - Remove verbose RuntimeError guards, replace with asserts - Remove weight caching (premature optimization) - Consolidate two parallel forward paths into one Net: -574 lines, structurally impossible for forward paths to diverge. Co-authored-by: Cursor <cursoragent@cursor.com>
maocheng23
force-pushed
the
feat/true_on_policy_qwen_moe
branch
from
May 23, 2026 02:47
7ac2a80 to
b0679e2
Compare
6 tasks
maocheng23
marked this pull request as ready for review
May 23, 2026 21:22
maocheng23
changed the base branch from
feat/true_on_policy_qwen_dense
to
miles-main
May 23, 2026 22:20
Zhichenzzz
approved these changes
May 25, 2026
Zhichenzzz
left a comment
There was a problem hiding this comment.
Great work, LGTM! Just a small possible change for me, Thanks @maocheng23 !
| torch.distributed.all_gather(gathered, padded, group=ep_group) | ||
| return torch.cat(gathered, dim=0) | ||
|
|
||
| @staticmethod |
There was a problem hiding this comment.
The list-of-tensors form forces torch to assemble a single contiguous input buffer before handing off to NCCL. The input here is already a single contiguous tensor grad_output.contiguous(), could we pass it directly to reduce_scatter_tensor to reduce comm overhead?
torch.distributed.reduce_scatter_tensor(
grad_local,
grad_output,
group=ctx.ep_group,
)
This was referenced May 26, 2026
7 tasks
yueming-yuan
force-pushed
the
miles-main
branch
from
August 24, 2026 19:59
2e64d78 to
235952d
Compare
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
Adds the Megatron-LM side of the Qwen3-30B-A3B MoE true-on-policy stack.
This PR is one of three coupled PRs that must land together because they share the
qwen3_moe_true_on_policy_v1contract and were validated as one end-to-end stack.Companion PRs:
Target
Bit-identical rollout/train logprob parity for Qwen3-30B-A3B MoE under deterministic decode, with differentiable Megatron backward.
SGLang remains the numerical source of truth. Megatron reproduces the SGLang MoE numerics in training, including deterministic routing/top-k and EP reduction behavior required by the contract.
Main Changes
moe_runner.triton_utilslayout.qwen3_moe_true_on_policy_v1contract.Validation
Latest rebased EP4 E2E on ion7, Qwen3-30B-A3B, 8x H200, run
qwen3-moe-top-ep4-rebased-e2e-260522-ion7-r4:raysubmit_yc4WK8aCKzP4tx1QTP=1, EP=4, ETP=1, CP=2rollout_num_gpus=8,rollout_num_gpus_per_engine=4,SGLang TP=4,SGLang EP=4recompute_logprobs_via_prefill=False,use_rollout_logprobs=False-2.8848648071289062e-05-2.8848648071289062e-05-2.8848648071289062e-05train/train_rollout_logprob_abs_diff = 0.0train/train_rollout_kl = 0.0Local record:
recovery/qwen3_moe_clean/journal/2026-05-22-qwen3-moe-clean-e2e.mdTest Plan
radixark/Megatron-LM:miles-mainstack.