Fix MegatronFSDP root module hook dispatch - #5808
Merged
wujingyue merged 1 commit intoJul 15, 2026
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. |
Contributor
Author
|
/ok to test 08332c4 |
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
wujingyue
force-pushed
the
agent/fix-mfsdp-root-forward-hooks
branch
from
July 14, 2026 17:48
08332c4 to
0b5f9db
Compare
Contributor
Author
|
/ok to test 0b5f9db |
cspades
approved these changes
Jul 14, 2026
Member
There was a problem hiding this comment.
I think this is indeed a bug. #5789 (comment)
Originally I tested TorchTitan and BioNeMo (HuggingFace) models with fully_shard. I wonder if every single root module I tested never owned any direct parameters, similar to MCore models.
cc @shjwudp
deepakn94
approved these changes
Jul 14, 2026
Phlip79
approved these changes
Jul 15, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29389041233 |
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 was referenced Aug 17, 2026
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
MegatronFSDP.forwardthroughnn.Module.__call__so wrapped-module forward hooks run.optim_grads_paramssharding.Root Cause
MegatronFSDP.forwardcalledself.module.forward(...)directly, bypassing the wrapped module’s registered forward pre-hooks. For root-owned parameters, that skipped the FSDP gather hook and left the root forward reading ungathered/freed parameter storage.Fixes #5789
Validation
python -m py_compile megatron/core/distributed/fsdp/src/megatron_fsdp/megatron_fsdp.py tests/unit_tests/distributed/mfsdp_v1/test_mfsdp_fully_shard.pyuv run --no-sync python -m torch.distributed.run --nproc-per-node 2 -m pytest -q tests/unit_tests/distributed/mfsdp_v1/test_mfsdp_fully_shard.py::TestMegatronFsdpFullyShard::test_root_module_forward_uses_gathered_parameters