Repository navigation
[BC] Make graph capture backend-agnostic with torch.accelerator - #5353
Conversation
|
|
5644661 to
d4d94c0
Compare
bab9c29 to
1bbbf76
Compare
|
@claude summarize the unique API changes in a table, from source to destination. |
|
Claude finished @SherlockNoMad's task in 58s —— View job API changes in this PR (source -> destination)The diff covers Module
Public names (renamed)
Private names (renamed)
New APIs
Signature and type changes on existing members
Torch calls replaced inside the wrapper
Unchanged (still CUDA-named)These keep their CUDA names, so the naming is now mixed:
|
| @@ -211,15 +209,81 @@ def teardown(self) -> None: | |||
| self._captured_parameter_gradients = None | |||
|
|
|||
|
|
|||
| class CUDAGraphManager: | |||
| class GraphBackend: | |||
There was a problem hiding this comment.
I'm wondering if we really need this new abstraction. What's wrong with using torch.accelerator.Graph directly? Doesn't that API already handle registration of the accelerator?
|
@wconstab torch.accelerator.Graph only works for backends that register an implementation, and currently, only xpu does. On cuda it raises "Graph is not supported on device type: CUDA". The cuda path also needs the kernel annotations that only torch.cuda.graph provides. So, the default backend uses torch.accelerator.Graph directly and only cuda overrides it. Once torch registers cuda, cuda_graph_backend.py can be removed. |
1bbbf76 to
a6f0815
Compare
fegin
left a comment
There was a problem hiding this comment.
Codex caught these configurations should also be change as well:
These still keep the CUDA wording:
- optim.enable_cuda_graph
- training.disable_cuda_graphs
- training.cuda_graph_per_microbatch_group
- profiler.maybe_cuda_graph_annotation_config
- post_validate_fsdp_for_cuda_graph
- prepare_pipeline_schedule_for_cuda_graph
- Validator._cuda_graph_enabled
fegin
left a comment
There was a problem hiding this comment.
LGTM, please
- rebase
- change the remaining cudagraph naming for consistency.
- update the PR summary
85add64 to
69c9e1f
Compare
fegin
left a comment
There was a problem hiding this comment.
Please fix the CI failures.
) ## Summary (human-written) Merge conflicts from the previous PRs cause CI failing. `disable_cuda_graph`->`disable_accelerator_graphs` ## Why CPU Unit Test fails on main: https://github.com/pytorch/torchtitan/actions/runs/40973844709/job/123796998693 #5353 renamed `training.disable_cuda_graphs` to `training.disable_accelerator_graphs`. #4920 and #5556 landed after it and still use the old name. `TestShippedCpRecipes::test_every_cp_recipe_passes_the_gate` builds `deepseek_v4_debugmodel_fsdp4_ep4` and fails: AttributeError: 'TrainingConfig' object has no attribute 'disable_cuda_graphs' `rl_grpo_deepseek_v3_debug_varlen` in `alphabet_sort.py` has the same stale keyword. No CPU test builds it, but it raises `TypeError` when run. ## What changed - Mechanical rename in two places: `tests/integration_tests/models.py` and `torchtitan_recipes/tests/rl/alphabet_sort.py`. ## Testing - `git grep disable_cuda_graphs` returns nothing. - Expect the CPU Unit Test job on this PR to pass `test_every_cp_recipe_passes_the_gate`.
) Upstream c8f0265 (pytorch#5353) made accelerator graph capture backend-agnostic via torch.accelerator. On Sunspot XPU this now captures oneCCL collectives inside the graph (was a CUDA-only no-op before). The captured region hits `ur_eventWait: wait method cannot be used for an event associated with a command graph` on every arm (agpt TP=1/TP=2 + moe for_loop tolist sync). The smoke validates numerics/sharding, not graph throughput. Disable graphs here so Sunspot VERDICT can pass; production remains graph-enabled (training.disable_accelerator_graphs=False by default). Provenance: 12481831 F Exit 1 3/3 rc143 on 7d4c8e8 — re-armed here.
- README.md hub: refresh Recently Updated table (2026-10-31 now at top). - running-with-newer-pytorch: 2.15 -> 2.16 (xpu-torch216 gate 12481837). - xpu-graphs-block-oneccl-collectives: note pytorch#5353 re-break (accelerator graphs capture oneCCL again on XPU even without CCL_OP_SYNC=1). Co-authored-by: internal-model
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
## Why
#5353 renamed `torchtitan/distributed/cuda_graph.py` and `CUDA_GRAPH.md`
to `accelerator_graph.py` and `ACCELERATOR_GRAPH.md`. #5711 fixed
`disable_cuda_graphs` call sites and left these globs.
An accelerator_graph-only PR no longer gets `ciflow/rl`, so the RL
workflows that label starts do not run, and the `cuda_graph` area no
longer requests fegin. Nothing else under `ciflow/rl` matches that diff:
not `torchtitan/rl/**`, `tests/rl/**`, `scripts/rl/**`,
`torchtitan/trainer.py`, the checkpointer, data,
`torchtitan/models/common/**`, qwen3_5, qwen3_8, or the RL workflow yaml
names.
**Example.** A PR that only edits
`torchtitan/distributed/accelerator_graph.py`:
| | Before | After |
| --- | --- | --- |
| `ciflow/rl` | not applied; RL workflows stay off | applied; RL
workflows can run |
| area reviewers | `cuda_graph` does not match, so fegin is not
requested | `cuda_graph` matches and requests fegin |
## What changed
Path metadata only. The label name `ciflow/rl`, the area name
`cuda_graph`, and reviewer `fegin` are unchanged.
- `.github/labeler.yml`: `torchtitan/distributed/cuda_graph.py` ->
`torchtitan/distributed/accelerator_graph.py`
- `.github/area_reviewers.yml`: `torchtitan/distributed/cuda_graph.py`
and `torchtitan/distributed/CUDA_GRAPH.md` ->
`torchtitan/distributed/accelerator_graph.py` and
`torchtitan/distributed/ACCELERATOR_GRAPH.md`
`torchtitan/experiments/graph_trainer/cuda_graph.py` is a different file
that still exists. The distributed area does not point at it.
## Alternatives considered
- Do not fold `accelerator_graph.py` under
`torchtitan/models/common/**`. That glob already labels model changes,
and it would not request fegin for the graph files.
## User-facing changes
None for training. CI label behavior only.
| Before | After |
| --- | --- |
| Editing `torchtitan/distributed/accelerator_graph.py` or
`ACCELERATOR_GRAPH.md` does not add `ciflow/rl` and does not request
fegin | Those edits add `ciflow/rl`, and the `cuda_graph` area requests
fegin |
## Testing
`git grep` under `.github/` shows no remaining
`torchtitan/distributed/cuda_graph.py` or
`torchtitan/distributed/CUDA_GRAPH.md`. No GPU run. No new test: this is
yaml path metadata.
This PR makes the training step graph wrapper work on any accelerator instead of only on CUDA, so backends such as XPU no longer need a near duplicate module. torchtitan/distributed/cuda_graph.py becomes the accelerator_graph package, which uses torch's device generic torch.accelerator.Graph. CUDA keeps an explicit torch.cuda.graph branch because it does not register with torch.accelerator.Graph, and that branch also keeps the profiler's kernel annotations.