Skip to content

Skip CUDA-graph config validation where graphs cannot capture - #4790

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
Johnsonms:johnson/rocm-cuda-graph-validation
Sep 18, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
Johnsonms:johnson/rocm-cuda-graph-validation

Conversation

@Johnsonms

Copy link
Copy Markdown
Contributor

Summary

CUDA graph capture cannot run on ROCm — wrap_with_cuda_graph() logs a warning
and returns the eager callable. But the validators that enforce CUDA-graph
restrictions never checked the device, so they raised ValueError on ROCm for
configurations that would run fine there. training.disable_cuda_graphs
defaults to False, so ROCm users hit this by default.

This exports the capability check as cuda_graphs_supported() and has
wrap_with_cuda_graph() and every validator share it, so the sites cannot
drift apart.

Gated sites:

File Restriction
config/validation.py varlen attention with max_num_documents unset
config/validation.py expert parallelism with a synchronizing token dispatcher
trainer.py pipeline parallelism with a validator
training_engine.py looped pipeline schedules
training_engine.py SDC replay with num_replays > 1

No behaviour change on NVIDIA. cuda_graphs_supported() is True on CUDA,
so every existing error path fires exactly as before.

This does not touch the ROCm exclusion itself. hipGraph exists and the blanket
torch.version.hip is None may be worth revisiting, but that is a separate
question — see the issue.

Tests

The existing CUDA-graph rejection tests in test_config_manager.py asserted
raises that are now device-dependent, and would silently stop asserting anything
on a CPU-only runner. They now pin the predicate to True and keep asserting
the raises; new tests cover the inert case and the previously untested varlen
path.

Verified on 8x MI350X (gfx950, torch 2.15.0.dev+rocm7.2):

  • Before: varlen without max_num_documents, EP=2 with LocalTokenDispatcher,
    and PP=2 with a looped schedule each raised ValueError at config time.
  • After: all three are accepted, and llama3_debugmodel_varlen_attn with
    max_num_documents=None trains (3 steps, loss 8.18 -> 7.20) with the expected
    "using eager execution" warning.
  • tests/unit_tests/cpu/: same 4 pre-existing failures before and after
    (missing torchvision/vllm locally), +7 new passing tests.

Fixes #4789

CUDA graph capture is unavailable on ROCm: wrap_with_cuda_graph() logs a
warning and returns the eager callable. The validators that enforce
CUDA-graph restrictions did not check the device, so they raised
ValueError on ROCm for configurations that run fine there. Since
disable_cuda_graphs defaults to False, ROCm users hit this by default.

Export the capability predicate as cuda_graphs_supported() and have
wrap_with_cuda_graph() and every validator share it, so the sites cannot
drift apart:

- config/validation.py: varlen attention without max_num_documents, and
  expert parallelism with a synchronizing token dispatcher
- trainer.py: pipeline parallelism with a validator
- training_engine.py: looped pipeline schedules, and SDC replay with
  num_replays > 1

No behaviour change on NVIDIA: cuda_graphs_supported() is True there, so
every error path fires exactly as before. The existing tests for these
raises now pin the predicate to True and keep asserting them; new tests
cover the inert case.

Fixes pytorch#4789
@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Sep 18, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 18, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/rl
  • ciflow/fake-pg

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@Johnsonms

Copy link
Copy Markdown
Contributor Author

Verified on NVIDIA B200: no behaviour change

I ran the PR head (3e8c4acee) against its base (030673f98) on an NVIDIA B200 (CC 10.0) to back the "no behaviour change on NVIDIA" claim in the description with data. Conclusion: on NVIDIA this PR is a no-op. cuda_graphs_supported() is True, CUDA graphs still capture in a real training run (no eager fallback), all five gated validators raise byte-identically before and after, and the CPU unit-test failure set is unchanged with the PR adding exactly its 7 new passing tests. The only risk this change carries is on ROCm, where it does what it says.

Evidence (environment, four checks, logs)

Environment

torchtitan from: <clone>/tt-pr/torchtitan/__init__.py   (PR head 3e8c4acee, base 030673f98)
torch: 2.15.0.dev20260918+cu130 | hip: None
cuda available: True
device: NVIDIA B200   (driver 580.159.04, CUDA_VISIBLE_DEVICES=0)

Note: torchtitan main now requires the bfx9 fp32-matmul mode on CC ≥ 10.0 (enable_fp32_matmul_emulation_with_bf16x9), which stable torch 2.14.0 does not have, so the training run needs a current nightly.

