Repository navigation
Conversation
…llelism MFSDP v2 shards embeddings with uneven (flat-buffer) offsets, and different PP stages can use different flattened layouts. Two ranks owning the same logical slice may hold it at different flat-buffer offsets with different local shard shapes, so reducing the raw local shards directly would combine mismatched elements. Reconstruct the full logical embedding gradient via uneven_dtensor_to_full_tensor before the PP all-reduce, then copy back the slice this rank owns into its shard's local tensor. Signed-off-by: Jianbin Chang <jianbinc@nvidia.com>
shjwudp
added a commit
to shjwudp/Megatron-LM
that referenced
this pull request
Sep 11, 2026
…llelism MFSDP v2 shards embeddings with uneven (flat-buffer) offsets, and different PP stages can use different flattened layouts. Two ranks owning the same logical slice may hold it at different flat-buffer offsets with different local shard shapes, so reducing the raw local shards directly would combine mismatched elements. Reconstruct the full logical embedding gradient via uneven_dtensor_to_full_tensor before the PP all-reduce, then copy back the slice this rank owns into its shard's local tensor. Without this, MFSDP v2 + PP/VPP fails in finalize_model_grads._allreduce_embedding_grad with "attempting to assign a gradient of size '[N,1024]' to a tensor of size '[V,1024]'". This is NVIDIA PR NVIDIA#6500's change (author: Jianbin Chang), ported so shjwudp:split/pr-d-shared-context (PR NVIDIA#6486) actually runs MFSDP v2 + VPP. Excluded the separate MFSDP-v2+MoE empty-shard TE workaround (PR NVIDIA#7002). Validated on EOS H100 (deepseek_v3_proxy, real DeepSeek-V3 SlimPajama, PP=2/VPP=2, seed 1234, 1000 iters): M-FSDP v2 and DistOpt converge to the same val-loss (diff <= ~0.02, 0 NaN, exit 0). Signed-off-by: Jianbin Chang <jianbinc@nvidia.com> Signed-off-by: Jack Chang <jianbinc@nvidia.com>
shjwudp
added a commit
to shjwudp/Megatron-LM
that referenced
this pull request
Sep 20, 2026
…llelism MFSDP v2 shards embeddings with uneven (flat-buffer) offsets, and different PP stages can use different flattened layouts. Two ranks owning the same logical slice may hold it at different flat-buffer offsets with different local shard shapes, so reducing the raw local shards directly would combine mismatched elements. Reconstruct the full logical embedding gradient via uneven_dtensor_to_full_tensor before the PP all-reduce, then copy back the slice this rank owns into its shard's local tensor. Without this, MFSDP v2 + PP/VPP fails in finalize_model_grads._allreduce_embedding_grad with "attempting to assign a gradient of size '[N,1024]' to a tensor of size '[V,1024]'". This is NVIDIA PR NVIDIA#6500's change (author: Jianbin Chang), ported so shjwudp:split/pr-d-shared-context (PR NVIDIA#6486) actually runs MFSDP v2 + VPP. Excluded the separate MFSDP-v2+MoE empty-shard TE workaround (PR NVIDIA#7002). Validated on EOS H100 (deepseek_v3_proxy, real DeepSeek-V3 SlimPajama, PP=2/VPP=2, seed 1234, 1000 iters): M-FSDP v2 and DistOpt converge to the same val-loss (diff <= ~0.02, 0 NaN, exit 0). Signed-off-by: Jianbin Chang <jianbinc@nvidia.com> Signed-off-by: Jack Chang <jianbinc@nvidia.com>
copy-pr-bot Bot
pushed a commit
that referenced
this pull request
Sep 22, 2026
…llelism MFSDP v2 shards embeddings with uneven (flat-buffer) offsets, and different PP stages can use different flattened layouts. Two ranks owning the same logical slice may hold it at different flat-buffer offsets with different local shard shapes, so reducing the raw local shards directly would combine mismatched elements. Reconstruct the full logical embedding gradient via uneven_dtensor_to_full_tensor before the PP all-reduce, then copy back the slice this rank owns into its shard's local tensor. Without this, MFSDP v2 + PP/VPP fails in finalize_model_grads._allreduce_embedding_grad with "attempting to assign a gradient of size '[N,1024]' to a tensor of size '[V,1024]'". This is NVIDIA PR #6500's change (author: Jianbin Chang), ported so shjwudp:split/pr-d-shared-context (PR #6486) actually runs MFSDP v2 + VPP. Excluded the separate MFSDP-v2+MoE empty-shard TE workaround (PR #7002). Validated on EOS H100 (deepseek_v3_proxy, real DeepSeek-V3 SlimPajama, PP=2/VPP=2, seed 1234, 1000 iters): M-FSDP v2 and DistOpt converge to the same val-loss (diff <= ~0.02, 0 NaN, exit 0). Signed-off-by: Jianbin Chang <jianbinc@nvidia.com> Signed-off-by: Jack Chang <jianbinc@nvidia.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
MFSDP v2 shards embeddings with uneven (flat-buffer) offsets, and different PP stages can use different flattened layouts. Two ranks that own the same logical slice may hold it at different flat-buffer offsets with different local shard shapes, so reducing the raw local shards directly would combine mismatched elements.
Reconstruct the full logical embedding gradient via
uneven_dtensor_to_full_tensorbefore the PP all-reduce, then copy back the slice this rank owns into its shard's local tensor.Changes
finalize_model_grads.py: in_allreduce_embedding_grad, foruse_megatron_fsdp, reconstruct the full logical embedding gradient before the all-reduce and copy back the local shard slice.Notes
Split out of PR #6197; standalone (no dependency on the overlap PR).