Skip to content

Integrate MFSDP v2 with fine-grained 1F1B scheduling - #6692

Closed
shjwudp wants to merge 11 commits into
NVIDIA:pull-request/6484from
shjwudp:split/pr6484-fine-grained-hooks
Closed

shjwudp wants to merge 11 commits into
NVIDIA:pull-request/6484from
shjwudp:split/pr6484-fine-grained-hooks

Conversation

@shjwudp

@shjwudp shjwudp commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 2 of the MFSDP v2 combined-1F1B split. This PR contains the MCore adapter and models/common schedule integration; the generic experimental lifecycle remains in #6484.

  • infer MFSDP custom scheduling from overlap_moe_expert_parallel_comm
  • install fine-grained demand-unshard hooks with nearest-FSDP-owner tracking and idempotent setup
  • keep forward resharding explicit and let the parameter countdown finalize backward reduction
  • add MFSDP v2 no_sync() handling and wait for the final reduce-scatter before gradient consumers
  • add focused adapter tests and 20-step MFSDP-v2/DistOpt overlap parity coverage

Dependency

Depends on #6484 and is based on its verified pull-request/6484 mirror. Retarget this PR to main before merging; merging while based on the mirror would land into the bot scratch branch instead of main.

Validation

  • Black 26.3.0: passed
  • isort 5.13.2: passed
  • Ruff 0.9.10, including explicit undefined/unused-symbol checks: passed
  • git diff --check: passed
  • pre-split 20-step, 2-GPU MFSDP-v2/DistOpt parity: passed; final LM loss 4.30552197 vs. 4.30558395
  • GPU rerun on current main: pending cluster MFA availability

@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@shjwudp

shjwudp commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 33627e2

@shjwudp

shjwudp commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0a0f601

@shjwudp

shjwudp commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1fdb108

@shjwudp shjwudp changed the title Integrate MFSDP v2 with the MCore 1F1B lifecycle Integrate MFSDP v2 with fine-grained 1F1B scheduling Sep 3, 2026
@shjwudp
shjwudp changed the base branch from main to pull-request/6484 September 3, 2026 14:22
@shjwudp
shjwudp force-pushed the split/pr6484-fine-grained-hooks branch from e200680 to 51723a8 Compare September 3, 2026 14:34
@copy-pr-bot
copy-pr-bot Bot force-pushed the pull-request/6484 branch from 7dcc669 to cff249e Compare September 4, 2026 06:44
Clarify the API contract: the callback runs gradient reduction once all
trainable parameters have accumulated their gradients, not via a
module-level full-backward post hook (which can fire at the wrong time,
e.g. with TE delayed wgrad). Addresses review feedback on NVIDIA#6484.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
pre_backward() runs from the registered backward hook or the 1F1B schedule,
neither of which passes a value, so the knob is dead. Restore the
unconditional context.register_post_backward_final_callback() call.
Addresses NVIDIA#6484 review feedback.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
The range_push was moved after context=self.context during the life-cycle
refactor; it is a no-op reorder, so put it back to keep the diff focused.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
Rename _post_backward_hook_registered to _grad_reduction_callback_registered
to match the renamed register_grad_reduction_callback API, and document that
external schedulers calling unshard() directly must perform the root
all-gather-stream sync that pre_forward() normally does first.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
…rop duplicate-guard

- Keep the public method name register_post_backward_hook (the callback also
  reshards; rename to grad_reduction_callback was misleading).
- Drop the _post_backward_hook_registered state so FsdpModule can accept
  multiple hooks and let the fine-grained scheduler do its own checking.
- Comment why register_load_state_dict_pre_hook is registered unconditionally.
- Rename _lifecycle_events to _forward_backward_events.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
Wrap the unshard/reshard/gradient_reduce nvtx push/pop in a context manager
so an early return cannot skip the matching pop. forward/backward span
multiple lifecycle methods and keep their explicit push/pop.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
Drop tests that assert on private attributes/internal methods (behavior-
not-implementation): test_fully_shard_can_disable_execution_hooks,
test_register_post_backward_hook_waits_for_all_parameter_gradients, and
test_multiple_forwards_before_backwards_reset_gradient_readiness. register_hooks
and the fine-grained scheduler get their coverage in the upcoming 1F1B PRs.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
…IA#6484 lifecycle)

Port the NVIDIA#6692 fine-grained scheduler integration on top of split/pr-a-overlap
(a2ba13b), dropping the removed custom_schedule lifecycle and relying on the
NVIDIA#6484 MFSDP v2 API (register_post_backward_hook, idempotent unshard()/reshard()).

- Add fine_grained_mfsdp_scheduler.py (setup_combined_1f1b_hooks,
  submodule unshard/reshard hooks, reshard_fsdp_module) with no custom_schedule.
- Wire it in model_chunk_schedule_plan.py.
- Add end-to-end ND-parallel overlap parity test.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
@shjwudp
shjwudp force-pushed the split/pr6484-fine-grained-hooks branch from e5bdfec to 7172f5f Compare September 7, 2026 02:38
Signed-off-by: Jack Chang <jianbinc@nvidia.com>
…hedule_plan.py

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
Signed-off-by: Jack Chang <jianbinc@nvidia.com>
@shjwudp
shjwudp marked this pull request as draft September 7, 2026 12:22
@copy-pr-bot
copy-pr-bot Bot deleted the branch NVIDIA:pull-request/6484 September 7, 2026 12:54
@copy-pr-bot copy-pr-bot Bot closed this Sep 7, 2026
shjwudp added a commit to shjwudp/Megatron-LM that referenced this pull request Sep 7, 2026
…IA#6484 lifecycle)

Port the NVIDIA#6692 fine-grained scheduler integration on top of split/pr-a-overlap
(a2ba13b), dropping the removed custom_schedule lifecycle and relying on the
NVIDIA#6484 MFSDP v2 API (register_post_backward_hook, idempotent unshard()/reshard()).

- Add fine_grained_mfsdp_scheduler.py (setup_combined_1f1b_hooks,
  submodule unshard/reshard hooks, reshard_fsdp_module) with no custom_schedule.
- Wire it in model_chunk_schedule_plan.py.
- Add end-to-end ND-parallel overlap parity test.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
shjwudp added a commit to shjwudp/Megatron-LM that referenced this pull request Sep 10, 2026
…IA#6484 lifecycle)

Port the NVIDIA#6692 fine-grained scheduler integration on top of split/pr-a-overlap
(a2ba13b), dropping the removed custom_schedule lifecycle and relying on the

- Add fine_grained_mfsdp_scheduler.py (setup_combined_1f1b_hooks,
  submodule unshard/reshard hooks, reshard_fsdp_module) with no custom_schedule.
- Wire it in model_chunk_schedule_plan.py.
- Add end-to-end ND-parallel overlap parity test.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
shjwudp added a commit to shjwudp/Megatron-LM that referenced this pull request Sep 15, 2026
…IA#6484 lifecycle)

Port the NVIDIA#6692 fine-grained scheduler integration on top of split/pr-a-overlap
(a2ba13b), dropping the removed custom_schedule lifecycle and relying on the

- Add fine_grained_mfsdp_scheduler.py (setup_combined_1f1b_hooks,
  submodule unshard/reshard hooks, reshard_fsdp_module) with no custom_schedule.
- Wire it in model_chunk_schedule_plan.py.
- Add end-to-end ND-parallel overlap parity test.

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant