Skip to content

fix(mfsdp): refresh V2 compute weights after optimizer step - #6336

Open
wujingyue wants to merge 1 commit into
NVIDIA:mainfrom
wujingyue:agent/mfsdp-v2-native-weight-sync
Open

fix(mfsdp): refresh V2 compute weights after optimizer step#6336
wujingyue wants to merge 1 commit into
NVIDIA:mainfrom
wujingyue:agent/mfsdp-v2-native-weight-sync

Conversation

@wujingyue

@wujingyue wujingyue commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refresh MFSDP V2 BF16 compute weights through FullyShardedOptimizer's native post-step copy hook.
  • Extend the MFSDP V2 optimizer integration test from three to ten steps so missing compute-weight refreshes are detected.

Root cause

#5949 moved main-weight to model-weight synchronization from pre-forward to optimizer post-step. FullyShardedOptimizer inherited the post-step extension point but left its implementation as a no-op, so optimizer weights updated while subsequent forwards continued to use stale compute weights.

The existing three-step integration test used a 1% relative tolerance. The resulting loss drift remained below that threshold, so the test passed despite the missing refresh.

Validation

  • uv run python -m torch.distributed.run --nproc_per_node=2 -m pytest -q tests/unit_tests/distributed/mfsdp_v2/test_mcore_adapter.py::TestMcoreAdapter::test_build_train_and_step
  • ruff check and black --check on edited files

Related to #5949 and #6325.

@copy-pr-bot

copy-pr-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

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
wujingyue force-pushed the agent/mfsdp-v2-native-weight-sync branch 2 times, most recently from 89e7063 to 1252bd6 Compare August 7, 2026 04:23
@wujingyue
wujingyue marked this pull request as ready for review August 7, 2026 04:26
@wujingyue
wujingyue requested review from a team as code owners August 7, 2026 04:26
@wujingyue
wujingyue requested a review from skyw August 7, 2026 04:26
@wujingyue

Copy link
Copy Markdown
Contributor Author

/ok to test 1252bd6

def _copy_main_params_to_model_params(self) -> None:
"""No-op: MFSDP v2 currently syncs compute weights in its forward pre-hook."""
"""Refresh MFSDP V2 compute weights after updating optimizer weights."""
# TODO: Reuse experimental.checkpoint.resync_compute_weights after #6024 merges.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: may be add name to the TODO.

for parameter in self.get_parameters()
if (parameter_group := get_containing_parameter_group(parameter)) is not None
}
for parameter_group in parameter_groups:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: single letter "s" difference is hard to spot and easily miss. May consider better name.

Comment thread megatron/core/optimizer/fully_sharded_optimizer.py Outdated
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Aug 7, 2026
@wujingyue
wujingyue force-pushed the agent/mfsdp-v2-native-weight-sync branch from 1252bd6 to 54d9aec Compare August 7, 2026 17:48
@wujingyue
wujingyue force-pushed the agent/mfsdp-v2-native-weight-sync branch from 54d9aec to ad73e1b Compare August 7, 2026 17:52
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: low Final Review PR is in the "final review" stage Run tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants