Repository navigation
[Testcase Refactoring] Bind ShardedTensor test ranks for runtime accelerator backends - #190528
shichuanliujie9527 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190528
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit fa30eb3 with merge base b7930e4 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@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 |
|
Please hold the merge for a small follow-up. The generic backend check also changes the existing HPU/HCCL behavior, so I am adding an explicit HPU guard and will update this PR shortly. |
Merge failedReason: GraphQL query Details for Dev Infra teamRaised by workflow job |
|
|
|
@fffrog Could you please review the latest follow-up when convenient? It preserves the existing HPU/HCCL behavior. The ciflow/trunk workflow is also awaiting maintainer approval. Thanks! |
|
@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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchbot label "module: tests/distributed" |
|
@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 |
Merge failedReason: 3 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
…tic backend resolution Add a property to that resolves the default distributed backend from the test variant's using . This allows and to dynamically resolve the correct backend per device variant (CUDA/nccl, NPU/hccl, XPU/xccl, etc.) instead of hardcoding 'nccl'. Changes: - Add property - Change , , default from 'nccl' to None - When backend=None, resolve from at runtime - with_comms admission check uses 'gloo' check instead of hardcoded list Depends on pytorch#187650 (skip_if_lt_x_gpu hardware-agnostic) and pytorch#190528 (init_pg dynamic device setup).
…tic backend resolution Add a property to that resolves the default distributed backend from the test variant's using . This allows and to dynamically resolve the correct backend per device variant (CUDA/nccl, NPU/hccl, XPU/xccl, etc.) instead of hardcoding 'nccl'. Changes: - Add property - Change , , default from 'nccl' to None - When backend=None, resolve from at runtime - with_comms admission check uses 'gloo' check instead of hardcoded list Depends on pytorch#187650 (skip_if_lt_x_gpu hardware-agnostic) and pytorch#190528 (init_pg dynamic device setup).
…tic backend resolution Add a property to that resolves the default distributed backend from the test variant's using . This allows and to dynamically resolve the correct backend per device variant (CUDA/nccl, NPU/hccl, XPU/xccl, etc.) instead of hardcoding 'nccl'. Changes: - Add property - Change , , default from 'nccl' to None - When backend=None, resolve from at runtime - with_comms admission check uses 'gloo' check instead of hardcoded list Depends on pytorch#187650 (skip_if_lt_x_gpu hardware-agnostic) and pytorch#190528 (init_pg dynamic device setup).
…tic backend resolution Add a property to that resolves the default distributed backend from the test variant's using . This allows and to dynamically resolve the correct backend per device variant (CUDA/nccl, NPU/hccl, XPU/xccl, etc.) instead of hardcoding 'nccl'. Changes: - Add property - Change , , default from 'nccl' to None - When backend=None, resolve from at runtime - with_comms admission check uses 'gloo' check instead of hardcoded list Depends on pytorch#187650 (skip_if_lt_x_gpu hardware-agnostic) and pytorch#190528 (init_pg dynamic device setup).
…tic backend resolution Add a property to that resolves the default distributed backend from the test variant's using . This allows and to dynamically resolve the correct backend per device variant (CUDA/nccl, NPU/hccl, XPU/xccl, etc.) instead of hardcoding 'nccl'. Changes: - Add property - Change , , default from 'nccl' to None - When backend=None, resolve from at runtime - with_comms admission check uses 'gloo' check instead of hardcoded list Depends on pytorch#187650 (skip_if_lt_x_gpu hardware-agnostic) and pytorch#190528 (init_pg dynamic device setup).
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
|
@d4l3k Both module reviews are approved on the current head, all 97 reported |
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
…on label Summary: - Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter - Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type - Switch backend admission to @requires_capabilities(Capability.distributed.backend) - Add hw_classification = HardwareClassification.ACCELERATOR Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080 Test Plan: - NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run - CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent) - CUDA: TODO - A100 regression run to be confirmed in PR thread
|
@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 |
…lerator backends (pytorch#190528) ## Summary Makes `ShardedTensorTestBase.init_pg` bind the per-rank device based on the accelerator actually present, instead of matching a hard-coded backend list. ## Motivation `init_pg` had two hard-coded lists that leave out-of-tree backends behind: ```python if backend not in ["nccl", "gloo", "mpi", "hccl", "xccl"]: raise RuntimeError(f"Backend {backend} not supported!") ... # set device for nccl pg for collectives if backend == "nccl" or backend == "xccl": torch.accelerator.set_device_index(self.rank) ``` The second one is the functional problem: every rank ends up on device 0 for any backend outside that pair, so collectives fail with an unhelpful error. The first rejects backends by name even when the distributed framework has them registered and available. ## Changes - The admission check asks the framework: `dist.is_backend_available(backend)`. That covers the built-in backends via their `is_*_available()` functions and third-party ones through `Backend.register_backend`, so a device that registers its own backend is accepted the same way the built-ins are — and it additionally catches "requested but not compiled into this build", which the name-only list did not. - The device binding resolves the accelerator at runtime instead of matching a backend pair: ```python if torch.accelerator.is_available() and backend != dist.Backend.GLOO: torch.accelerator.set_device_index(self.rank) ``` - `with_comms` keeps its original three-part admission check: an accelerator has to be present, the requested backend has to be that accelerator's default backend, and the device count has to cover `world_size`. Only the outer hard-coded `nccl`/`xccl`/`hccl` list is replaced by a Gloo exclusion, so an out-of-tree backend reaches the same check the built-in ones do. Every in-tree caller of this base class passes `gloo`, the default `nccl`, or `get_default_backend_for_device(device_type)`, so their skip/run outcome is unchanged — including `nccl` requested on a non-CUDA accelerator host, which still skips. Because the wrapper already establishes that relationship before `init_comms` runs, `init_pg` does not repeat the default-backend comparison. `gloo` is excluded deliberately: `Backend.default_device_backend_map` maps both `cpu` and `mps` to `gloo`, so without that guard an MPS run would take the binding path even though there is no per-rank accelerator index to set. No special case is made for any individual device. HPU registers its backend through the same third-party mechanism as any other out-of-tree device, so the generic path covers it; singling it out would reintroduce exactly the kind of hard-coding this change removes. ## Test Plan `ruff check` and `ruff format --check` pass. Verified on an out-of-tree accelerator backend (PrivateUse1, Ascend NPU, 4 devices) through the two suites that use this base class: `test_checkpoint.py` runs `Ran 8 tests ... OK` and `test_file_system_checkpoint.py` runs `Ran 9 tests ... OK`. Before this change every rank bound to device 0 and those suites failed during process group setup. CPU (gloo) runs are unaffected: `current_accelerator()` returns `None` on a CPU-only host, and where an accelerator is present but the process group is gloo, the `Backend.GLOO` guard short-circuits before the default-backend lookup and keeps the binding from firing. ## Related Part of pytorch#185590. Pull Request resolved: pytorch#190528 Approved by: https://github.com/d4l3k, https://github.com/pjyFight, https://github.com/fffrog
Summary
Makes
ShardedTensorTestBase.init_pgbind the per-rank device based on theaccelerator actually present, instead of matching a hard-coded backend list.
Motivation
init_pghad two hard-coded lists that leave out-of-tree backends behind:The second one is the functional problem: every rank ends up on device 0 for any
backend outside that pair, so collectives fail with an unhelpful error. The
first rejects backends by name even when the distributed framework has them
registered and available.
Changes
dist.is_backend_available(backend).That covers the built-in backends via their
is_*_available()functions andthird-party ones through
Backend.register_backend, so a device thatregisters its own backend is accepted the same way the built-ins are — and it
additionally catches "requested but not compiled into this build", which the
name-only list did not.
backend pair:
with_commskeeps its original three-part admission check: an accelerator hasto be present, the requested backend has to be that accelerator's default
backend, and the device count has to cover
world_size. Only the outerhard-coded
nccl/xccl/hccllist is replaced by a Gloo exclusion, so anout-of-tree backend reaches the same check the built-in ones do. Every in-tree
caller of this base class passes
gloo, the defaultnccl, orget_default_backend_for_device(device_type), so their skip/run outcome isunchanged — including
ncclrequested on a non-CUDA accelerator host, whichstill skips.
Because the wrapper already establishes that relationship before
init_commsruns,init_pgdoes not repeat the default-backend comparison.gloois excluded deliberately:Backend.default_device_backend_mapmaps bothcpuandmpstogloo, so without that guard an MPS run would take thebinding path even though there is no per-rank accelerator index to set.
No special case is made for any individual device. HPU registers its backend
through the same third-party mechanism as any other out-of-tree device, so the
generic path covers it; singling it out would reintroduce exactly the kind of
hard-coding this change removes.
Test Plan
ruff checkandruff format --checkpass.Verified on an out-of-tree accelerator backend (PrivateUse1, Ascend NPU, 4
devices) through the two suites that use this base class:
test_checkpoint.pyrunsRan 8 tests ... OKandtest_file_system_checkpoint.pyrunsRan 9 tests ... OK. Before this changeevery rank bound to device 0 and those suites failed during process group setup.
CPU (gloo) runs are unaffected:
current_accelerator()returnsNoneon aCPU-only host, and where an accelerator is present but the process group is
gloo, the
Backend.GLOOguard short-circuits before the default-backend lookupand keeps the binding from firing.
Related
Part of #185590.