Repository navigation
[Test][XPU] Make test_converter.py device-agnostic and enable XPU - #197113
tszulist-hbn wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197113
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 1720e60 with merge base 7083f3a ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
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. |
Moves _check_equal_ts_ep_converter and _check_tensor_list_equal out of TestConverter into a _ConverterTestMixin so that a second test class can reuse them in the follow-up commit. This is pure code motion: no test is added, removed or renamed. The mixin deliberately carries no hw_classification, since that attribute is inherited and would silently label every subclass. Test Plan: Collected test IDs are bit-identical to the parent commit (48 before, 48 after, empty diff): ``` python -m pytest test/export/test_converter.py --collect-only -q ``` Full file behaves identically to the parent commit -- Ran 48 tests, OK (skipped=3, the 2 XNNPACK skips plus the CUDA-gated test on this CUDA-less machine): ``` python test/export/test_converter.py ``` ``` lintrunner test/export/test_converter.py ``` Authored with the assistance of Claude Code (Claude Opus 5). Co-Authored-By: Claude Opus 5 <[email protected]>
…ble XPU
test/export/test_converter.py carried no hw_classification at all, and 46 of
its 48 tests never touch a device: the TS2EPConverter is a graph-level
transformation whose only device-sensitive path is convert_prim_device
(torch/_export/converter.py). The two device-bound tests, test_prim_device
and its CUDA-gated near-copy test_prim_device_cuda, differed only in the
device of the input tensor; the latter was gated by a file-local
requires_cuda helper.
TestConverter is therefore tagged GENERIC and left un-parameterized, while
the two prim_device tests are merged into one device-parameterized test in a
new ACCELERATOR class, TestConverterDevice, instantiated over cpu, cuda and
xpu. The now-unused requires_cuda helper is deleted.
Two notes on the shape of the change. The other 46 tests are deliberately not
device-parameterized: they would cost 46 extra test runs per accelerator for
no additional coverage, since the converter's only device-sensitive path is
the one covered by test_prim_device. And TestConverterDevice deliberately
does not inherit TestConverter's setUp, which calls
init_torchbind_implementations(): the new test does not use torchbind, and
that initialization is exactly what makes the downstream torch-xpu-ops fork
of this file fail 46 of its 48 tests on a missing libtorchbind_test.so.
TestConverterDevice consequently also inherits the real TestCase.tearDown
rather than TestConverter's no-op override, so it is held to the standard
leak assertions; it passes under them.
This obsoletes third_party/torch-xpu-ops/test/xpu/export/test_converter_xpu.py,
a 1519-line copy of this file whose only functional difference is
device="cuda:0" -> device="xpu:0". A companion PR deletes it.
Test Plan:
Per-device test-ID accounting on an XPU machine without CUDA. 48 IDs before,
48 after; the 46 untouched IDs are bit-identical and the only delta is the
two intended renames:
```
python -m pytest test/export/test_converter.py --collect-only -q
```
- TestConverter::test_prim_device + TestConverterDeviceCPU::test_prim_device_cpu
- TestConverter::test_prim_device_cuda + TestConverterDeviceXPU::test_prim_device_xpu
On a CUDA machine the count is likewise unchanged, with the CUDA ID moving to
TestConverterDeviceCUDA. On a machine with neither accelerator the count goes
48 -> 47, because the CUDA test used to be collected-and-skipped and is now
not generated at all; no runnable coverage is lost on any device.
The full file, showing one skip turning into a passing XPU test (before:
skipped=3, the 2 XNNPACK skips plus the CUDA-gated test; after: skipped=2):
```
python test/export/test_converter.py
```
The new device-parameterized test on both locally available devices:
```
python test/export/test_converter.py -v -k prim_device
```
Both classes are classified, in both directions:
```
python test/export/test_converter.py --hw-classification GENERIC
python test/export/test_converter.py --hw-classification ACCELERATOR
```
GENERIC: total=48, passed=46, unclassified=0, mismatched=2
ACCELERATOR: total=48, passed=2, unclassified=0, mismatched=46
```
lintrunner test/export/test_converter.py
```
Authored with the assistance of Claude Code (Claude Opus 5).
Co-Authored-By: Claude Opus 5 <[email protected]>
540851e to
1720e60
Compare
|
@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 |
…torch#197113) Part of pytorch#142029. `test/export/test_converter.py` had no `hw_classification` and no device parameterization. Two of its 48 tests were device-bound: `test_prim_device` and `test_prim_device_cuda`, a CUDA-gated near-copy differing only in the device of the input tensor. What changed: - `TestConverter` is tagged `GENERIC` and stays un-parameterized. - The two `prim_device` tests are merged into one device-parameterized test in a new `ACCELERATOR` class `TestConverterDevice`, instantiated over cpu, cuda and xpu. - The file-local `requires_cuda` helper is deleted. Coverage delta: | | before | after | |---|---|---| | collected test IDs | 48 | 48 | | skipped | 3 | 2 | | `prim_device` on CPU / CUDA / XPU | 1 / 1 (skipped) / 0 | 1 / 1 / 1 | The 46 untouched test IDs are bit-identical. Those 46 are intentionally not device-parameterized: the converter's only device-sensitive path is `convert_prim_device`, covered by the one parameterized test. This obsoletes `third_party/torch-xpu-ops/test/xpu/export/test_converter_xpu.py`, a 1519-line copy whose only functional difference is `device="cuda:0"` -> `device="xpu:0"`; a companion PR deletes it. Authored with the assistance of Claude Code (Claude Opus 5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#197113 Approved by: https://github.com/pbielak, https://github.com/etaf, https://github.com/jansel Co-authored-by: Claude Opus 5 <[email protected]>
) Next PR for synchronizing upstream generalization with local files: 1) **functorch/test_eager_transforms.py** Upstream PR: pytorch/pytorch#192806 Before: 682 passed, 7 skipped, 2 xfailed After: 721 passed, 6 skipped, 2 xfailed Changes: - 11 new test cases: `TestGradTransform::test_inference_mode_*` - 4 new test cases: `TestCompileTransforms::test_compile_dynamic_grad_*` - 2 new test cases: `TestGradTransform::test_pop_dynamic_layer_stack_to_depth_*` - 2 new test cases: `TestFunctionalize::test_multioutput_view_*` - new test case: `TestGradTransform::test_linear_nd_inplace_activation` - new test case: `TestAutogradFunction::test_unwrap_dead_wrappers` - 1 less skipped: `test_unrelated_hessian` now passes on XPU - `TestGradTrackingTensorToList` is no longer device-parametrized: the local copy ran its 4 device-agnostic test cases twice (CPU and XPU), upstream marks the class `GENERIC` and runs them once - the 15 device-parametrized classes are renamed to `Test*Device` 2) **functorch/test_leaf_function.py** Upstream PR: pytorch/pytorch#193950 Before: not run After: 102 passed, 1 skipped 3) **export/test_passes.py** Upstream PR: pytorch/pytorch#196974 Before: 25 passed, 2 xfailed After: 26 passed, 4 skipped, 2 xfailed Changes: - 5 new test cases: `TestMoveToDevicePassCuda`, 4 require CUDA and are skipped, `test_move_to_device_pass_interpreter_only_graph` passes - move `test_move_device_example_inputs`, `test_move_device_submod`, `test_move_device_to` and `test_move_to_device_pass` from `TestPasses` to the new device-parametrized `TestMoveToDevicePassDevice` 4) **export/test_converter.py** Upstream PR: pytorch/pytorch#197113 Before: 46 passed, 2 skipped After: 46 passed, 2 skipped Changes: - move `test_prim_device` from `TestConverter` to the new device-parametrized `TestConverterDevice`, which runs it on both CPU and XPU. The local copy carried it as `test_prim_device_cuda` with a hardcoded `device="xpu:0"`, so a single misnamed test case becomes two properly parametrized ones
…ted devices (#190296) ## Summary Drop `only_for=("cpu", "cuda", "xpu")` from `instantiate_device_type_tests(TestConverterDevice, ...)`, so the class instantiates for every supported device type, including PrivateUse1 backends such as NPU. `allow_xpu=True` is preserved, keeping the XPU class from #197113. `test_prim_device` needs no changes for this: it creates its input on the injected `device`, and the module under test builds `torch.ones(..., device=x.device)`. ## Test plan ```bash python -m pytest test/export/test_converter.py --collect-only -q ``` CPU collect: 47 tests, including `TestConverterDeviceCPU::test_prim_device_cpu`. With a registered PrivateUse1 backend (for example NPU), `TestConverterDevicePRIVATEUSE1::test_prim_device_npu` is collected as well. Pull Request resolved: #190296 Approved by: https://github.com/lizhihai137, https://github.com/fffrog, https://github.com/KarhouTam Co-authored-by: Cursor <[email protected]>
…tel#5693) Next PR for synchronizing upstream generalization with local files: 1) **functorch/test_eager_transforms.py** Upstream PR: pytorch/pytorch#192806 Before: 682 passed, 7 skipped, 2 xfailed After: 721 passed, 6 skipped, 2 xfailed Changes: - 11 new test cases: `TestGradTransform::test_inference_mode_*` - 4 new test cases: `TestCompileTransforms::test_compile_dynamic_grad_*` - 2 new test cases: `TestGradTransform::test_pop_dynamic_layer_stack_to_depth_*` - 2 new test cases: `TestFunctionalize::test_multioutput_view_*` - new test case: `TestGradTransform::test_linear_nd_inplace_activation` - new test case: `TestAutogradFunction::test_unwrap_dead_wrappers` - 1 less skipped: `test_unrelated_hessian` now passes on XPU - `TestGradTrackingTensorToList` is no longer device-parametrized: the local copy ran its 4 device-agnostic test cases twice (CPU and XPU), upstream marks the class `GENERIC` and runs them once - the 15 device-parametrized classes are renamed to `Test*Device` 2) **functorch/test_leaf_function.py** Upstream PR: pytorch/pytorch#193950 Before: not run After: 102 passed, 1 skipped 3) **export/test_passes.py** Upstream PR: pytorch/pytorch#196974 Before: 25 passed, 2 xfailed After: 26 passed, 4 skipped, 2 xfailed Changes: - 5 new test cases: `TestMoveToDevicePassCuda`, 4 require CUDA and are skipped, `test_move_to_device_pass_interpreter_only_graph` passes - move `test_move_device_example_inputs`, `test_move_device_submod`, `test_move_device_to` and `test_move_to_device_pass` from `TestPasses` to the new device-parametrized `TestMoveToDevicePassDevice` 4) **export/test_converter.py** Upstream PR: pytorch/pytorch#197113 Before: 46 passed, 2 skipped After: 46 passed, 2 skipped Changes: - move `test_prim_device` from `TestConverter` to the new device-parametrized `TestConverterDevice`, which runs it on both CPU and XPU. The local copy carried it as `test_prim_device_cuda` with a hardcoded `device="xpu:0"`, so a single misnamed test case becomes two properly parametrized ones
…ted devices (pytorch#190296) ## Summary Drop `only_for=("cpu", "cuda", "xpu")` from `instantiate_device_type_tests(TestConverterDevice, ...)`, so the class instantiates for every supported device type, including PrivateUse1 backends such as NPU. `allow_xpu=True` is preserved, keeping the XPU class from pytorch#197113. `test_prim_device` needs no changes for this: it creates its input on the injected `device`, and the module under test builds `torch.ones(..., device=x.device)`. ## Test plan ```bash python -m pytest test/export/test_converter.py --collect-only -q ``` CPU collect: 47 tests, including `TestConverterDeviceCPU::test_prim_device_cpu`. With a registered PrivateUse1 backend (for example NPU), `TestConverterDevicePRIVATEUSE1::test_prim_device_npu` is collected as well. Pull Request resolved: pytorch#190296 Approved by: https://github.com/lizhihai137, https://github.com/fffrog, https://github.com/KarhouTam Co-authored-by: Cursor <[email protected]>
Part of #142029.
test/export/test_converter.pyhad nohw_classificationand no device parameterization. Two of its 48 tests were device-bound:test_prim_deviceandtest_prim_device_cuda, a CUDA-gated near-copy differing only in the device of the input tensor.What changed:
TestConverteris taggedGENERICand stays un-parameterized.prim_devicetests are merged into one device-parameterized test in a newACCELERATORclassTestConverterDevice, instantiated over cpu, cuda and xpu.requires_cudahelper is deleted.Coverage delta:
prim_deviceon CPU / CUDA / XPUThe 46 untouched test IDs are bit-identical. Those 46 are intentionally not device-parameterized: the converter's only device-sensitive path is
convert_prim_device, covered by the one parameterized test.This obsoletes
third_party/torch-xpu-ops/test/xpu/export/test_converter_xpu.py, a 1519-line copy whose only functional difference isdevice="cuda:0"->device="xpu:0"; a companion PR deletes it.Authored with the assistance of Claude Code (Claude Opus 5).
🤖 Generated with Claude Code