fix(moe): align EP expert weight dtype with activation dtype#1913
Open
jQizhang wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Open
fix(moe): align EP expert weight dtype with activation dtype#1913jQizhang wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
jQizhang wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Conversation
…NeMo#1863) FSDP2's MixedPrecisionPolicy only casts params on its wrap mesh, so cross-mesh DTensors (EP-sharded MoE experts) stay in fp32 while the surrounding block's activations are cast to bf16. grouped_mm then raises `Expected b.scalar_type() == torch::kBFloat16 to be true, but got false` (see NVIDIA-NeMo#1863). Fix: in `GroupedExperts.forward` and `GroupedExpertsDeepEP.forward`, cast the local expert weights to the input activation dtype right before grouped_mm. This matches grouped_mm's own requirement that both operands share a dtype. The .data is not mutated, so fp32 master weights remain available to the optimizer. Validation: smoke tests on NeMo-RL GRPO 1n8g + Gemma4 26B-A4B MoE against Automodel main @ bd942f2. * Without this patch: DTensorPolicyWorkerV2.get_logprobs() crashes at grouped_gemm.backend.gmm with the exact NVIDIA-NeMo#1863 error string. * With this patch: 3 GRPO steps complete, loss -0.007/0.008/-0.014, reward 0.70/0.60/0.84. Signed-off-by: larkzhang-nv <larkz@nvidia.com>
Contributor
|
/ok to test 31f4157 |
ZhiyuLi-Nvidia
approved these changes
Apr 20, 2026
Contributor
ZhiyuLi-Nvidia
left a comment
There was a problem hiding this comment.
Thank you @jQizhang. LGTM!
Contributor
|
@hemildesai could you also take a review? |
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 ?
Fix issue #1863 : EP-sharded MoE expert weights stay in fp32 while the surrounding block's activations are cast to bf16 by FSDP2's MixedPrecisionPolicy, causing grouped_mm to crash with a dtype mismatch. Aligns expert weight dtype to the input activation dtype at the call site.
Changelog
Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information