Repository navigation
Conversation
Implement the multi-device detection in Engine::compute_dependencies. As the
dependency walk visits each node in the queue, look at the node's device and
skip anything that runs on the CPU ready queue. Record the first non-CPU
device seen; once a second, distinct non-CPU device shows up, fire
C10_LOG_API_USAGE_ONCE("torch.autograd.multidevice_backward").
The emission is gated by a process-wide static std::atomic<bool> flag
(relaxed ordering) so the log fires at most once per process and the per-node
check short-circuits cheaply on every subsequent backward. A CPU plus a
single accelerator still does not count, matching the intent of measuring
reliance on multithreaded autograd across multiple accelerators.
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192081
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit a8dd0af with merge base d34e364 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| bool will_use_accelerator = false; | ||
| // Log (once per process) backward passes that span multiple non-CPU | ||
| // devices, to assess reliance on multithreaded autograd before changing | ||
| // its default. CPU + a single accelerator does not count. |
There was a problem hiding this comment.
Why shouldn't CPU + single accelerator count?
There was a problem hiding this comment.
You are in fact right and I should distinguish these two cases.
Extends the logging to cover a second case: a backward pass that spans a non-CPU device together with CPU nodes now emits its own `torch.autograd.gpu_cpu_backward` marker, alongside the existing `torch.autograd.multidevice_backward` for passes spanning two distinct non-CPU devices. The two cases are independent and may both fire for the same pass. To support this, the per-node scan now also tracks whether any CPU node was seen (`saw_cpu`) in addition to the first non-CPU device. Each marker fires at most once per process, guarded by its own atomic flag. Other changes: - Switch the guard flags from load/store to `exchange`, closing the race where concurrent backward threads could both log the same marker. - Add an `inspect_devices` short-circuit computed once up front, so the per-node device inspection is skipped entirely after both markers have already fired — avoiding needless work on the common path. [ghstack-poisoned]
Add once-per-process API usage logs for backward passes, split by the set of devices they span, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and emits two independent signals that may both fire for the same pass: - torch.autograd.multidevice_backward when two distinct non-CPU devices are observed. - torch.autograd.gpu_cpu_backward when a single non-CPU device runs alongside CPU nodes. Multi-device (multiple accelerators in one backward) is the case that genuinely benefits from multithreaded autograd and is expected to be rare; the GPU + CPU case is expected to be common. Each log fires at most once per process, and the per-node device inspection is skipped entirely once both have fired. Test Plan: Built, then ran each case in a fresh process with PYTORCH_API_USAGE_STDERR=1 and grepped the emitted events: ``` a = torch.randn(4, requires_grad=True, device="cuda") b = torch.randn(4, requires_grad=True, device="cpu") (a.sum() + b.sum()).backward() a = torch.randn(4, requires_grad=True, device="cuda") (a * 2).sum().backward() a = torch.randn(4, requires_grad=True, device="cpu") (a * 2).sum().backward() ``` The GPU + CPU, single-accelerator, and CPU-only cases behaved as described. The multi-device path was not exercised at runtime (the test host has a single GPU); its logic mirrors the GPU + CPU path and was verified by inspection. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 1db815b Pull-Request: #192081
Add a once-per-process API usage log for backward passes that span more than one non-CPU device, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and fires only when it observes two distinct non-CPU devices; a CPU plus a single accelerator does not count. Test Plan: Built and confirmed the log fires under a multi-device backward and stays silent for single-device backward. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 72cfa0a Pull-Request: #192081
Add a once-per-process API usage log for backward passes that span more than one non-CPU device, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and fires only when it observes two distinct non-CPU devices; a CPU plus a single accelerator does not count. Test Plan: Built and confirmed the log fires under a multi-device backward and stays silent for single-device backward. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 72cfa0a Pull-Request: #192081
Add a once-per-process API usage log for backward passes that span more than one non-CPU device, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and fires only when it observes two distinct non-CPU devices; a CPU plus a single accelerator does not count. Test Plan: Built and confirmed the log fires under a multi-device backward and stays silent for single-device backward. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 72cfa0a Pull-Request: #192081
Add a once-per-process API usage log for backward passes that span more than one non-CPU device, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and fires only when it observes two distinct non-CPU devices; a CPU plus a single accelerator does not count. Test Plan: Built and confirmed the log fires under a multi-device backward and stays silent for single-device backward. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 72cfa0a Pull-Request: #192081
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Add once-per-process API usage logs for backward passes, split by the set of devices they span, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and emits two independent signals that may both fire for the same pass: - torch.autograd.multidevice_backward when two distinct non-CPU devices are observed. - torch.autograd.gpu_cpu_backward when a single non-CPU device runs alongside CPU nodes. Multi-device (multiple accelerators in one backward) is the case that genuinely benefits from multithreaded autograd and is expected to be rare; the GPU + CPU case is expected to be common. Each log fires at most once per process, and the per-node device inspection is skipped entirely once both have fired. Test Plan: Built, then ran each case in a fresh process with PYTORCH_API_USAGE_STDERR=1 and grepped the emitted events: ``` a = torch.randn(4, requires_grad=True, device="cuda") b = torch.randn(4, requires_grad=True, device="cpu") (a.sum() + b.sum()).backward() a = torch.randn(4, requires_grad=True, device="cuda") (a * 2).sum().backward() a = torch.randn(4, requires_grad=True, device="cpu") (a * 2).sum().backward() ``` The GPU + CPU, single-accelerator, and CPU-only cases behaved as described. The multi-device path was not exercised at runtime (the test host has a single GPU); its logic mirrors the GPU + CPU path and was verified by inspection. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> ghstack-source-id: 1db815b Pull-Request: #192081
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 1, 8, linux.rocm.gpu.gfx950.1) Details for Dev Infra teamRaised by workflow job |
mergedog handoffNote This PR is being shepherded by mergedog, an automation tool run by a maintainer. It watches CI and may push fixes; the PR author does not need to act unless a maintainer asks. All CI is green (or skipped). Ready for human review and Current PR head: Autonomous changes pushed
CI notes at handoffmergedog is treating these still-failing checks as unrelated/spurious. Please verify before merging:
Warning: mergedog's suppressed check list differs from the latest Dr. CI summary. Suppressed by mergedog but not marked unrelated by Dr. CI:
Latest Dr. CI summary## :link: Helpful Links
### :test_tube: See artifacts and rendered test results at [hud.pytorch.org/pr/192081](https://hud.pytorch.org/pr/192081)
* :page_facing_up: Preview [Python docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/192081/index.html)
* :page_facing_up: Preview [C++ docs built from this PR](https://docs-preview.pytorch.org/pytorch/pytorch/192081/cppdocs/index.html)
* :question: Need help or want to give feedback on the CI? Visit the [bot commands wiki](https://github.com/pytorch/pytorch/wiki/Bot-commands)
Note: Links to docs will display an error until the docs builds have been completed.
## :x: 1 New Failure, 2 Pending, 1 Unrelated Failure
As of commit a8dd0af1d1eac00099f6530c0ac2e7b3b792bafb with merge base d34e3640083f5f9bea117e37b7cfc9a49d7d943d (<sub><sub><img alt="image" width=70 src="https://img.shields.io/date/1785384900?label=&color=FFFFFF&style=flat-square"></sub></sub>):
<details open><summary><b>NEW FAILURE</b> - The following job has failed:</summary><p>
* [trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 1, 8, linux.rocm.gpu.gfx950.1)](https://hud.pytorch.org/pr/pytorch/pytorch/192081#93059516974) ([gh](https://github.com/pytorch/pytorch/actions/runs/31237333440/job/93059516974))
`test/inductor/test_max_autotune.py::TestMaxAutotune::test_max_autotune_decompose_k_dynamic_input_bwd`
<details><summary>AI verdict: <a href="https://hud.pytorch.org/pr/pytorch/pytorch/192081#93059516974"><img alt="AI verdict: not related" src="https://hud.pytorch.org/api/drci/advisorBadge?owner=pytorch&repo=pytorch&sha=a8dd0af1d1eac00099f6530c0ac2e7b3b792bafb&job=trunk+%2F+linux-jammy-rocm-py3.10-mi350+%2F+test+%28default%2C+1%2C+8%2C+linux.rocm.gpu.gfx950.1%29"></a></summary><blockquote>
The commit only adds API usage logging (`C10_LOG_API_USAGE_ONCE`) in the autograd engine's `compute_dependencies`. The failing test checks that inductor generates `extern_kernels.bmm_dtype` in compiled code — completely unrelated code path. The same test method also failed at the merge base (under a different test class variant), indicating a pre-existing issue on mi350.
<a href="https://hud.pytorch.org/pr/pytorch/pytorch/192081#93059516974">Full reasoning on HUD →</a>
</blockquote></details>
</p></details>
<details ><summary><b>BROKEN TRUNK</b> - The following job failed but were present on the merge base:</summary><p>👉 <b>Rebase onto the `viable/strict` branch to avoid these failures</b></p><p>
* [trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 4, 8, linux.rocm.gpu.gfx950.1)](https://hud.pytorch.org/pr/pytorch/pytorch/192081#93059516977) ([gh](https://github.com/pytorch/pytorch/actions/runs/31237333440/job/93059516977)) ([trunk failure](https://hud.pytorch.org/pytorch/pytorch/commit/d34e3640083f5f9bea117e37b7cfc9a49d7d943d#90780378556))
`test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined::test_max_autotune_decompose_k_dynamic_input_bwd`
</p></details>
This comment was automatically generated by Dr. CI and updates every 15 minutes.During shepherding, the configured LLM was invoked 2 times. If any CI shows red, it judged that failure unrelated to this PR's changes — please verify below before merging. Session 1 — fix-CI (2026-08-08T05:53:44+00:00)
LLM transcriptSession 2 — fix-CI (2026-08-08T05:56:37+00:00)
LLM transcript |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 1, 8, linux.rocm.gpu.gfx950.1), trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 4, 8, linux.rocm.gpu.gfx950.1) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…192081) Add once-per-process API usage logs for backward passes, split by the set of devices they span, so we can assess how much real workloads rely on multithreaded autograd before changing its default. The check walks the graph roots in compute_dependencies and emits two independent signals that may both fire for the same pass: - torch.autograd.multidevice_backward when two distinct non-CPU devices are observed. - torch.autograd.gpu_cpu_backward when a single non-CPU device runs alongside CPU nodes. Multi-device (multiple accelerators in one backward) is the case that genuinely benefits from multithreaded autograd and is expected to be rare; the GPU + CPU case is expected to be common. Each log fires at most once per process, and the per-node device inspection is skipped entirely once both have fired. Test Plan: Built, then ran each case in a fresh process with PYTORCH_API_USAGE_STDERR=1 and grepped the emitted events: ``` a = torch.randn(4, requires_grad=True, device="cuda") b = torch.randn(4, requires_grad=True, device="cpu") (a.sum() + b.sum()).backward() a = torch.randn(4, requires_grad=True, device="cuda") (a * 2).sum().backward() a = torch.randn(4, requires_grad=True, device="cpu") (a * 2).sum().backward() ``` The GPU + CPU, single-accelerator, and CPU-only cases behaved as described. The multi-device path was not exercised at runtime (the test host has a single GPU); its logic mirrors the GPU + CPU path and was verified by inspection. Authored with assistance from an AI coding assistant. Co-Authored-By: Claude Opus 4.8 <[email protected]> Pull Request resolved: pytorch#192081 Approved by: https://github.com/soulitzer
Stack from ghstack (oldest at bottom):
Add once-per-process API usage logs for backward passes, split by the set
of devices they span, so we can assess how much real workloads rely on
multithreaded autograd before changing its default. The check walks the
graph roots in compute_dependencies and emits two independent signals that
may both fire for the same pass:
are observed.
alongside CPU nodes.
Multi-device (multiple accelerators in one backward) is the case that
genuinely benefits from multithreaded autograd and is expected to be rare;
the GPU + CPU case is expected to be common. Each log fires at most once
per process, and the per-node device inspection is skipped entirely once
both have fired.
Test Plan: Built, then ran each case in a fresh process with
PYTORCH_API_USAGE_STDERR=1 and grepped the emitted events:
The GPU + CPU, single-accelerator, and CPU-only cases behaved as
described. The multi-device path was not exercised at runtime (the test
host has a single GPU); its logic mirrors the GPU + CPU path and was
verified by inspection.
Authored with assistance from an AI coding assistant.
Co-Authored-By: Claude Opus 4.8 [email protected]