Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192958
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. |
c775024 to
00c8a5f
Compare
|
@pytorchbot label "module: tests/distributed" |
There was a problem hiding this comment.
devices only contains cpu, hpu, xpu and cuda. The default value of DEVICE is cuda. So we can't generalize it to other device type. It's necessary to be refactored.
| @instantiate_parametrized_tests | ||
| @skipIfHpu | ||
| class TestTraceableCollectives(MultiThreadedTestCase): | ||
| hw_classification = HardwareClassification.GENERIC |
There was a problem hiding this comment.
Accelerator is used in this test class. I think GENERIC is not appropriate.
There was a problem hiding this comment.
BACKEND is related to cuda, hpu, xpu. It can't be generalized to other device. I think it should be refactored to be device-agnostic.
00c8a5f to
1e58c38
Compare
|
Thanks for the review @wjlFlyer! All three points addressed in the latest push (1e58c38):
Stale |
| @@ -267,6 +249,8 @@ def test_find_root_pg(self): | |||
| @instantiate_parametrized_tests | |||
| @skipIfHpu | |||
| class TestTraceableCollectives(MultiThreadedTestCase): | |||
| hw_classification = HardwareClassification.ACCELERATOR | |||
There was a problem hiding this comment.
Current testclass tagged ACCELERATOR are not instantiated by instantiate_device_type_tests.
1e58c38 to
807c094
Compare
Label all 11 test classes with hw_classification, refactor module-level
DEVICE/devices/BACKEND to be device-agnostic, and instantiate
TestTraceableCollectives with instantiate_device_type_tests.
Classes labeled:
- GENERIC (7): TestExpand, TestPgTag, TestMetaCollectives, TestGradCollectives,
TestMakeFx, TestAllGatherViewOptimization, TestFunctionalAutograd.
- ACCELERATOR (4): TestTraceableCollectives, TestCollectivesWithDistributedBackend,
TestDistributedBackendCollectivesWithWorldSize4,
TestFunctionalAutogradWithDistributedBackend.
Refactored to be device-agnostic:
- Replaced DEVICE/devices if-elif chain (TEST_HPU/TEST_XPU/TEST_CUDA) with
dynamic detection via torch.accelerator.
- Replaced hardcoded BACKEND chain (NCCL/HCCL/XCCL) with
c10d.get_default_backend_for_device(DEVICE).
- Removed stale TEST_CUDA/TEST_HPU/TEST_XPU imports.
TestTraceableCollectives now uses instantiate_device_type_tests (addressing
review feedback). Replaced @instantiate_parametrized_tests +
@parametrize("device", devices) with instantiate_device_type_tests.
Removed stale parametrize/instantiate_parametrized_tests imports.
Test Plan:
- python -m py_compile test/distributed/test_functional_api.py passes.
- lintrunner test/distributed/test_functional_api.py passes (No lint issues).
- Test count unchanged: 34 def test_* methods.
|
Thanks @wjlFlyer!
Verified: py_compile PASS, lintrunner PASS, 34 test methods unchanged. |
|
Hi @wjlFlyer, all 4 review comments have been addressed in the latest push (807c094). Could you please re-review when you have a chance? Thanks! |
| allow_xpu=True, | ||
| ) | ||
| instantiate_device_type_tests( | ||
| TestTraceableCollectives, globals(), only_for=DEVICE, allow_xpu=True |
There was a problem hiding this comment.
If test class is tagged accelerator, we could only use excep_for, shouldn't use only_for.
…test_functional_api ACCELERATOR-classified tests must run across every accelerator, so instantiate them with except_for="cpu" instead of only_for=DEVICE. Applies to all four instantiate_device_type_tests calls in the file.
…tantiation (#202776) Part of #185590. This PR first added a four-line device fallback. After the review, it now changes `test/distributed/test_functional_api.py` to follow the rules in `test/REVIEW.md` (#202723). It overlaps with #192958, which has had no update since 2026-09-14. ## What changes - Every test class has one `hw_classification`. - `GENERIC`: `TestExpand`, `TestPgTag`, `TestPublicAPI`, `TestGradCollectives`, `TestMetaCollectives`, `TestMakeFx`, `TestAllGatherViewOptimization`, `TestFunctionalAutograd`. Their form does not change. - `ACCELERATOR`: `TestTraceableCollectives`, `TestCollectivesWithDistributedBackend`, `TestDistributedBackendCollectivesWithWorldSize4`, `TestFunctionalAutogradWithDistributedBackend`. - `TestTraceableCollectives` no longer uses `@parametrize("device", devices)` and `instantiate_parametrized_tests`. Each test takes the `device` that `instantiate_device_type_tests` injects, and the class is instantiated for CPU and each accelerator. The class keeps its `MultiThreadedTestCase` base. The seven copies of the device guard are now one method, `_setup_device`. - The three `DistributedTestBase` classes no longer use `only_for=DEVICE`. They use `except_for=("cpu",)`, so the set of devices does not change. - `with_comms` takes the device from the injected argument. It uses the device type, because `DeviceMesh` does not accept an index such as `"cuda:0"`. It checks the device count when the default backend of that device is not gloo. Before, it checked the global `BACKEND`. - The `DEVICE`, `devices` and `BACKEND` globals, the NOTE comment and the `TEST_CUDA`, `TEST_HPU` and `TEST_XPU` imports are removed. - `test/distributed/test_functional_api.py` is removed from `tools/linter/adapters/test_linter_allowlist.json`. ## Testing I ran the same change on a copy of the `release/pt_214` test tree of a downstream fork. I linted this `main` branch only. I did not run this branch. ``` # Lint on the changed file (Python 3.14): no messages python tools/linter/adapters/test_linter.py test/distributed/test_functional_api.py => rc 0 # The old file gives 6 hw_classification errors with the same command. # CPU variants PYTORCH_TESTING_DEVICE_ONLY_FOR=cpu python test/distributed/test_functional_api.py => 24 passed, 1 skipped (TestTraceableCollectivesCPU: 7 passed) ``` On an out-of-tree accelerator (Trainium trn2, torch-neuronx, 8 workers) the file gives 23 passed, 4 skipped and 7 failed. The 7 failures are the `TestTraceableCollectives` tests for that device. They fail with `Inconsistent device IDs found in kernel inputs: expected device 0 but found device 1`. That class runs each rank as a thread of one process, so it needs one process to use several devices. That backend supports one device for each process. This is a limit of that backend and not of the tests. I handle it in the downstream test registry. The accelerator-only classes pass on that backend. I did not run CUDA, XPU or HPU. ## Notes - The test names change, because `instantiate_device_type_tests` names the variants. For example `test_broadcast_device_cuda` becomes `test_broadcast_cuda`. - The bot reports "missing actionable issue". I have no maintainer who agreed to this change. @fffrog, please tell me which issue to link. An AI assistant (Claude Code) helped to write this change and this text. I reviewed both. Pull Request resolved: #202776 Approved by: https://github.com/fffrog, https://github.com/albanD
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
Thanks for the review and feedback. The changes in this PR have been superseded by the subsequent refactoring in #202776, which covers the To avoid overlapping changes and duplicate maintenance, I'll close this PR in favor of #202776. Thanks again for your time and review! |
Summary
test/distributed/test_functional_api.pycontains 11 test classes, 7 of which were unclassified. This PR labels all 11 classes withhw_classificationand refactors the module-levelDEVICE/devices/BACKENDglobals to be device-agnostic (addressing review feedback).Changes
1. hw_classification labels
TestExpand,TestPgTag,TestMetaCollectives,TestGradCollectives,TestMakeFx,TestAllGatherViewOptimization,TestFunctionalAutograd. These use fake process groups, meta device, orMultiThreadedTestCasewith no real accelerator dependency.TestTraceableCollectives(uses@parametrize("device", devices)with accelerator device),TestCollectivesWithDistributedBackend,TestDistributedBackendCollectivesWithWorldSize4,TestFunctionalAutogradWithDistributedBackend(useinstantiate_device_type_testswith adeviceparameter).2. Device-agnostic globals (addressing review)
Replaced the module-level
DEVICE/devices/BACKENDif-elif chains with dynamic detection:DEVICE/devices: Replacedif TEST_HPU/TEST_XPU/TEST_CUDAchain withtorch.accelerator.is_available()+torch.accelerator.current_accelerator().type, so out-of-tree backends registered under privateuse1 (e.g. NPU) are automatically included.BACKEND: Replaced hardcodedNCCL/HCCL/XCCLchain withc10d.get_default_backend_for_device(DEVICE).with_comms: Updated device-count guard fromBACKEND == NCCL or BACKEND == XCCLtoBACKEND != GLOO.TEST_CUDA/TEST_HPU/TEST_XPUimports.The
only_for=DEVICEwhitelist on the ACCELERATORinstantiate_device_type_testscalls is retained.DistributedTestBase.backend()only knows cuda/hpu/xpu and falls back to gloo for out-of-tree devices. Removingonly_forwould generate device variants thatDistributedTestBasecannot initialize correctly.No method bodies or decorators are changed. No hccl/ascend/npu references introduced.
Motivation
PR #190991 established the convention that every
TestCasesubclass must carry ahw_classificationattribute. The 7 unclassified classes in this file were invisible under hardware-classification filtering.The
DEVICE/devices/BACKENDif-elif chains only covered cuda/hpu/xpu and could not generalize to out-of-tree device types. Dynamic detection viatorch.acceleratorandget_default_backend_for_devicemakes the tests automatically include any registered accelerator (e.g. NPU via privateuse1), consistent with the device-agnostic direction.Dependencies
None.
Test Plan
python -m py_compile test/distributed/test_functional_api.pypasses.lintrunner test/distributed/test_functional_api.pypasses (No lint issues).def test_*methods.TestTraceableCollectives(ACCELERATOR) 7 passed.TestTraceableCollectives(ACCELERATOR) 14 passed (7 CPU + 7 NPU variants —devicesnow includes "npu" via dynamic detection).cc @fffrog @wjlFlyer @pjyFight @FuDdd @lyriexs666 @jishuangfeng @JamesD18 @JiasenTian