Skip to content

fix: swap DTensor shard placements after transpose in Step3p5 state dict adapter#1691

Merged
akoumpa merged 2 commits intomainfrom
fix/step3p5-dtensor-placement-transpose
Apr 6, 2026
Merged

fix: swap DTensor shard placements after transpose in Step3p5 state dict adapter#1691
akoumpa merged 2 commits intomainfrom
fix/step3p5-dtensor-placement-transpose

Conversation

@adil-a
Copy link
Copy Markdown
Collaborator

@adil-a adil-a commented Apr 6, 2026

Summary

  • Fix Step3p5 model checkpoint loading crash when ep_shard_size > 1 (i.e. DP replicas exist beyond EP)
  • The Step3p5StateDictAdapter transposes dims 1↔2 when converting between HF and native MoE weight formats, but was recreating DTensors with the original Shard placements — causing Shard(1) (from FSDP2's shard_placement_fn=lambda _: Shard(1) in the MoE parallelizer) to apply to the wrong axis after transpose
  • This produced incorrect global shapes (e.g. [288, 8192, 640] instead of [288, 4096, 1280] for down_proj.weight), making DCP load fail with ValueError: Size mismatch
  • The fix swaps Shard(1)Shard(2) in placements after every transpose(1, 2) across all 4 conversion sites (2 in to_hf, 2 in from_hf)

Test plan

  • All 17 existing Step3p5 state dict adapter unit tests pass
  • Validated on cw-dfw with same CI config (PP=2, EP=32, 16 nodes, 128 GPUs): model loads, trains 10 steps (loss 5.12→2.92), and saves consolidated safetensors checkpoint successfully
  • CI job that originally failed: https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/jobs/292910876

🤖 Generated with Claude Code

…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>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 6, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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>
@adil-a
Copy link
Copy Markdown
Collaborator Author

adil-a commented Apr 6, 2026

/ok to test 276298c

@akoumpa akoumpa merged commit 5018039 into main Apr 6, 2026
53 of 54 checks passed
@akoumpa akoumpa deleted the fix/step3p5-dtensor-placement-transpose branch April 6, 2026 22:19
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants