Repository navigation
Conversation
6bbbefd to
342cd1c
Compare
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195000
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@pytorchbot label "module: tests/distributed" |
There was a problem hiding this comment.
device_type in parent class MultiProcContinuousTest is classmethod, self.device_type here means it should be property. Please check this.
There was a problem hiding this comment.
After being instantiated through instantiate_device_type_tests, self.device_type here refers to an attribute within the device class (e.g., PrivateUse1TestBase)), not a class method within MultiProcContinuousTest.
|
I stacked the current #192214 head ( The common Would you prefer fixing this in #195000 by keeping CPU unindexed, for example: if self.rank < 0 or self.device_type == "cpu":
return torch.device(self.device_type)
return torch.device(self.device_type, self.rank)I validated that exact one-line candidate on the same stacked source. The NPU I have not added a local device-resolution workaround back to #192214 because |
…eTest MultiProcContinuousForInstantiateTest is a thin subclass of MultiProcContinuousTest that bridges the continuous-worker distributed test base with device-type-parameterized test classes generated by instantiate_device_type_tests. It exists so that distributed test classes can rely on the base class (instead of per-test overrides) to resolve the backend string and the per-rank torch.device, while still honoring the device_type string attribute injected by instantiate_device_type_tests.
342cd1c to
c756b16
Compare
KarhouTam
left a comment
There was a problem hiding this comment.
Since the new class inherits from MultiProcContinuousTest, which needs refactoring for OOT device compatibility, I think we should hold this PR for now.
…86:test/composability_common)
|
I’d like the new base class to keep working with the device argument that the current continuous-worker fixture passes when it starts a test.
|
|
The core problem this PR set out to solve — bridging
With that in place, the bridging half of this PR is redundant on main. Closing in favor of #205504. Thanks @jialinw77 @danieldale2026 for the |
…conflict The bot rebase onto viable/strict hit a content conflict when replaying the first PR commit over upstream changes to test_replicate_with_fsdp.py and common_distributed.py. Merging main (5cda694) resolves it as a whole-branch three-way merge: common_distributed.py only takes the upstream symm-mem ROCm arch tweak, and the MultiProcContinuousForInstantiateTest class kept from pytorch#195000 (closed without merge) stays compatible with the upstream MultiProcContinuousTest base, whose backend_str now takes the device argument per pytorch#205504.
… rationale pytorch#195000 closed in favor of pytorch#205504: main's MultiProcContinuousTest already normalizes device_type across the forms instantiate_device_type_tests injects and calls backend_str(cls, device), so the bridging subclass is redundant. Test classes now inherit the upstream base directly and override backend_str in the standardized per-class form, resolving the deterministic backend with dist.get_default_backend_for_device. The zero-caller current_device property is dropped with the subclass, leaving torch/testing/_internal/common_distributed.py identical to main.
…g torch.accelerator APIs Refactor test/distributed/_composable/test_replicate_with_fsdp.py to be device-agnostic: inject the test device via instantiate_device_type_tests, declare HardwareClassification.ACCELERATOR, and resolve the communication backend per class with the standardized backend_str(cls, device) override calling dist.get_default_backend_for_device. Test classes inherit the upstream MultiProcContinuousTest directly (the pytorch#195000 bridging subclass was dropped per its closing rationale: main already normalizes the injected device_type forms), and the file is removed from the test-linter allowlist.
…g torch.accelerator APIs Refactor test/distributed/_composable/test_replicate_with_fsdp.py to be device-agnostic: inject the test device via instantiate_device_type_tests, declare HardwareClassification.ACCELERATOR, and resolve the communication backend per class with the standardized backend_str(cls, device) override calling dist.get_default_backend_for_device. Test classes inherit the upstream MultiProcContinuousTest directly (the pytorch#195000 bridging subclass was dropped per its closing rationale: main already normalizes the injected device_type forms), and the file is removed from the test-linter allowlist.
…ic using torch.accelerator APIs Refactor test/distributed/_composable/test_replicate.py to be device-agnostic: ReplicateTest and ReplicateTestNoXPU inherit the upstream MultiProcContinuousTest directly and resolve the communication backend with the standardized per-class backend_str(cls, device) override calling dist.get_default_backend_for_device (the MultiProcContinuousForInstantiateTest bridging subclass from pytorch#195000 is dropped per its closing rationale: main already normalizes the injected device_type forms), test methods receive and use the injected device, and the file is removed from the test-linter allowlist. torch/testing/_internal/common_distributed.py stays identical to main.
…g torch.accelerator APIs Refactor test/distributed/_composable/test_replicate_with_fsdp.py to be device-agnostic: inject the test device via instantiate_device_type_tests, declare HardwareClassification.ACCELERATOR, and resolve the communication backend per class with the standardized backend_str(cls, device) override calling dist.get_default_backend_for_device. Test classes inherit the upstream MultiProcContinuousTest directly (the pytorch#195000 bridging subclass was dropped per its closing rationale: main already normalizes the injected device_type forms), and the file is removed from the test-linter allowlist.
Summary
Added a new test base class
MultiProcContinuousForInstantiateTestintorch/testing/_internal/common_distributed.py. It is a thin subclass ofMultiProcContinuousTestthat bridges the continuous-worker distributed testbase with device-type-parameterized test classes generated by
instantiate_device_type_tests(theComposabilityTestuse case), so thatdistributed tests can resolve the communication backend and the per-rank
device through the base class instead of re-implementing them per test.
Changes
New class: MultiProcContinuousForInstantiateTest (extends MultiProcContinuousTest)
backend_str()classmethodc10d.get_default_backend_for_device(cls.device_type).framework registry, keyed by the
device_typestring class attributethat
instantiate_device_type_testsinjects on the generated subclass.current_deviceproperty(device_type, rank) -> torch.devicemapping in each test class.What the class intentionally does NOT do
_init_pg: the parent's_init_pgalready performsaccelerator detection via
torch.accelerator.current_accelerator()/torch.accelerator.device_count(), per-rank device binding viatorch.accelerator.set_device_index(rank % device_count), and per-rankHCCL port segmentation (
HCCL_NPU_SOCKET_PORT_RANGE) for the NPU/hccl case.deviceattribute: tests should use either thedevicekwarg injected by
instantiate_test(string form, e.g. "npu:0") orself.current_device(torch.device form).Motivation
MultiProcContinuousTestrequires a workingbackend_str()to callc10d.init_process_groupinside_init_pg, but the parent class does notdefine
backend_str()ordevice_typeitself. Device-type test classesproduced by
instantiate_device_type_testsreceive adevice_typestringclass attribute, but no backend resolution and no device helper. Before this
change, every distributed test that wanted to be parameterized over device
types (e.g.
ComposabilityTest) had to re-implement both on its own, whichwas redundant and error-prone (a previous bug where
self.device_typeevaluated to a classmethod object rather than a string came from exactly
this gap).
Test Plan
Verified on the composability distributed test suite, e.g.:
Notes