Avoid extra MFSDP v2 model-weight sync memcpy - #5834
Merged
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
wujingyue
force-pushed
the
cast
branch
3 times, most recently
from
July 16, 2026 01:25
1081a42 to
1c948b3
Compare
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
wujingyue
force-pushed
the
cast
branch
2 times, most recently
from
July 16, 2026 01:32
44885b9 to
85cbc0c
Compare
wujingyue
marked this pull request as ready for review
July 16, 2026 01:33
Contributor
Author
|
/ok to test 85cbc0c |
shjwudp
approved these changes
Jul 17, 2026
jiemingz
approved these changes
Jul 17, 2026
ericharper
approved these changes
Jul 17, 2026
ericharper
enabled auto-merge
July 17, 2026 18:03
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29602452616 |
chochowski
pushed a commit
to chochowski/Megatron-LM
that referenced
this pull request
Jul 20, 2026
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com> Signed-off-by: mchochowski <mchochowski@nvidia.com>
terminator123
pushed a commit
to 021ai/Megatron-LM
that referenced
this pull request
Aug 3, 2026
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
svcnvidia-nemo-ci
pushed a commit
to dimapihtar/Megatron-LM
that referenced
this pull request
Aug 4, 2026
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com> Signed-off-by: Dmytro Pykhtar <dpykhtar@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
main_weightdirectly into the persistentmodel_weightbuffer for the same-placement path.Root cause
sync_model_weight_from_main_weight()always castmain_weightinto a temporary compute-dtypeDBuffer, then calledredistribute(..., out=model_weight). Whenmain_weightandmodel_weightalready had the same placements,redistributeonly copied the temporary buffer intomodel_weight, producing an avoidable D2D memcpy after the cast.Implementation
This adds an
out=path toDBuffer.castand uses it from MFSDP v2 model-weight sync. The DBuffer helper change is an implementation detail for writing the cast result directly into existing storage.Validation
UV_NO_SYNC=1 CUDA_VISIBLE_DEVICES=0,1 uv run python -m torch.distributed.run --nproc-per-node 2 -m pytest -q tests/unit_tests/distributed/mfsdp_v2/test_dbuffer.py19 passed, 6 skippedUV_NO_SYNC=1 CUDA_VISIBLE_DEVICES=0,1 uv run python -m torch.distributed.run --nproc-per-node 2 -m pytest -q tests/unit_tests/distributed/mfsdp_v2/test_fully_shard.py14 passedgit diff --check