Skip to content

fix(cuda-graphs): MB-928 align DDP initialization with capture stream - #6021

Merged
ko3n1g merged 6 commits into
NVIDIA:mainfrom
svcnemo-autobot:fix/cuda-graph-grad-sync
Jul 28, 2026
Merged

fix(cuda-graphs): MB-928 align DDP initialization with capture stream#6021
ko3n1g merged 6 commits into
NVIDIA:mainfrom
svcnemo-autobot:fix/cuda-graph-grad-sync

Conversation

@svcnemo-autobot

@svcnemo-autobot svcnemo-autobot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Background

Full-iteration CUDA graph capture can fail when DDP-retained AccumulateGrad nodes reference a different initialization stream.

What changed

  • Use the shared capture stream only for full_iteration CUDA graphs.
  • Preserve a dedicated DDP initialization stream for none, local, and transformer_engine.
  • Cover both stream-selection paths and the retained-node regression.

Details

Both DDP construction paths select the shared stream only for full-iteration capture. Other implementations retain the side-stream behavior required by Transformer Engine FP8 gradient setup.

Tested

  • tools/autoformat.sh
  • test_dist_utils.py — 68 passed
  • Exact failing H100 CI image: test_fp8_param.py — 9 passed, 10 skipped
  • Exact failing H100 CI image: test_full_cuda_graph.py — 2 passed per rank

The separate GB200 failure was a launcher API read timeout before tests started.

Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
@svcnemo-autobot
svcnemo-autobot requested review from a team as code owners July 24, 2026 11:25
@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft July 24, 2026 11:25
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@copy-pr-bot

copy-pr-bot Bot commented Jul 24, 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.

@svcnemo-autobot

Copy link
Copy Markdown
Collaborator Author

/ok to test 9a05740

@ko3n1g
ko3n1g marked this pull request as ready for review July 24, 2026 11:44
@nemo-autobot-origin
nemo-autobot-origin Bot force-pushed the fix/cuda-graph-grad-sync branch from 81659ff to 6ec7ab0 Compare July 24, 2026 12:44
@nemo-autobot-origin
nemo-autobot-origin Bot force-pushed the fix/cuda-graph-grad-sync branch from 6ec7ab0 to 78a1b64 Compare July 24, 2026 12:47
@nemo-autobot-origin
nemo-autobot-origin Bot force-pushed the fix/cuda-graph-grad-sync branch from 78a1b64 to f311a97 Compare July 24, 2026 12:50
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Jul 27, 2026
@ko3n1g
ko3n1g enabled auto-merge July 27, 2026 19:29
Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
auto-merge was automatically disabled July 27, 2026 22:33

Head branch was pushed to by a user without write access

@svcnemo-autobot

Copy link
Copy Markdown
Collaborator Author

/ok to test af504fe

@svcnemo-autobot

Copy link
Copy Markdown
Collaborator Author

/ok to test 16e9c71

Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
@svcnemo-autobot

Copy link
Copy Markdown
Collaborator Author

/ok to test 2232cc0

ddp_stream = get_shared_capture_stream()
else:
# Preserve a dedicated initialization stream for all other implementations.
ddp_stream = torch.cuda.Stream()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it make sense to use:

  • full_iteration: the shared capture stream
  • local / transformer_engine: a dedicated side stream
  • none: the default stream

Without CUDA graphs, forward/backward normally run on the default stream. Constructing DDP on a separate stream can associate its retained AccumulateGrad nodes with that stream, while incoming gradients are produced on the default stream, resulting in Pytorch warnings like:

The AccumulateGrad node's stream does not match the stream of the node that produced the incoming gradient.

The FP8 failures seen at 5caed0b do not demonstrate that none requires a side stream. The initial TE CUDA-graph test failed during capture and leaked TE’s temporary class-level monkey-patch wrapper; the subsequent main_grad failures appear to be cascading failures from that leaked state.

@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/30348900592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low Run functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants