[Dev] remove dead manual_release_grads code path in 1F1B overlap schedule - #4510
Merged
Merged
Conversation
5 tasks
`ScheduleNode.manual_release_grads` was hardcoded to False at construction and never reassigned anywhere in the codebase, so the two `if self.manual_release_grads:` branches in `ScheduleNode._backward` and `TransformerLayerNode.backward_dw` were unreachable. The supporting bookkeeping — `self.delay_grads_release`, `self.output_grads`, the `assert self.delay_grads_release` in `backward_dw`, and the `if self.delay_wgrad_compute: self.output_grads = grads; ...` block in `backward_impl` — existed only to feed the unreachable branches. PyTorch's caching allocator already reclaims the dgrad tensors when the last Python reference drops at the end of `_backward` / `backward_dw`, so this whole machinery was a no-op. A/B comparison with the flag temporarily exposed as a TransformerConfig field (qwen3_moe_proxy, PP=1 EP=8, overlap_moe_expert_parallel_comm + delay_wgrad_compute, 100 iters on real 8xH100): peak max-allocated memory was identical at 12479.13 MB with the flag both ON and OFF.
Wohox
force-pushed
the
denliu/remove-dead-manual-release-grads
branch
from
April 29, 2026 02:00
eeb40a5 to
43e037e
Compare
Wohox
marked this pull request as ready for review
April 29, 2026 02:06
Contributor
Author
|
/ok to test 43e037e |
yaox12
approved these changes
Apr 29, 2026
yaox12
enabled auto-merge
April 29, 2026 02:11
yashaswikarnati
approved these changes
Apr 29, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25090906354 |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Apr 29, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25098175650 |
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.
What does this PR do ?
Removes dead code in the 1F1B overlap schedule.
ScheduleNode.manual_release_gradswas hardcoded toFalseat construction inpipeline_parallel/utils.pyand never reassigned anywhere in the codebase, so bothif self.manual_release_grads:branches were unreachable. The supporting bookkeeping (delay_grads_release,output_grads) existed only to feed those unreachable branches.Removed:
pipeline_parallel/utils.py:self.manual_release_grads = Falseandself.delay_grads_release = Falsefields onScheduleNode; the unreachableg.untyped_storage().resize_(0)branch in_backward.models/gpt/fine_grained_callables.py: inbackward_impl, theif self.delay_wgrad_compute: self.output_grads = grads; self.delay_grads_release = ...block (only consumed by the dead release path); inbackward_dw, the unreachabletensor.untyped_storage().resize_(0)loop, the now-meaninglessassert self.delay_grads_release, and the explicitself.output_grads = Noneclearing.PyTorch's caching allocator already reclaims the dgrad tensors when the last Python reference drops at the end of
_backward/backward_dw, so this whole machinery was a no-op. Same scope as #4122.Why this is safe
A/B comparison was run with the flag temporarily exposed as a
TransformerConfigfield, onqwen3_moe_proxy(PP=1 EP=8,overlap_moe_expert_parallel_comm+delay_wgrad_computeenabled, 100 iters on real 8×H100, EOS):manual_release_gradsFalse(status quo)True(release on)Peak allocated memory is identical to two decimals.
Companion main PR: #4511
Contribution process
Pre-checks
(Pure deletion of unreachable code; existing 1F1B-overlap functional tests cover the surrounding paths.)
Code review
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.
For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.