Skip to content

[Dev] remove dead manual_release_grads code path in 1F1B overlap schedule - #4510

Merged
ko3n1g merged 1 commit into
NVIDIA:devfrom
Wohox:denliu/remove-dead-manual-release-grads
Apr 29, 2026
Merged

[Dev] remove dead manual_release_grads code path in 1F1B overlap schedule#4510
ko3n1g merged 1 commit into
NVIDIA:devfrom
Wohox:denliu/remove-dead-manual-release-grads

Conversation

@Wohox

@Wohox Wohox commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

Removes dead code in the 1F1B overlap schedule. ScheduleNode.manual_release_grads was hardcoded to False at construction in pipeline_parallel/utils.py and never reassigned anywhere in the codebase, so both if 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 = False and self.delay_grads_release = False fields on ScheduleNode; the unreachable g.untyped_storage().resize_(0) branch in _backward.
  • models/gpt/fine_grained_callables.py: in backward_impl, the if self.delay_wgrad_compute: self.output_grads = grads; self.delay_grads_release = ... block (only consumed by the dead release path); in backward_dw, the unreachable tensor.untyped_storage().resize_(0) loop, the now-meaningless assert self.delay_grads_release, and the explicit self.output_grads = None clearing.

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 TransformerConfig field, on qwen3_moe_proxy (PP=1 EP=8, overlap_moe_expert_parallel_comm + delay_wgrad_compute enabled, 100 iters on real 8×H100, EOS):

manual_release_grads Peak max-allocated (MB)
False (status quo) 12479.13
True (release on) 12479.13

Peak allocated memory is identical to two decimals.

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact the @mcore-oncall.

Companion main PR: #4511

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

(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"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
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, the Final Review label 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 Approved label 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.com or zijiey@nvidia.com.

@copy-pr-bot

copy-pr-bot Bot commented Apr 29, 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.

`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
Wohox force-pushed the denliu/remove-dead-manual-release-grads branch from eeb40a5 to 43e037e Compare April 29, 2026 02:00
@Wohox
Wohox marked this pull request as ready for review April 29, 2026 02:06
@Wohox
Wohox requested review from a team as code owners April 29, 2026 02:06
@Wohox Wohox added dev branch Dev branch related issues and development Final Review PR is in the "final review" stage labels Apr 29, 2026
@Wohox

Wohox commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 43e037e

@yaox12
yaox12 enabled auto-merge April 29, 2026 02:11
@yaox12
yaox12 added this pull request to the merge queue Apr 29, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25090906354

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 29, 2026
@ko3n1g
ko3n1g added this pull request to the merge queue Apr 29, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25098175650

Merged via the queue into NVIDIA:dev with commit 66a2ff8 Apr 29, 2026
68 checks passed
@Wohox
Wohox deleted the denliu/remove-dead-manual-release-grads branch June 15, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: low dev branch Dev branch related issues and development Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants