Repository navigation
[Testcase Refactoring] Make test_bad_decomp device-agnostic via instantiate_device_type_tests - #198354
[Testcase Refactoring] Make test_bad_decomp device-agnostic via instantiate_device_type_tests#198354gavinwang269 wants to merge 1 commit into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198354
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 85f47ec with merge base f9ed292 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@pytorchbot label "module: tests/graph" |
91987b2 to
ccdd5fe
Compare
…device migrations Rebased onto latest main (scaffold + migrated debuginfo from pytorch#198361 are kept). Drops the seven methods whose device versions arrive in the parallel move pieces pytorch#198354 (test_bad_decomp), pytorch#198355 (test_joint_graph), pytorch#198356 (test_rng), pytorch#198357 (test_emulate_precision_casts), pytorch#198358 (test_bad_lowering), pytorch#198359 (test_bisect_pre_grad_graph) and pytorch#198360 (test_cudagraph_bisect_max); keeps test_pre_grad, test_crossref and test_eager_backend. Marks the remaining class GENERIC, renames test_ns to bisector_ns (a class attribute named test_* would otherwise be collected by instantiate_device_type_tests), slims tearDown and removes get_lib. Must merge LAST in the series, only after every sibling move above has landed; otherwise the deleted GPU tests lose their replacements. Also fixes the lint failures on the previous revision: removes imports that are unused at this point in the series (contextmanager, import_module, _prims_common, preserve_rng_state, module-level config) and normalizes the blank-line runs left by the method removals. These imports are intentionally not kept for the siblings; each move piece brings back exactly what it uses. Signed-off-by: gavinwang269 <[email protected]>
| "Debug info: <OpOverload(op='aten.exponential', overload='default')>" | ||
| ) | ||
| self.assertIn(expected_result, output.stdout) | ||
| @unittest.skipIf(not has_triton(), "requires Triton") |
There was a problem hiding this comment.
There should be a blank line between two functions.
There was a problem hiding this comment.
The blank line is present between the previous test last line and the @unittest.skipIf decorator, and pycodestyle --select E3 is clean on the file; I suspect the older base rendered a misleading hunk here. Just rebased onto latest main (1680a48), the region now reads self.assertTrue(...) / blank / @unittest.skipIf / def test_bad_decomp. PTAL.
There was a problem hiding this comment.
please remove @unittest.skipIf(not has_triton(), "requires Triton") here since it is a duplicate of the decorator of the class TestCompilerBisectorDevice
There was a problem hiding this comment.
Removed the duplicate method-level @unittest.skipIf(not has_triton(), "requires Triton") from test_bad_decomp; the class-level decorator on TestCompilerBisectorDevice applies the identical guard to every method. Nothing changed at runtime: on a Triton-less host the class decorator still skips, and where Triton exists the method decorator was a no-op, so no test newly runs or newly skips.
0d0e0e1 to
49c7a9e
Compare
ccf66b6 to
da85e60
Compare
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
da85e60 to
8619602
Compare
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
|
cc @jansel @eellison — rebased onto current main: #198359 landed and relocated test_bisect_pre_grad_graph, so the moved test_bad_decomp now sits right after it in the device class; content otherwise unchanged from the head @lizhihai137 approved (+66/-59, one file). @can-gaa-hou's open GENERIC question on the base class stays parked for the maintainer call. |
| out = CompilerBisector.do_bisect(test_fn) | ||
| self.assertEqual(out.backend, "aot_eager_decomp_partition_crossref") | ||
|
|
||
| def test_eager_backend(self): |
There was a problem hiding this comment.
this is also a generic test
There was a problem hiding this comment.
Agreed - the remaining members of TestCompilerBisector are generic, which is why the class now declares hw_classification = GENERIC (the same three lines byte-identical across #198354/#198355/#198360, so any merge order converges). The two incidental GPU_TYPE body edits you flagged are reverted in 76b367c so those tests stay untouched here and move in their owning PRs.
| self.assertEqual(out.bisect_number, 4) | ||
| self.assertTrue("joint_custom_post_pass" in out.debug_info) | ||
|
|
||
| def test_crossref(self): |
There was a problem hiding this comment.
this is also a generic test
There was a problem hiding this comment.
Ditto on this one: no test-body change intended here beyond moving test_bad_decomp; the generic end state rides the GENERIC declaration plus the sibling moves.
|
|
||
| inp = torch.rand([10], device=GPU_TYPE) | ||
| device_type = torch.accelerator.current_accelerator().type | ||
| inp = torch.rand([10], device=device_type) |
There was a problem hiding this comment.
#198355 has already refactor here, revert it in this pr
| foo_c = torch.compile(foo, mode="reduce-overhead") # noqa: UNSPECIFIED_BACKEND | ||
| bar_c = torch.compile(bar, mode="reduce-overhead") # noqa: UNSPECIFIED_BACKEND | ||
| x = torch.randn(10, device=GPU_TYPE) | ||
| device_type = torch.accelerator.current_accelerator().type |
There was a problem hiding this comment.
#198360 has already refactor it here, revert in this pr
8619602 to
bf0241f
Compare
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
bf0241f to
76b367c
Compare
Move `test_bad_decomp` from `TestCompilerBisector` into `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so the test is instantiated for all non-CPU accelerator devices (including out-of-tree backends) instead of being gated behind `HAS_GPU`. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+68 -60): - `test_bad_decomp` moves from `TestCompilerBisector` (class-level `@unittest.skipIf(not HAS_GPU, ...)`, no `device` parameter) into the existing `TestCompilerBisectorDevice` (`hw_classification = HardwareClassification.ACCELERATOR`, already instantiated via `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)`). - The hardcoded `device=GPU_TYPE` inside the moved method becomes the `device` argument injected by instantiation. - The Triton requirement for the moved test is carried by the class-level `@unittest.skipIf(not has_triton(), "requires Triton")` decorator of `TestCompilerBisectorDevice`; the duplicate method-level copy of that decorator was removed. A fully device-aware gate needs a Triton `Capability` in the registry, left for a follow-up. - The method body is otherwise unchanged, byte for byte. - In the legacy `TestCompilerBisector` base class (which this series retires once all methods have moved): it now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR`, the remaining `device=GPU_TYPE` selections become a runtime `torch.accelerator.current_accelerator().type` evaluated inside each test body (no import-time probe), and the `GPU_TYPE` import is gone. The base class keeps its import-time `HAS_GPU` gate, noted in a comment. The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU`, defined as `HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`. Out-of-tree accelerators registered via `PrivateUse1` are not in this list, so the whole test class gets skipped even though the test only needs a generic accelerator with Triton support. Using `instantiate_device_type_tests` with `except_for="cpu"` runs the test on all non-CPU device types registered in the test framework, including out-of-tree backends, and `hw_classification` provides metadata for `--hw-classification` filtering. - MTIA coverage note: `HAS_GPU` could previously resolve to MTIA; MTIA CI does not collect this file today, and instantiation would not add an MTIA variant without a corresponding test base. Coverage note, not a regression on currently-tested devices. The base-class `current_accelerator()` form resolves to the same device that `GPU_TYPE` selected on CUDA, ROCm, and MTIA hosts. - CUDA and XPU keep the same effective guard set they had before the move (accelerator instantiation plus the Triton skip). Test Plan CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`, run from outside the source tree): 11 tests collected; the moved test now appears as `test_bad_decomp_npu` only for accelerator devices. Re-measured after the follow-up edits: still 11 collected. NPU (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `python -m pytest test/dynamo/test_compiler_bisector.py -k test_bad_decomp_npu -v` -> 1 passed (28s over three consecutive runs with the follow-up edits); previously this test never executed on NPU. Lint: `lintrunner test/dynamo/test_compiler_bisector.py` -> ok No lint issues.
76b367c to
85f47ec
Compare
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
|
@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 |
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
Move `test_joint_graph` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). `test/dynamo/test_compiler_bisector.py` (+39 -38): - `test_joint_graph` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. - Drop the now-redundant in-method `from torch._inductor import config` (the module is imported at file scope). - Update the `CustomPostPass.uuid()` string to name `TestCompilerBisectorDevice` after the move (keeps the pass identity meaningful and unique). - The method-level `@unittest.skipIf(not has_triton(), ...)` on the moved test was removed as a duplicate of the class-level decorator of `TestCompilerBisectorDevice`. - The legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge. The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering. Test Plan - CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`): 11 tests collected on the rebased branch; the moved test now instantiates only for accelerator devices. Re-measured after the follow-up edits: still 11. - NPU real hardware (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): `pytest -k test_joint_graph_npu` -> 1 passed (32.2s, re-measured after this round's edits); previously this test never executed on NPU. - `lintrunner` (includes in-tree TEST_LINTER): no issues, re-run after this round's edits.
…ssified class Summary test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the accelerator-wide TestCompilerBisector class. This moves it into a class of its own, classified for CUDA and instantiated through instantiate_device_type_tests. With the move (and pytorch#198354/pytorch#198355 having landed), TestCompilerBisector holds only device-agnostic tests, so it gains the GENERIC classification and drops the import-time HAS_GPU gate along with the now-unused GPU_TYPE/HAS_GPU and requires_cuda imports; @requires_cuda is not kept on the CUDA class because the only_for="cuda" instantiation already answers it. The dead get_lib()/test_ns scaffolding cleanup that an earlier revision of this PR carried was dropped to keep the diff to the move itself. Test Plan - cpu-wheel venv (no GPU here): pytest --collect-only reports the same 10 test IDs before and after; the CUDA leg runs on the hardware shards. - lintrunner and the in-tree test linter clean on the file.
…ntiate_device_type_tests (pytorch#198354) ## Summary Move `test_bad_decomp` from `TestCompilerBisector` into `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so the test is instantiated for all non-CPU accelerator devices (including out-of-tree backends) instead of being gated behind `HAS_GPU`. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). ## Changes `test/dynamo/test_compiler_bisector.py` (+58 -56): - `test_bad_decomp` moves from `TestCompilerBisector` (class-level `@unittest.skipIf(not HAS_GPU, ...)`, no `device` parameter) into the existing `TestCompilerBisectorDevice` (`hw_classification = HardwareClassification.ACCELERATOR`, already instantiated via `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)`). - The hardcoded `device=GPU_TYPE` inside the moved method becomes the `device` argument injected by instantiation. - The Triton requirement for the moved test is carried by the class-level `@unittest.skipIf(not has_triton(), "requires Triton")` decorator of `TestCompilerBisectorDevice`; the duplicate method-level copy of that decorator was removed. A fully device-aware gate needs a Triton `Capability` in the registry, left for a follow-up. - The method body is otherwise unchanged, byte for byte. - The legacy `TestCompilerBisector` base class is untouched: the hw_classification declaration this PR previously added was dropped per review -- pytorch#198360 is the single PR that adds the GENERIC label to it. ## Motivation The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU`, defined as `HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`. Out-of-tree accelerators registered via `PrivateUse1` are not in this list, so the whole test class gets skipped even though the test only needs a generic accelerator with Triton support. Using `instantiate_device_type_tests` with `except_for="cpu"` runs the test on all non-CPU device types registered in the test framework, including out-of-tree backends, and `hw_classification` provides metadata for `--hw-classification` filtering. ## Notes - MTIA coverage note: `HAS_GPU` could previously resolve to MTIA; MTIA CI does not collect this file today, and instantiation would not add an MTIA variant without a corresponding test base. Coverage note, not a regression on currently-tested devices. - CUDA and XPU keep the same effective guard set they had before the move (accelerator instantiation plus the Triton skip). ## Test Plan CPU (`env-pytorch-2.16-20261029-cpu` venv, `pytest --collect-only`, run from outside the source tree): 11 tests collected; the moved test now appears as `test_bad_decomp_npu` only for accelerator devices. Re-measured after the follow-up edits: still 11 collected. NPU (Ascend 910B4, CANN 9.2.0 GA, `env-pytorch-2.16-20261029-npu` venv with torch_npu 737bb43 + triton-ascend 3.6.0): ```bash python -m pytest test/dynamo/test_compiler_bisector.py -k test_bad_decomp_npu -v # 1 passed (28s over three consecutive runs with the follow-up edits); previously this test never executed on NPU ``` ```bash lintrunner test/dynamo/test_compiler_bisector.py # ok No lint issues ``` Pull Request resolved: pytorch#198354 Approved by: https://github.com/lizhihai137, https://github.com/jansel
…ssified class Summary test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the accelerator-wide TestCompilerBisector class. This moves it into a class of its own, classified for CUDA and instantiated through instantiate_device_type_tests. With the move (and pytorch#198354/pytorch#198355 having landed), TestCompilerBisector holds only device-agnostic tests, so it gains the GENERIC classification and drops the import-time HAS_GPU gate along with the now-unused GPU_TYPE/HAS_GPU and requires_cuda imports; @requires_cuda is not kept on the CUDA class because the only_for="cuda" instantiation already answers it. The dead get_lib()/test_ns scaffolding cleanup that an earlier revision of this PR carried was dropped to keep the diff to the move itself. Test Plan - cpu-wheel venv (no GPU here): pytest --collect-only reports the same 10 test IDs before and after; the CUDA leg runs on the hardware shards. - lintrunner and the in-tree test linter clean on the file.
…ssified class Summary test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the accelerator-wide TestCompilerBisector class. This moves it into a class of its own, classified for CUDA and instantiated through instantiate_device_type_tests. With the move (and pytorch#198354/pytorch#198355 having landed), TestCompilerBisector holds only device-agnostic tests, so it gains the GENERIC classification and drops the import-time HAS_GPU gate along with the now-unused GPU_TYPE/HAS_GPU and requires_cuda imports; the Triton gates that remain become accelerator-aware @skipIf(..., device_type=...) forms, and as the last PR touching this file the test-linter allowlist entry is removed. Review-round decisions on pytorch#198360. The automated review noted that test_rng, after losing @skipPRIVATEUSE1, now runs and fails on PrivateUse1/HPU and asked to restore a skip via a setUp gate; the human maintainer instructed the opposite on the same lines (discussion_r4533004167): expose the test to all out-of-tree accelerators and let a backend that does not support it skip it in its own instantiation rather than have upstream silently skip it. The maintainer instruction wins: no upstream gate is added for other backends, and the stale comment block claiming PrivateUse1 is "skipped explicitly" is removed with nothing replacing it, so no comment asserts a skip that does not happen. The measured consequence, stated plainly: on an Ascend 910B4 (torch_npu, triton-ascend installed) test_rng_npu now runs and fails because preserve_rng_state (torch/_dynamo/utils.py) saves/restores only CPU, CUDA and XPU RNG, so the eager and compiled draws diverge and do_bisect reports backend="eager". Coverage delta is skip -> fail on backends that do not preserve RNG state; the out-of-tree test suite is expected to opt out. Style: the Triton gate on test_cudagraph_bisect_max drops the "xpu" entry per the maintainer's suggestion (the class is instantiated only_for="cuda", so the entry can never match). only_for="cuda" itself is kept: Rule 4's only_for ban is scoped to ACCELERATOR classes, Rule 5 imposes no instantiation requirements on CUDA-classified classes, and the in-tree linter's OnlyForRule is registered for ACCELERATOR only (checked by running the linter plus a deliberate-violation probe to confirm the finding fires where it should). Test Plan torch 2.16.0.dev20261029; the "cpu" venv autoloads torch_npu (registers PrivateUse1), so CPU-only claims use TORCH_DEVICE_BACKEND_AUTOLOAD=0. All pytest runs from /tmp with absolute paths. CPU-only host, final state: TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -> collected 3 (test_pre_grad, test_crossref, test_eager_backend), 3 passed so the 3 GENERIC tests run and pass on a GPU-less host now that the HAS_GPU gate is gone. (Linux only; the macOS/Windows CPU shards are left to CI.) Same file on a host with PrivateUse1 registered: collected 10 vs 11 for the stock file; the moved test is not instantiated where no CUDA device type exists (on CUDA builds it is TestCompilerBisectorCudaCUDA.test_cudagraph_bisect_max_cuda). Whole file: python -m pytest -q -rs <file> # final: 1 failed, 3 passed, 6 skipped python -m pytest -q -rs <stock> # base commit version: 11 skipped, 0 failed The one failure is TestCompilerBisectorRNGNPU.test_rng_npu with AssertionError: String comparison failed: 'eager' != 'inductor', i.e. the intended exposure above (stock skipped it via the class-level Triton gate on this no-triton venv and via @skipPRIVATEUSE1 on the NPU machine); the 6 skips are the pre-existing per-device "requires Triton on npu" gates. NPU machine (8x Ascend 910B4, triton-ascend installed), final state: python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -k test_rng -> 1 failed, 9 deselected (the bisect leg diverges on RNG as above; the inductor leg additionally hits a pre-existing torch_npu wheel codegen crash, reproduced with a plain torch.compile of the same function and unrelated to this change). Pre-PR the same command skips with "test doesn't work on privateuse1 backend". Lint: python tools/linter/adapters/test_linter.py test/dynamo/test_compiler_bisector.py -> no findings (allowlist entry removed; a deliberate ACCELERATOR only_for violation makes it emit exactly the [only_for] finding) lintrunner test/dynamo/test_compiler_bisector.py tools/linter/adapters/test_linter_allowlist.json -> ok No lint issues. Not covered here: the CUDA legs (no NVIDIA hardware on this host); the upstream hardware shards run those.
…assified test class (#198360) Summary `test_cudagraph_bisect_max` needs CUDA graphs, so it does not belong in the accelerator-wide `TestCompilerBisector` class, where it was reachable for any device the old aggregate gate accepted. This moves it into a class of its own, classified for CUDA and instantiated through `instantiate_device_type_tests`, Changes - New `TestCompilerBisectorCuda` with `hw_classification = CUDA`, holding `test_cudagraph_bisect_max`, instantiated with `instantiate_device_type_tests(..., only_for="cuda")` so the test takes the injected `device` parameter instead of naming one. - `@requires_cuda` is not kept on top of that: after `only_for="cuda"` the instantiation already answers it, and a second gate would be a second, independently rotting source of the same fact. - The Triton condition that the original class reached through the `HAS_GPU` formula is restored on the class that still needs a Triton kernel, expressed as its own requirement rather than as part of an aggregate boolean. - `test_rng` no longer carries an upstream PrivateUse1 skip; per maintainer direction out-of-tree accelerators are exposed rather than silently skipped, and a backend that does not support it opts out in its own `instantiate_device_type_tests` instantiation. Test Plan Host: torch 2.16.0.dev20261029; the "cpu" venv autoloads torch_npu and therefore registers PrivateUse1, so CPU-only claims below run with `TORCH_DEVICE_BACKEND_AUTOLOAD=0`. All pytest commands from a directory outside the source tree with the absolute file path. CPU-only (no CUDA, no accelerator registered) at head 78146ef: TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -> collected: 3 (TestCompilerBisector::test_pre_grad / test_crossref / test_eager_backend) -> 3 passed With the `HAS_GPU` gate removed the three GENERIC tests now run on a GPU-less host and pass; that addresses the automated review's request for HEAD numbers. The new head's macOS/Windows CPU test jobs have not reported yet, so those remain CI's to report. Test-ID move: on a CUDA build `test_cudagraph_bisect_max` is `TestCompilerBisectorCudaCUDA.test_cudagraph_bisect_max_cuda` (class name = original + `device_type.upper()`, method suffix `_cuda`, per `instantiate_device_type_tests`). On a machine with no CUDA device type registered it is not collected at all (`only_for="cuda"` matches nothing); collection here is 10 IDs with PrivateUse1 registered vs 11 pre-PR. PrivateUse1-registered host (same wheel, torch_npu autoloaded): python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -> 1 failed, 3 passed, 6 skipped (skips: 6x "requires Triton on npu", the pre-existing per-device gates) The one failure is `TestCompilerBisectorRNGNPU.test_rng_npu` with `String comparison failed: 'eager' != 'inductor'`. This is the intended coverage change decided in review: per @fffrog's instruction the `@skipPRIVATEUSE1` special case is not restored — `test_rng` is exposed to all out-of-tree accelerators and backends that do not support it skip it in their own `instantiate_device_type_tests` instantiation. (`preserve_rng_state` currently preserves only CPU/CUDA/XPU RNG, so an out-of-tree backend without RNG preservation must opt out.) The stock (pre-PR) file run with the same command gives `11 skipped, 0 failed`, isolating this as the deliberate skip-to-exposed delta, not a pre-existing failure. NPU hardware (8x Ascend 910B4, triton-ascend installed): python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -k test_rng -> 1 failed, 9 deselected The bisect diverges on the eager/aot legs (RNG, as above); the inductor leg on this wheel additionally hits a pre-existing torch_npu codegen skew (`NPUPythonWrapperCodeGen... 'tunable_dyn_dims_mask'`), reproduced with a plain `torch.compile` of the same function and unrelated to this change. Pre-PR the same command skipped with "test doesn't work on privateuse1 backend". Lint: python tools/linter/adapters/test_linter.py test/dynamo/test_compiler_bisector.py -> no findings (allowlist entry removed in this PR) lintrunner test/dynamo/test_compiler_bisector.py tools/linter/adapters/test_linter_allowlist.json -> ok No lint issues. Not covered here: the CUDA legs (`test_cudagraph_bisect_max_cuda`, the cuda/xpu variants of the Triton-gated tests) — this host has no NVIDIA hardware; the upstream hardware shards run those. Signed-off-by: gavinwang269 <[email protected]> - `TestCompilerBisector` gains `hw_classification = HardwareClassification.GENERIC` (review request), byte-identical to the declaration in #198354/#198355 so the three slices converge in any merge order. - Bare one-line `hw_classification = HardwareClassification.GENERIC` on `TestCompilerBisector` (the only PR adding it). Once #198354/#198355 have moved the remaining GPU_TYPE occupants, the import-time `HAS_GPU` decorator and the `HAS_GPU`/`GPU_TYPE` imports are retired here too, so the natural merge order lands the exact end state. Rebase note (2026-11-09): replayed onto current main after #198354/#198355 merged, and per review this now also removes the import-time HAS_GPU gate and the GPU_TYPE/HAS_GPU import (both have no users left in the file). The single GENERIC declaration here is the only one across the series. Scope note: an earlier revision of this PR carried the dead-scaffolding cleanup from #198362; per the review discussion that cleanup is dropped, and this PR closes out the bisector series with the move and the classification only (+53/-53). Final-cleanup note (2026-11-10): as the last PR touching test_compiler_bisector.py in this series, this also drops the file entry from tools/linter/adapters/test_linter_allowlist.json (TEST_LINTER runs clean on the file after the removal), and moves the Triton gates to accelerator-aware @skipIf(..., device_type=...) forms, narrowed per review on each class. Pull Request resolved: #198360 Approved by: https://github.com/fffrog, https://github.com/lizhihai137, https://github.com/can-gaa-hou
Summary
Move
test_bad_decompfromTestCompilerBisectorintoTestCompilerBisectorDeviceintest/dynamo/test_compiler_bisector.py, so the test is instantiated for all non-CPU accelerator devices (including out-of-tree backends) instead of being gated behindHAS_GPU.Split from #191435 (refactoring this file for out-of-tree accelerator support).
Changes
test/dynamo/test_compiler_bisector.py(+58 -56):test_bad_decompmoves fromTestCompilerBisector(class-level@unittest.skipIf(not HAS_GPU, ...), nodeviceparameter) into the existingTestCompilerBisectorDevice(hw_classification = HardwareClassification.ACCELERATOR, already instantiated viainstantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)).device=GPU_TYPEinside the moved method becomes thedeviceargument injected by instantiation.@unittest.skipIf(not has_triton(), "requires Triton")decorator ofTestCompilerBisectorDevice; the duplicate method-level copy of that decorator was removed. A fully device-aware gate needs a TritonCapabilityin the registry, left for a follow-up.TestCompilerBisectorbase class is untouched: the hw_classification declaration this PR previously added was dropped per review -- [Testcase Refactoring] Split test_cudagraph_bisect_max into a CUDA-classified test class #198360 is the single PR that adds the GENERIC label to it.Motivation
The
@unittest.skipIf(not HAS_GPU)class guard usesHAS_GPU, defined asHAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON. Out-of-tree accelerators registered viaPrivateUse1are not in this list, so the whole test class gets skipped even though the test only needs a generic accelerator with Triton support. Usinginstantiate_device_type_testswithexcept_for="cpu"runs the test on all non-CPU device types registered in the test framework, including out-of-tree backends, andhw_classificationprovides metadata for--hw-classificationfiltering.Notes
HAS_GPUcould previously resolve to MTIA; MTIA CI does not collect this file today, and instantiation would not add an MTIA variant without a corresponding test base. Coverage note, not a regression on currently-tested devices.Test Plan
CPU (
env-pytorch-2.16-20261029-cpuvenv,pytest --collect-only, run from outside the source tree):11 tests collected; the moved test now appears as
test_bad_decomp_npuonly for accelerator devices. Re-measured after the follow-up edits: still 11 collected.NPU (Ascend 910B4, CANN 9.2.0 GA,
env-pytorch-2.16-20261029-npuvenv with torch_npu 737bb43 + triton-ascend 3.6.0):python -m pytest test/dynamo/test_compiler_bisector.py -k test_bad_decomp_npu -v # 1 passed (28s over three consecutive runs with the follow-up edits); previously this test never executed on NPUlintrunner test/dynamo/test_compiler_bisector.py # ok No lint issuescc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98