Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190518
Note: Links to docs will display an error until the docs builds have been completed.
|
|
@pytorchbot label "module: tests/distributed" |
a928044 to
39cba16
Compare
39cba16 to
ea2e307
Compare
The changes have been made in accordance with the suggestions. |
JamesD18
left a comment
There was a problem hiding this comment.
Thanks for the update — the earlier review comments have been properly addressed: requires_accelerator_dist_backend() has been removed and replaced with @requires_capabilities(Capability.distributed.backend) from #191919, applied to all three test methods.
hw_classification = HardwareClassification.ACCELERATOR together with instantiate_device_type_tests using except_for="cpu" is the correct classification: the tests now accept a device parameter, are gated via the framework's capability‑registration mechanism, and dynamically resolve the backend through torch.device(device).type, instead of hard‑coding "nccl"/"cuda".
There was a problem hiding this comment.
When we remove def device here, can we call self.device directly here?
| @classmethod | ||
| def backend_str(cls) -> str: | ||
| # Testing with NCCL backend | ||
| return "nccl" | ||
|
|
||
| @property | ||
| def device(self) -> torch.device: | ||
| return torch.device(device_type, self.rank) |
There was a problem hiding this comment.
Please inherit MultiProcContinuousTest to create a new base class named ComposabilityBaseTest, and add new function into this new class:
- def backend_str(device) -> return the backend
- def current_device -> return the correct device with the current rank
You can refer to C10dTorchCommsTestBase for reference
Then ComposabilityTest should inhert ComposabilityBaseTest.
That said, I think adding those two functions into MultiProcContinuousTest should be better way, but we need to evaluate the effect radius.
- all the self.device -> self.current_device
There was a problem hiding this comment.
The current change adds a new base class that overrides the backend_str class method and implements the device property. Tests pass.
An alternative approach would be to modify backend_str and add the device method directly in MultiProcContinuousTest . Tests also pass with this approach, but since many test classes inherit from MultiProcContinuousTest , the blast radius would be considerably larger.
| skip_if_lt_x_gpu, | ||
| ) | ||
| from torch.testing._internal.common_device_type import ( | ||
| Capability, |
There was a problem hiding this comment.
Do NOT use Capability here, please.
| @@ -195,9 +189,9 @@ def _build_pp_schedule( | |||
| ) | |||
| return pipeline_schedule, partial_models, offsets | |||
|
|
|||
| @requires_nccl() | |||
| @requires_capabilities(Capability.distributed.backend) | |||
There was a problem hiding this comment.
We can try to refactor this requires_accelerator_dist_backend to support new accelerator.
There was a problem hiding this comment.
I’d skip a generated device variant when its device type has no registered distributed backend.
AI-assisted verification at
457a4cef1f. The test now imports with the existing MultiProcContinuousTest and resolves XPU to XCCL. With a controlled four-device PrivateUse1 module and no default process-group backend registered for it, the test file generated 22 variants. Calling the generated class’s_ensure_processes_spawned()raisedValueError: Default backend not registered for device : privateuseonebefore any worker was spawned. The exception comes frombackend_str(device_type), before the fixture can check backend availability. Could that missing mapping produce a class skip? A registered backend should keep its current path.
ea2e307 to
1ad6226
Compare
…ynamic backend resolution Add a new CommonDistributedBackend(MultiProcessTestCase) intermediate class that provides dynamic backend resolution via dist.get_default_backend_for_device(self.device_type), following the same pattern as DTensorTestBase (PR pytorch#191288). Change with_comms default from backend='nccl' to backend=None, which resolves to self.backend at runtime. ShardedTensorTestBase is preserved unchanged — adding backend/device methods to existing intermediate classes triggers TypeError due to instantiate_device_type_tests conflicts. Test classes can use multiple inheritance to combine CommonDistributedBackend with existing intermediate classes: class TestFoo(CommonDistributedBackend, ShardedTensorTestBase): @with_comms(init_rpc=False) # backend resolved dynamically def test_foo(self, device): ... Reference: DTensorTestBase (PR pytorch#191288), PR pytorch#190518
…ynamic backend resolution Add a new CommonDistributedBackend(MultiProcessTestCase) intermediate class that provides dynamic backend resolution via dist.get_default_backend_for_device(self.device_type), following the same pattern as DTensorTestBase (PR pytorch#191288). Change with_comms default from backend='nccl' to backend=None, which resolves to self.backend at runtime. ShardedTensorTestBase is preserved unchanged — adding backend/device methods to existing intermediate classes triggers TypeError due to instantiate_device_type_tests conflicts. Test classes can use multiple inheritance to combine CommonDistributedBackend with existing intermediate classes: class TestFoo(CommonDistributedBackend, ShardedTensorTestBase): @with_comms(init_rpc=False) # backend resolved dynamically def test_foo(self, device): ... Reference: DTensorTestBase (PR pytorch#191288), PR pytorch#190518
…ynamic backend resolution Add a new CommonDistributedBackend(MultiProcessTestCase) intermediate class that provides dynamic backend resolution via dist.get_default_backend_for_device(self.device_type), following the same pattern as DTensorTestBase (PR pytorch#191288). Change with_comms default from backend='nccl' to backend=None, which resolves to self.backend at runtime. ShardedTensorTestBase is preserved unchanged — adding backend/device methods to existing intermediate classes triggers TypeError due to instantiate_device_type_tests conflicts. Test classes can use multiple inheritance to combine CommonDistributedBackend with existing intermediate classes: class TestFoo(CommonDistributedBackend, ShardedTensorTestBase): @with_comms(init_rpc=False) # backend resolved dynamically def test_foo(self, device): ... Reference: DTensorTestBase (PR pytorch#191288), PR pytorch#190518
1ad6226 to
4c0f36d
Compare
4c0f36d to
78e1f6e
Compare
|
Please resolve the conflicts @zjq-86, thanks |
…a device-type instantiation
78e1f6e to
0b3b122
Compare
…a device-type instantiation
4a48630 to
537ac85
Compare
…a device-type instantiation
457a4ce to
aa49cef
Compare
…a device-type instantiation
…a device-type instantiation
|
|
||
| instantiate_parametrized_tests(ComposabilityTest) | ||
| instantiate_device_type_tests( | ||
| ComposabilityTest, globals(), except_for="cpu", allow_xpu=True |
There was a problem hiding this comment.
Use "[cpu]" instead please, and I think It's better to have each parameter on its own line.
Summary
This PR migrates
ComposabilityTestintest/distributed/test_composability.pyto device-type instantiation pertest/REVIEW.md(#202723), making the test hardware-agnostic, and removes the file fromtools/linter/adapters/test_linter_allowlist.json.Changes
Updated
ComposabilityTestintest/distributed/test_composability.py:hw_classification = HardwareClassification.ACCELERATORand switched instantiation frominstantiate_parametrized_teststoinstantiate_device_type_tests(..., except_for="cpu", allow_xpu=True), so every test runs once per accelerator device instead of assuming CUDA.deviceparameter; tensors, pipeline stages, and meshes are built on it. The module-leveldevice_type/backendglobals and thedeviceproperty are removed.backend_strresolves the process-group backend dynamically viatorch.distributed.get_default_backend_for_device()(nccl on CUDA, hccl on NPU, xccl on XPU, ...) instead of hard-coding"nccl". A small compatibility shim keeps the override callable under framework revisions that invokebackend_str()without a device argument.test_pp_fsdp_deferred_reduction_rejects_shared_comm_ctxdrops its@requires_nccl()gate:share_comm_ctxonly rebinds FSDPModule comm contexts (no NCCL coupling) and the "Do not call share_comm_ctx" validation is generic pipeline-schedule logic, so the test belongs in the ACCELERATOR class and runs on every accelerator with >= 2 devices.setUpClassprobe that skips the device variant cleanly (instead of erroring at process-group setup) when the accelerator has no registered distributed backend:get_default_backend_for_deviceraises inside_ensure_processes_spawned()before any per-test skip can run; the probe converts that into a class-levelunittest.SkipTest. Registered backends keep their current path.test/distributed/test_composability.pyfromtools/linter/adapters/test_linter_allowlist.json.Motivation
ComposabilityTesthard-coded"nccl"as the distributed backend and used CUDA-specific gating, so on accelerators whose default backend is not NCCL (e.g., NPU uses HCCL, XPU uses XCCL) the tests were skipped or failed at process-group initialization. Followingtest/REVIEW.mdrules 1/2/4/6/7, the tests now adapt to any accelerator registered withtorch.accelerator, including PrivateUse1-based out-of-tree backends such as NPU.Test Plan
Verified on CPU and across multiple accelerator types:
Notes