Check 1 — predicate: cuda_graphs_supported() = True → PASS

Check 2 — graphs still capture

  • wrap_with_cuda_graph(fn) is not fn → True → PASS
  • llama3_debugmodel, 1 GPU, 5 steps: training completed, log contains torchtitan.distributed.cuda_graph - INFO - Recorded CUDA graph and no using eager execution → PASS
[titan] 2026-09-18 21:14:50,818 - torchtitan.observability.metrics - INFO - step:  1  loss:  8.18896  grad_norm:  1.4145  memory:  1.09GiB(0.61%)  tps: 613  tflops: 0.04  mfu: 0.00%
[titan] 2026-09-18 21:14:50,915 - torchtitan.observability.metrics - INFO - step:  2  loss:  7.86728  grad_norm:  1.5113  memory:  1.09GiB(0.61%)  tps: 169,332  tflops: 12.12  mfu: 0.54%
[titan] 2026-09-18 21:14:51,082 - torchtitan.distributed.cuda_graph - INFO - Recorded CUDA graph
[titan] 2026-09-18 21:14:51,122 - torchtitan.observability.metrics - INFO - step:  3  loss:  7.17645  grad_norm:  1.8522  memory:  1.09GiB(0.61%)  tps: 79,444  tflops: 5.69  mfu: 0.25%
[titan] 2026-09-18 21:14:51,194 - torchtitan.observability.metrics - INFO - step:  4  loss:  6.35949  grad_norm:  2.2604  memory:  0.97GiB(0.55%)  tps: 226,410  tflops: 16.21  mfu: 0.72%
[titan] 2026-09-18 21:14:51,250 - torchtitan.observability.metrics - INFO - step:  5  loss:  5.57870  grad_norm:  2.5696  memory:  0.97GiB(0.55%)  tps: 296,715  tflops: 21.24  mfu: 0.94%
[titan] 2026-09-18 21:14:53,250 - torchtitan.trainer - INFO - Training completed

Check 3 — the five raises, base vs PR: diff of the probe output on base 030673f98 vs PR head 3e8c4acee is empty. PR output (each case hits its own validator; the three negative controls stay accepted):

must raise  | varlen, max_num_documents=None -> ValueError: CUDA graphs require fixed-shape varlen document metadata for
must raise  | EP=2, LocalTokenDispatcher     -> ValueError: CUDA graphs support only expert parallel token dispatcher co
must raise  | PP=2 + validator, 1F1B         -> ValueError: CUDA graphs with pipeline parallelism do not support validat
must raise  | PP=2, Interleaved1F1B          -> ValueError: CUDA graphs do not support looped pipeline schedules yet. Us
must raise  | SDC replay num_replays=2       -> ValueError: SDC replay supports at most one replay when CUDA graphs are 
must accept | varlen, max_num_documents=64   -> accepted
must accept | EP=2, non-blocking HybridEP    -> accepted
must accept | PP=2, 1F1B, no validator       -> accepted

Check 4 — tests/unit_tests/cpu/, base vs PR

base: 8 failed, 926 passed, 34 skipped, 13 errors, 71 subtests passed in 808.19s
PR:   8 failed, 933 passed, 34 skipped, 13 errors, 71 subtests passed in 265.86s

The 21 failing/erroring tests are the same set on base and PR (no PR-only failure), and the PR has exactly +7 passing tests. All 21 are environment-only and unrelated to CUDA graphs: missing transformers, the image's torchvision built against an older torch (torchvision::nms does not exist), a torchao release without the mxfp8 32x32 swizzle kernels, no flux config_registry in-tree, and test_no_new_cli_options.

test_config_manager.py -k "cuda_graph or sdc_replay" on the PR: 20 passed (incl. the five modified test_cuda_graphs_reject_* / test_sdc_replay_rejects_* and the six new test_cuda_graphs_unsupported_allows_*), 29 deselected, 9.02s.

Comment thread torchtitan/training_engine.py Resolved

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry, I missed the argument, now I get it.

@tianyu-l
tianyu-l merged commit ab67081 into pytorch:main Sep 18, 2026
16 checks passed
@Johnsonms
Johnsonms deleted the johnson/rocm-cuda-graph-validation branch September 18, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CUDA-graph config validation rejects valid ROCm configs, although graphs never capture on ROCm

2 participants