Conversation
…ict adapter When FSDP2 shards MoE expert params on dim 1 (via ep_shard mesh), the Step3p5StateDictAdapter's to_hf/from_hf conversions transposed dims 1 and 2 of the local tensor but recreated the DTensor with the original placements. This caused Shard(1) to apply to the wrong axis, producing incorrect global shapes (e.g. [288, 8192, 640] instead of [288, 4096, 1280] for down_proj.weight), which made DCP checkpoint loading fail with a size mismatch error. The fix swaps Shard(1) <-> Shard(2) in placements after every transpose(1, 2) so DTensor.from_local infers the correct global shape. Signed-off-by: adil-a <adasif@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adil-a <adil.asif2000@hotmail.com>
Pass swapped placements through _create_dtensor_from_local_or_reference via a new placements_override parameter instead of duplicating the DTensor creation logic inline. Signed-off-by: adil-a <adasif@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adil-a <adil.asif2000@hotmail.com>
Collaborator
Author
|
/ok to test 276298c |
akoumpa
approved these changes
Apr 6, 2026
linnanwang
pushed a commit
that referenced
this pull request
Apr 24, 2026
…ict adapter (#1691) * fix: swap DTensor shard placements after transpose in Step3p5 state dict adapter When FSDP2 shards MoE expert params on dim 1 (via ep_shard mesh), the Step3p5StateDictAdapter's to_hf/from_hf conversions transposed dims 1 and 2 of the local tensor but recreated the DTensor with the original placements. This caused Shard(1) to apply to the wrong axis, producing incorrect global shapes (e.g. [288, 8192, 640] instead of [288, 4096, 1280] for down_proj.weight), which made DCP checkpoint loading fail with a size mismatch error. The fix swaps Shard(1) <-> Shard(2) in placements after every transpose(1, 2) so DTensor.from_local infers the correct global shape. Signed-off-by: adil-a <adasif@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adil-a <adil.asif2000@hotmail.com> * refactor: use placements_override param instead of bypassing helper Pass swapped placements through _create_dtensor_from_local_or_reference via a new placements_override parameter instead of duplicating the DTensor creation logic inline. Signed-off-by: adil-a <adasif@nvidia.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adil-a <adil.asif2000@hotmail.com> --------- Signed-off-by: adil-a <adil.asif2000@hotmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
ep_shard_size > 1(i.e. DP replicas exist beyond EP)Step3p5StateDictAdaptertransposes dims 1↔2 when converting between HF and native MoE weight formats, but was recreating DTensors with the originalShardplacements — causingShard(1)(from FSDP2'sshard_placement_fn=lambda _: Shard(1)in the MoE parallelizer) to apply to the wrong axis after transpose[288, 8192, 640]instead of[288, 4096, 1280]fordown_proj.weight), making DCPloadfail withValueError: Size mismatchShard(1)↔Shard(2)in placements after everytranspose(1, 2)across all 4 conversion sites (2 into_hf, 2 infrom_hf)Test plan
🤖 Generated with Claude Code