Repository navigation
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197384
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 4ac01b8 with merge base 2ea2e41 ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 17, 2026
Closed
[ghstack-poisoned]
This was referenced Sep 18, 2026
aorenste
added a commit
that referenced
this pull request
Sep 18, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: faf6ea3
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Sep 19, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 18dc98c
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Sep 22, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 1298f7d
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Sep 27, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 396b8c9
Pull-Request: #197384
aorenste
marked this pull request as ready for review
September 27, 2026 18:08
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Sep 30, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: e455bd0
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Oct 13, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The dynamo shards are single-GPU and multigpu-test.sh runs an explicit
allowlist that does not include test_streams.py, so the two-device test
never executes in CI. It is kept as the end-to-end case and backed by a
single-GPU test that patches current_device_index, which drives both the
trace-time resolution and the guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_uses_caller_device
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: e796aa7
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Oct 20, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The end-to-end two-device test lives in
test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu,
because that is where the multi-GPU CI job looks; the dynamo shards are
single-GPU. test_streams.py keeps a single-GPU test that patches
current_device_index, which drives both the trace-time resolution and the
guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 07442eb
Pull-Request: #197384
[ghstack-poisoned]
aorenste
added a commit
that referenced
this pull request
Oct 25, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The end-to-end two-device test lives in
test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu,
because that is where the multi-GPU CI job looks; the dynamo shards are
single-GPU. test_streams.py keeps a single-GPU test that patches
current_device_index, which drives both the trace-time resolution and the
guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 98aae3d
Pull-Request: #197384
aorenste
added a commit
that referenced
this pull request
Oct 30, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The end-to-end two-device test lives in
test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu,
because that is where the multi-GPU CI job looks; the dynamo shards are
single-GPU. test_streams.py keeps a single-GPU test that patches
current_device_index, which drives both the trace-time resolution and the
guard that checks it.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: 936f594
Pull-Request: #197384
aorenste
added a commit
that referenced
this pull request
Nov 1, 2026
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with `device.index or 0`, so compiled code
synchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`,
so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The end-to-end two-device test lives in
test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu,
because that is where the multi-GPU CI job looks; the dynamo shards are
single-GPU. test_streams.py keeps a single-GPU test that patches
current_device_index, which drives both the trace-time resolution and the
guard that checks it. Since the patched indices needn't exist on the runner, it
also patches torch.accelerator.current_stream (Dynamo reads it before tracing)
and torch.accelerator.synchronize, which it records to check the runtime
synchronized the resolved devices.
Test Plan:
```shell
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
CUDA_VISIBLE_DEVICES=0 .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device
.venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor
PATH="$PWD/.venv/bin:$PATH" lintrunner -a
```
Authored with the assistance of an AI assistant.
ghstack-source-id: fb77fcf
Pull-Request: #197384
Contributor
Author
|
@pytorchbot merge |
Collaborator
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 |
aorenste
added a commit
to aorenste/pytorch
that referenced
this pull request
Nov 3, 2026
…ch#203047) Summary: test_torch_get_device_module fails on a CUDA build with no GPU once pytorch#197384 (D128968633) lands, as in test_dynamo here and OSS periodic's nogpu_AVX512 shard. Its last step compiles `torch.get_device_module().synchronize()`, which on that build is `torch.cuda.synchronize()`. pytorch#197384 resolves an index-less synchronize's device while tracing; with no driver, `torch.accelerator.current_device_index()` raises, so Dynamo graph-breaks and runs the call eagerly, and eager raises `RuntimeError: Found no NVIDIA driver on your system`. Before, the compiled op was `torch.accelerator.synchronize`, a silent no-op on uninitialized CUDA. Raising like eager is intended, so the test was relying on that no-op. Move the synchronize step into its own test, gated on `requires_accelerator`, so the rest of test_torch_get_device_module keeps running on GPU-less machines. Decorating the whole test would also work, but would drop its get_device_module checks there. This is the forward fix for D128968633, which is rebased on top of it so both land together. Authored with the assistance of an AI assistant (Claude). Test Plan: In an OSS checkout containing pytorch#197384: ``` CUDA_VISIBLE_DEVICES= python test/dynamo/test_functions.py -k test_torch_get_device_module CUDA_VISIBLE_DEVICES=0 python test/dynamo/test_functions.py -k test_torch_get_device_module ``` With no GPU visible, test_torch_get_device_module passes and test_torch_get_device_module_synchronize is skipped ("requires accelerator"); before this change test_torch_get_device_module failed in that configuration. With a GPU, both pass. Reviewed By: jeanschmidt Differential Revision: D129106076
pytorchmergebot
pushed a commit
that referenced
this pull request
Nov 4, 2026
…) (#203047) Summary: test_torch_get_device_module fails on a CUDA build with no GPU once #197384 (D128968633) lands, as in test_dynamo here and OSS periodic's nogpu_AVX512 shard. Its last step compiles `torch.get_device_module().synchronize()`, which on that build is `torch.cuda.synchronize()`. #197384 resolves an index-less synchronize's device while tracing; with no driver, `torch.accelerator.current_device_index()` raises, so Dynamo graph-breaks and runs the call eagerly, and eager raises `RuntimeError: Found no NVIDIA driver on your system`. Before, the compiled op was `torch.accelerator.synchronize`, a silent no-op on uninitialized CUDA. Raising like eager is intended, so the test was relying on that no-op. Move the synchronize step into its own test, gated on `requires_accelerator`, so the rest of test_torch_get_device_module keeps running on GPU-less machines. Decorating the whole test would also work, but would drop its get_device_module checks there. This is the forward fix for D128968633, which is rebased on top of it so both land together. Authored with the assistance of an AI assistant (Claude). Test Plan: In an OSS checkout containing #197384: ``` CUDA_VISIBLE_DEVICES= python test/dynamo/test_functions.py -k test_torch_get_device_module CUDA_VISIBLE_DEVICES=0 python test/dynamo/test_functions.py -k test_torch_get_device_module ``` With no GPU visible, test_torch_get_device_module passes and test_torch_get_device_module_synchronize is skipped ("requires accelerator"); before this change test_torch_get_device_module failed in that configuration. With a GPU, both pass. Reviewed By: jeanschmidt Differential Revision: D129106076 Pull Request resolved: #203047 Approved by: https://github.com/bobrenjc93
dominikjastrzebskix
pushed a commit
to dominikjastrzebskix/pytorch
that referenced
this pull request
Nov 5, 2026
pytorch#197384) torch.cuda.synchronize(torch.device("cuda")) -- and the bare torch.cuda.synchronize() that builds the same device -- means "the current device". Dynamo lowered it with `device.index or 0`, so compiled code synchronized device 0 whichever device was current, while eager synchronized the caller's. Resolve the index from torch.accelerator.current_device_index() instead. It has to be resolved while tracing rather than deferred to the operator: Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`, so an index read at run time picks up the graph's device, not the caller's. Resolving at trace time makes it a constant, which then has to be guarded -- an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index(). That guard specializes every frame containing an index-less synchronize on the ambient device index: one frame per current device, so a process cycling through 8 GPUs compiles 8 frames and exactly consumes the default recompile_limit of 8, after which the frame falls back to eager. Carrying the index as a runtime value instead is what the Inductor device guard rules out, so the recompiles are the price of synchronizing the right device. Resolving needs a visible accelerator. Where there is none, graph break instead of letting the RuntimeError escape as an InternalTorchDynamoError that asks the user to file a PyTorch bug -- the call then runs eagerly and raises what eager raises. compile_on_one_rank is untouched: there the index stays None so the runtime resolves it per rank. The end-to-end two-device test lives in test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu, because that is where the multi-GPU CI job looks; the dynamo shards are single-GPU. test_streams.py keeps a single-GPU test that patches current_device_index, which drives both the trace-time resolution and the guard that checks it. Since the patched indices needn't exist on the runner, it also patches torch.accelerator.current_stream (Dynamo reads it before tracing) and torch.accelerator.synchronize, which it records to check the runtime synchronized the resolved devices. Test Plan: ```shell .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device CUDA_VISIBLE_DEVICES=0 .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device .venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor PATH="$PWD/.venv/bin:$PATH" lintrunner -a ``` Authored with the assistance of an AI assistant. Pull Request resolved: pytorch#197384 Approved by: https://github.com/bobrenjc93
dominikjastrzebskix
pushed a commit
to dominikjastrzebskix/pytorch
that referenced
this pull request
Nov 5, 2026
…ch#203047) (pytorch#203047) Summary: test_torch_get_device_module fails on a CUDA build with no GPU once pytorch#197384 (D128968633) lands, as in test_dynamo here and OSS periodic's nogpu_AVX512 shard. Its last step compiles `torch.get_device_module().synchronize()`, which on that build is `torch.cuda.synchronize()`. pytorch#197384 resolves an index-less synchronize's device while tracing; with no driver, `torch.accelerator.current_device_index()` raises, so Dynamo graph-breaks and runs the call eagerly, and eager raises `RuntimeError: Found no NVIDIA driver on your system`. Before, the compiled op was `torch.accelerator.synchronize`, a silent no-op on uninitialized CUDA. Raising like eager is intended, so the test was relying on that no-op. Move the synchronize step into its own test, gated on `requires_accelerator`, so the rest of test_torch_get_device_module keeps running on GPU-less machines. Decorating the whole test would also work, but would drop its get_device_module checks there. This is the forward fix for D128968633, which is rebased on top of it so both land together. Authored with the assistance of an AI assistant (Claude). Test Plan: In an OSS checkout containing pytorch#197384: ``` CUDA_VISIBLE_DEVICES= python test/dynamo/test_functions.py -k test_torch_get_device_module CUDA_VISIBLE_DEVICES=0 python test/dynamo/test_functions.py -k test_torch_get_device_module ``` With no GPU visible, test_torch_get_device_module passes and test_torch_get_device_module_synchronize is skipped ("requires accelerator"); before this change test_torch_get_device_module failed in that configuration. With a GPU, both pass. Reviewed By: jeanschmidt Differential Revision: D129106076 Pull Request resolved: pytorch#203047 Approved by: https://github.com/bobrenjc93
dominikjastrzebskix
pushed a commit
to dominikjastrzebskix/pytorch
that referenced
this pull request
Nov 9, 2026
pytorch#197384) torch.cuda.synchronize(torch.device("cuda")) -- and the bare torch.cuda.synchronize() that builds the same device -- means "the current device". Dynamo lowered it with `device.index or 0`, so compiled code synchronized device 0 whichever device was current, while eager synchronized the caller's. Resolve the index from torch.accelerator.current_device_index() instead. It has to be resolved while tracing rather than deferred to the operator: Inductor wraps the call in `with torch.cuda._DeviceGuard(<graph device>):`, so an index read at run time picks up the graph's device, not the caller's. Resolving at trace time makes it a constant, which then has to be guarded -- an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index(). That guard specializes every frame containing an index-less synchronize on the ambient device index: one frame per current device, so a process cycling through 8 GPUs compiles 8 frames and exactly consumes the default recompile_limit of 8, after which the frame falls back to eager. Carrying the index as a runtime value instead is what the Inductor device guard rules out, so the recompiles are the price of synchronizing the right device. Resolving needs a visible accelerator. Where there is none, graph break instead of letting the RuntimeError escape as an InternalTorchDynamoError that asks the user to file a PyTorch bug -- the call then runs eagerly and raises what eager raises. compile_on_one_rank is untouched: there the index stays None so the runtime resolves it per rank. The end-to-end two-device test lives in test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu, because that is where the multi-GPU CI job looks; the dynamo shards are single-GPU. test_streams.py keeps a single-GPU test that patches current_device_index, which drives both the trace-time resolution and the guard that checks it. Since the patched indices needn't exist on the runner, it also patches torch.accelerator.current_stream (Dynamo reads it before tracing) and torch.accelerator.synchronize, which it records to check the runtime synchronized the resolved devices. Test Plan: ```shell .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device CUDA_VISIBLE_DEVICES=0 .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device .venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor PATH="$PWD/.venv/bin:$PATH" lintrunner -a ``` Authored with the assistance of an AI assistant. Pull Request resolved: pytorch#197384 Approved by: https://github.com/bobrenjc93
dominikjastrzebskix
pushed a commit
to dominikjastrzebskix/pytorch
that referenced
this pull request
Nov 9, 2026
…ch#203047) (pytorch#203047) Summary: test_torch_get_device_module fails on a CUDA build with no GPU once pytorch#197384 (D128968633) lands, as in test_dynamo here and OSS periodic's nogpu_AVX512 shard. Its last step compiles `torch.get_device_module().synchronize()`, which on that build is `torch.cuda.synchronize()`. pytorch#197384 resolves an index-less synchronize's device while tracing; with no driver, `torch.accelerator.current_device_index()` raises, so Dynamo graph-breaks and runs the call eagerly, and eager raises `RuntimeError: Found no NVIDIA driver on your system`. Before, the compiled op was `torch.accelerator.synchronize`, a silent no-op on uninitialized CUDA. Raising like eager is intended, so the test was relying on that no-op. Move the synchronize step into its own test, gated on `requires_accelerator`, so the rest of test_torch_get_device_module keeps running on GPU-less machines. Decorating the whole test would also work, but would drop its get_device_module checks there. This is the forward fix for D128968633, which is rebased on top of it so both land together. Authored with the assistance of an AI assistant (Claude). Test Plan: In an OSS checkout containing pytorch#197384: ``` CUDA_VISIBLE_DEVICES= python test/dynamo/test_functions.py -k test_torch_get_device_module CUDA_VISIBLE_DEVICES=0 python test/dynamo/test_functions.py -k test_torch_get_device_module ``` With no GPU visible, test_torch_get_device_module passes and test_torch_get_device_module_synchronize is skipped ("requires accelerator"); before this change test_torch_get_device_module failed in that configuration. With a GPU, both pass. Reviewed By: jeanschmidt Differential Revision: D129106076 Pull Request resolved: pytorch#203047 Approved by: https://github.com/bobrenjc93
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
torch.cuda.synchronize(torch.device("cuda")) -- and the bare
torch.cuda.synchronize() that builds the same device -- means "the current
device". Dynamo lowered it with
device.index or 0, so compiled codesynchronized device 0 whichever device was current, while eager synchronized
the caller's. Resolve the index from
torch.accelerator.current_device_index() instead.
It has to be resolved while tracing rather than deferred to the operator:
Inductor wraps the call in
with torch.cuda._DeviceGuard(<graph device>):,so an index read at run time picks up the graph's device, not the caller's.
Resolving at trace time makes it a constant, which then has to be guarded --
an ID_MATCH on torch plus an EQUALS_MATCH on current_device_index().
That guard specializes every frame containing an index-less synchronize on
the ambient device index: one frame per current device, so a process cycling
through 8 GPUs compiles 8 frames and exactly consumes the default
recompile_limit of 8, after which the frame falls back to eager. Carrying
the index as a runtime value instead is what the Inductor device guard
rules out, so the recompiles are the price of synchronizing the right
device.
Resolving needs a visible accelerator. Where there is none, graph break
instead of letting the RuntimeError escape as an InternalTorchDynamoError
that asks the user to file a PyTorch bug -- the call then runs eagerly and
raises what eager raises.
compile_on_one_rank is untouched: there the index stays None so the runtime
resolves it per rank.
The end-to-end two-device test lives in
test/distributed/tensor/test_compile_on_one_rank.py under requires_multigpu,
because that is where the multi-GPU CI job looks; the dynamo shards are
single-GPU. test_streams.py keeps a single-GPU test that patches
current_device_index, which drives both the trace-time resolution and the
guard that checks it. Since the patched indices needn't exist on the runner, it
also patches torch.accelerator.current_stream (Dynamo reads it before tracing)
and torch.accelerator.synchronize, which it records to check the runtime
synchronized the resolved devices.
Test Plan:
.venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device CUDA_VISIBLE_DEVICES=0 .venv/bin/python test/dynamo/test_streams.py TestStreamsCUDASpecific.test_synchronize_indexless_device_resolves_current_device .venv/bin/python test/distributed/tensor/test_compile_on_one_rank.py -k test_synchronize_indexless_device_uses_caller_device_without_coor PATH="$PWD/.venv/bin:$PATH" lintrunner -aAuthored with the assistance of an AI assistant.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98