Repository navigation
[Testcase Refactoring] Include a loaded PrivateUse1 backend in the fake backend's device list - #202363
[Testcase Refactoring] Include a loaded PrivateUse1 backend in the fake backend's device list#202363twthighd wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202363
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
|
@pytorchbot label "module: tests/distributed" |
a912582 to
06a12f0
Compare
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
…ice list
Summary:
- _register_fake_backend() registers the fake backend with a fixed device
list ("cpu", "cuda", "hpu", "xpu"), so a fake world cannot serve an
out-of-tree backend loaded through PrivateUse1: a device-qualified
backend query after init_process_group(backend="fake") raises
"No backend type associated with device type PrivateUse1". Build the
device list when the registrar is invoked and append the renamed
PrivateUse1 backend when its module is loaded, gated on module presence
with no hardware query.
- The registrar is invoked through lazy backend loading or the
compatibility shim in torch/testing/_internal/distributed/fake_pg.py;
the PrivateUse1 module must be loaded before registration, and loading
it later does not automatically refresh an existing fake registration.
- register_backend's precedence rules keep real backends safe: fake does
not overwrite the default device map entry of an already-registered
real backend, and a real backend registered later replaces fake in the
default device map.
This allows device-type-instantiated fake-PG tests to generate and run
out-of-tree accelerator variants instead of failing at the device-qualified
backend query, while CPU-only environments keep the original registration
behavior.
This is part of the test case refactoring initiative tracked in pytorch#185590.
06a12f0 to
ba58d8a
Compare
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
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. |
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
Summary
This PR makes the fake backend register itself for a PrivateUse1-based out-of-tree backend when that backend's module is loaded, so device-type-instantiated fake-PG tests can generate and run PrivateUse1 variants instead of failing with "No backend type associated with device type PrivateUse1".
Changes
torch/distributed/_backends/fake.py:_register_fake_backend()now builds the device list at invocation time: the built-in four ("cpu", "cuda", "hpu", "xpu") plus the renamed PrivateUse1 backend name when its module is present ontorch(anhasattrgate, no hardware query), and passes it toregister_backendinstead of the fixed list.torch.distributed.backendsentry point, or the built-in fallback) or through the compatibility shimtorch/testing/_internal/distributed/fake_pg.py. The PrivateUse1 module must be loaded before registration runs; loading it later does not automatically refresh an existing fake registration.Motivation
#194716 instantiates the fake-PG device tests with
instantiate_device_type_tests, which auto-generates a PrivateUse1 variant when a PrivateUse1 backend is available. On such hostsinit_process_group(backend="fake", device_id=<plugin device>)fails at the device-qualified backend query because fake only registered the built-in devices. The precedence rules inBackend.register_backendkeep this safe for real backends: fake does not overwrite the default device map entry of an already-registered real backend, and a real backend registered later replaces fake in the default device map. This PR only extends the device list so out-of-tree backends are covered by the same registration.Test Plan
Static:
py_compileclean; targetedlintrunnershows no new findings (the one local Pyreflymissing-attributeontorch._C._get_privateuse1_backend_nameis a local stub-generation lag — the API is declared intorch/_C/__init__.pyi.in, andtorch/_utils.pyproduces the same local finding on upstream code).Registration mechanics on a pre-move nightly CPU wheel (torch 2.16.0.dev20261029+cpu, whose
Backend.register_backend/default_device_backend_mapmatch current main), executing the shipped registrar source verbatim (AST-extracted from this PR's file) with plugin visibility simulated by a rename plus module attribute:torchattribute, so nothing is appended.Predicate on a real out-of-tree backend (8-device verify host): without the plugin the name stays at its default with no module attribute; after the plugin import the name flips and the module attribute appears; with default device-backend autoload the plugin is visible already after
import torch, i.e. before any fake registration trigger.Notes