Repository navigation
Conversation
Add a finalize_gradients step option so callers can keep FSDP accumulation open across complete pipeline schedules. Use the public FSDP finalizer. FSDP finalization reshards parameters, but the pipeline runtime kept the stage marked as unsharded. Track stages retained across calls separately and update the runtime state when reduction reshards a stage. This preserves the duplicate-unshard checks without forcing another all-gather between deferred steps. Keep the option scoped to FSDP. DDP and non-FSDP stages keep their existing reduction and scaling behavior. Test Plan: ``` python3 test/distributed/pipelining/test_schedule.py ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_outer_gradient_accumulation ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_unshard_reshard_runtime ``` ``` python3 test/distributed/test_composability.py -k test_pp_ddp ``` ``` UV_NO_CONFIG=1 lintrunner -a ``` This commit was authored with assistance from Codex. ghstack-source-id: d723137 Pull-Request: #196641
Add a finalize_gradients step option so callers can keep FSDP accumulation open across complete pipeline schedules. Use the public FSDP finalizer. FSDP finalization reshards parameters, but the pipeline runtime kept the stage marked as unsharded. Track stages retained across calls separately and update the runtime state when reduction reshards a stage. This preserves the duplicate-unshard checks without forcing another all-gather between deferred steps. Keep the option scoped to FSDP. DDP and non-FSDP stages keep their existing reduction and scaling behavior. Test Plan: ``` python3 test/distributed/pipelining/test_schedule.py ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_outer_gradient_accumulation ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_unshard_reshard_runtime ``` ``` python3 test/distributed/test_composability.py -k test_pp_ddp ``` ``` UV_NO_CONFIG=1 lintrunner -a ``` This commit was authored with assistance from Codex. ghstack-source-id: 7d78749 Pull-Request: #196641
Add a finalize_gradients step option so callers can keep FSDP accumulation open across complete pipeline schedules. Use the public FSDP finalizer. FSDP finalization reshards parameters, but the pipeline runtime kept the stage marked as unsharded. Track stages retained across calls separately and update the runtime state when reduction reshards a stage. This preserves the duplicate-unshard checks without forcing another all-gather between deferred steps. Keep the option scoped to FSDP. DDP and non-FSDP stages keep their existing reduction and scaling behavior. Test Plan: ``` python3 test/distributed/pipelining/test_schedule.py ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_outer_gradient_accumulation ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_unshard_reshard_runtime ``` ``` python3 test/distributed/test_composability.py -k test_pp_ddp ``` ``` UV_NO_CONFIG=1 lintrunner -a ``` This commit was authored with assistance from Codex. ghstack-source-id: d407cdf Pull-Request: #196641
Add a finalize_gradients step option so callers can keep FSDP accumulation open across complete pipeline schedules. Use the public FSDP finalizer. FSDP finalization reshards parameters, but the pipeline runtime kept the stage marked as unsharded. Track stages retained across calls separately and update the runtime state when reduction reshards a stage. This preserves the duplicate-unshard checks without forcing another all-gather between deferred steps. Keep the option scoped to FSDP. DDP and non-FSDP stages keep their existing reduction and scaling behavior. Test Plan: ``` python3 test/distributed/pipelining/test_schedule.py ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_outer_gradient_accumulation ``` ``` python3 test/distributed/test_composability.py -k test_pp_fsdp_unshard_reshard_runtime ``` ``` python3 test/distributed/test_composability.py -k test_pp_ddp ``` ``` UV_NO_CONFIG=1 lintrunner -a ``` This commit was authored with assistance from Codex. ghstack-source-id: d407cdf Pull-Request: #196641
| self._update_losses(self._stage, losses) | ||
|
|
||
| self._stage.perform_reduce_grad(self._n_microbatches if self.scale_grads else 1) | ||
| if self._finalize_gradients or not isinstance(self._stage.submod, FSDPModule): |
There was a problem hiding this comment.
you know this better, why we need
not isinstance(self._stage.submod, FSDPModule):
which reduce_grad path would FSDPModule take?
There was a problem hiding this comment.
Add a comment, there are still other stage, like DDP.
There was a problem hiding this comment.
approve to unblock.
as discussed offline, such case should be supported by a pluggable PP IR.
The original motivation of the PR is to support following case:
It ooms to run 1F1B with microbatch size of 32 due to staged activation memory, but it can run with microbatch size of 4. So it does 8 rounds of "outer gradient accumulation", with "inner PP 1F1B of microbatch size of 4".
The same effect can be achieved by a customized PP IR, which unrolls the "1F1B mb4 by 8 times".
sanketpurandare
left a comment
There was a problem hiding this comment.
This looks correct to me for eager stuff
|
@pytorchbot merge |
|
@pytorchmergebot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot revert -m "Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable" -c autorevert This PR is attributed to have caused regression in:
Note: This revert was accelerated by the AI advisor: AI advisor: related (confidence=0.99) Please investigate and fix the issues. |
|
Claude finished @pytorch-auto-revert[bot]'s task in 37s —— View job Revert diagnosis: legitimate
Cause.
This is a lint-only job (no test signal involved), it is 100% attributable to lines added by this PR, and the whole Fix. Either import the flag: from torch.testing._internal.common_utils import (
instantiate_parametrized_tests,
parametrize,
run_tests,
skip_but_pass_in_sandcastle_if,
TEST_WITH_ROCM,
)or, preferably, drop the manual early- from torch.testing._internal.common_utils import skipIfRocm
@skipIfRocm
@skip_if_lt_x_gpu(4)
@skip_but_pass_in_sandcastle_if(not TEST_MULTIGPU, "Test requires 4+ GPUs")
def test_pp_fsdp_outer_gradient_accumulation(self):Then re-verify with |
|
@pytorchbot successfully started a revert job. Check the current status here. |
This reverts commit affe288. Reverted #196641 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](#196641 (comment)))
|
@fegin your PR has been successfully reverted. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #4662 * #4661 * #4660 * #4659 * __->__ #4658 ---- **Conflict with #4649, need to discuss how to incorporate with #4649 **Depend on pytorch/pytorch#196640 and pytorch/pytorch#196641 - Add `parallelism.fsdp_defer_gradient_reduction` to reduce gradients after the final backward of a gradient accumulation group. - Replay the whole optimizer step during SDC checks. - Use the public FSDP and pipeline finalization APIs.
Stack from ghstack (oldest at bottom):
Add a finalize_gradients step option so callers can keep FSDP accumulation open across complete pipeline schedules.
Use the public FSDP finalizer.
FSDP finalization reshards parameters, but the pipeline runtime kept the stage marked as unsharded. Track stages retained across calls separately and update the runtime state when reduction reshards a stage. This preserves the duplicate-unshard checks without forcing another all-gather between deferred steps.
Keep the option scoped to FSDP. DDP and non-FSDP stages keep their existing reduction and scaling behavior.
Test Plan:
This commit was authored with assistance from Codex.