Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183629
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 04a3a76 with merge base 9c77719 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
weifengpy
left a comment
There was a problem hiding this comment.
add a unit test with grad norm to catch the error on HEAD~1 but pass on HEAD?
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot merge |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
When fully_shard receives multiple DP shard dimensions via DataParallelMeshDims (e.g. dp_shard + cp), _get_mesh_info_from_named_dims already flattens them into a single process group for the all-gather and reduce-scatter. However, _init_sharding_spec_spmd was building the sharding spec on the original SPMD mesh with separate axes, so the parameter and gradient DTensors exposed N separate Shard axes instead of one. This caused two problems for downstream consumers like clip_grad_norm_: - DTensor's _NormPartial reduction happened per-axis sequentially, producing different float32 summation order than the legacy path (which has a single flattened fsdp axis). - The Shard(0) on cp and dp_shard is actually not correct. It should be _StridedShard Fix: add _build_spmd_sharding_spec which reuses mesh_info.mesh (the already-flattened DP mesh from _get_mesh_info_from_named_dims) and concatenates it with non-DP submeshes following spmd_mesh.mesh_dim_names order. When there is only one DP shard dim, the method is a no-op. Verified bit-identical loss and grad_norm between legacy and full_dtensor at 500 steps across FSDP+CP+TP, HSDP+CP, and HSDP+TP configurations with TorchTitan. Pull Request resolved: pytorch#183629 Approved by: https://github.com/weifengpy ghstack dependencies: pytorch#180937, pytorch#180936
When fully_shard receives multiple DP shard dimensions via DataParallelMeshDims (e.g. dp_shard + cp), _get_mesh_info_from_named_dims already flattens them into a single process group for the all-gather and reduce-scatter. However, _init_sharding_spec_spmd was building the sharding spec on the original SPMD mesh with separate axes, so the parameter and gradient DTensors exposed N separate Shard axes instead of one. This caused two problems for downstream consumers like clip_grad_norm_: - DTensor's _NormPartial reduction happened per-axis sequentially, producing different float32 summation order than the legacy path (which has a single flattened fsdp axis). - The Shard(0) on cp and dp_shard is actually not correct. It should be _StridedShard Fix: add _build_spmd_sharding_spec which reuses mesh_info.mesh (the already-flattened DP mesh from _get_mesh_info_from_named_dims) and concatenates it with non-DP submeshes following spmd_mesh.mesh_dim_names order. When there is only one DP shard dim, the method is a no-op. Verified bit-identical loss and grad_norm between legacy and full_dtensor at 500 steps across FSDP+CP+TP, HSDP+CP, and HSDP+TP configurations with TorchTitan. Pull Request resolved: pytorch#183629 Approved by: https://github.com/weifengpy ghstack dependencies: pytorch#180937, pytorch#180936
Stack from ghstack (oldest at bottom):
When fully_shard receives multiple DP shard dimensions via DataParallelMeshDims (e.g. dp_shard + cp), _get_mesh_info_from_named_dims already flattens them into a single process group for the all-gather and reduce-scatter. However, _init_sharding_spec_spmd was building the sharding spec on the original SPMD mesh with separate axes, so the parameter and gradient DTensors exposed N separate Shard axes instead of one.
This caused two problems for downstream consumers like clip_grad_norm_:
Fix: add _build_spmd_sharding_spec which reuses mesh_info.mesh (the already-flattened DP mesh from _get_mesh_info_from_named_dims) and concatenates it with non-DP submeshes following spmd_mesh.mesh_dim_names order. When there is only one DP shard dim, the method is a no-op.
Verified bit-identical loss and grad_norm between legacy and full_dtensor at 500 steps across FSDP+CP+TP, HSDP+CP, and HSDP+TP configurations with TorchTitan.