cp: fix: DTensor materialization in MoE state_dict adapter for ep_shard > 1#1483
Merged
cp: fix: DTensor materialization in MoE state_dict adapter for ep_shard > 1#1483
Conversation
Use full_tensor() instead of .cpu() for DTensor parameters to correctly all-gather across FSDP shard dimensions. In from_hf, slice expert weights by ep_shard to load only the local expert partition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: HuiyingLi <willwin.lee@gmail.com>
Contributor
Author
|
/ok to test 05ce033 |
akoumpa
approved these changes
Mar 7, 2026
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
Cherry-pick from internal
zhiqi-devbranch (commit0ba321ce).Author: zhiqil zhiqil@nvidia.com
In multi-node training with
ep_shard_size > 1, expert weights are sharded as DTensors along bothepandep_sharddimensions. When saving checkpoints,to_hf()uses.cpu()on these DTensors, which preserves the DTensor wrapper and causesRuntimeError: got mixed torch.Tensor and DTensorduringall_gather_object.Fix:
to_hf(): Use.full_tensor().cpu()instead of.cpu()to all-gather across all shard dimensions before serializationfrom_hf(): Slice expert weights ondim=1byep_shard_rankto load only the local expert partitionFiles changed
nemo_automodel/components/models/qwen3_5_moe/state_dict_adapter.pynemo_automodel/components/models/qwen3_vl_moe/state_dict_adapter.pytests/unit_tests/models/qwen3_5_moe/test_qwen3_5_moe_state_dict_adapter.pytests/unit_tests/models/qwen3_vl_moe/test_qwen3_vl_moe_state_dict_adapter.pyRepro (8 GPUs, EP=4 → ep_shard_size=2)
torchrun --nproc-per-node=8 examples/vlm_finetune/finetune.py \ --config examples/vlm_finetune/qwen3/qwen3_vl_moe_30b_te_deepep.yaml \ --step_scheduler.max_steps 3 --step_scheduler.ckpt_every_steps 2 \ --checkpoint.enabled true --distributed.ep_size 4Before:
RuntimeError: got mixed torch.Tensor and DTensorat checkpoint saveAfter: Checkpoint saves and consolidates successfully