Repository navigation
[Testcase Refactoring] Make test_compiler_bisector device-agnostic via instantiate_device_type_tests - #191435
[Testcase Refactoring] Make test_compiler_bisector device-agnostic via instantiate_device_type_tests#191435gavinwang269 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191435
Note: Links to docs will display an error until the docs builds have been completed.
|
|
|
|
@pytorchbot label "module:tests/graph" |
|
Didn't find following labels among repository labels: module:tests/graph |
|
@pytorchbot label "module:tests/graph" |
|
Didn't find following labels among repository labels: module:tests/graph |
|
@pytorchbot label module:tests/graph |
|
Didn't find following labels among repository labels: module:tests/graph |
|
@pytorchbot label module: tests/graph |
|
Didn't find following labels among repository labels: module:,tests/graph |
|
@pytorchbot label "module: tests/graph" |
|
@pytorchbot ciflow |
|
❌ 🤖 pytorchbot command failed: Try |
|
The lint failure appears to be a CI infrastructure issue ( |
|
All 12 CI failures appear to be infrastructure issues, not code issues:
Could a maintainer please re-run the failed jobs? Thanks! |
There was a problem hiding this comment.
HAS_GPU is also needed to refactor here for device-agnostic?
There was a problem hiding this comment.
Update: This has been fully addressed in the latest version. HAS_GPU and GPU_TYPE imports have been removed entirely. The class now uses instantiate_device_type_tests(except_for="cpu", allow_xpu=True) with @unittest.skipIf(not has_triton(), "requires Triton") on device test methods, replacing the old @skipIf(not HAS_GPU) class-level guard. The device parameter is injected by instantiate_device_type_tests, eliminating all GPU_TYPE references.
| foo_c = torch.compile(foo, mode="reduce-overhead") # noqa: UNSPECIFIED_BACKEND | ||
| bar_c = torch.compile(bar, mode="reduce-overhead") # noqa: UNSPECIFIED_BACKEND | ||
| foo_c = torch.compile(foo, mode="reduce-overhead") | ||
| bar_c = torch.compile(bar, mode="reduce-overhead") | ||
| x = torch.randn(10, device=GPU_TYPE) |
There was a problem hiding this comment.
If you want this test to run on PU1, you may also want to refactor GPU_TYPE here.
There was a problem hiding this comment.
Update: Fully addressed in the latest version. All 7 device=GPU_TYPE references have been replaced with the device parameter injected by instantiate_device_type_tests. The GPU_TYPE import is removed. The helper file _test_compiler_bisector_run_helper.py now reads the device from the TORCH_TEST_DEVICE environment variable (set by the parent test process), with fallback to get_gpu_type(). No more hardcoded GPU type references remain in this file.
d4bafe0 to
c7f4c6a
Compare
|
@pytorchbot merge -i |
|
|
|
@pytorchbot merge |
|
Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra. |
…assified test class Per review: cudagraphs are CUDA-specific behavior, so `instantiate_device_type_tests(allow_xpu=True)` + `skipXPUIf(True, ...)` was the wrong fit. Move the test into a dedicated `TestCompilerBisectorCuda` class tagged `hw_classification = HardwareClassification.CUDA`, keeping `@requires_cuda`. Part of the orthogonal split for pytorch#191435; remaining tests migrate in their sibling PRs. Test Plan: module import + collection verified on torch 2.15.0.dev cpu nightly (1 test in the CUDA class, old class unaffected); ruff check/format clean. Authored with an AI assistant. Co-Authored-By: Claude Code <[email protected]>
… via instantiate_device_type_tests (#198361) ## Summary Make `test_bisect_run_debuginfo` in `test/dynamo/test_compiler_bisector.py` device-agnostic by migrating it into a new `TestCompilerBisectorDevice` instantiated via `instantiate_device_type_tests`. Split from #191435 (refactoring this file for out-of-tree accelerator support). ## Changes `test/dynamo/test_compiler_bisector.py`: - New `TestCompilerBisectorDevice(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`); `test_bisect_run_debuginfo` moves into it, and the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by `instantiate_device_type_tests(TestCompilerBisectorDevice, globals(), except_for="cpu", allow_xpu=True)`. - The Triton requirement stays gated by a device-blind `@unittest.skipIf(not has_triton(), "requires Triton")`; a fully device-aware gate needs a Triton `Capability` in the registry, left for a follow-up. - The subprocess device is passed to the helper via `TORCH_BISECT_TEST_DEVICE` (the helper change shipped in the same #191435 split). ## Notes This PR is self-contained: it includes the new-class scaffold (imports, `TestCompilerBisectorDevice`, the `instantiate_device_type_tests` call) so it is testable standalone. Unmigrated methods keep the old class guard and their non-`device` signatures, so instantiation leaves them untouched. - MTIA coverage note: `HAS_GPU` could previously resolve to MTIA; no `MTIATestBase` exists for this file, so no MTIA variant is generated. Coverage note, not a regression on currently-tested devices. ## 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` (e.g., Ascend NPU) are not in this list, so the whole test class gets skipped even though the tests only need a generic accelerator with Triton support. Using `instantiate_device_type_tests` with `except_for="cpu"` runs the tests 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. ## Test Plan | Environment | Result | |---|---| | CPU-only (`torch-2.15-cpu`) | `pytest test/dynamo/test_compiler_bisector.py -q` -> **10 skipped**, collection identical to `main` | | NPU (`torch-2.15-npu`, Ascend 910B4 / CANN 9.1.0 / triton-ascend 3.6.0), whole refactor applied | **11 passed, 0 failed** (3 generic + 8 `*_npu` device variants) | `ruff` 0.14.4 (CI-pinned): clean. Pull Request resolved: #198361 Approved by: https://github.com/Skylion007 Co-authored-by: Claude Code <[email protected]>
…assified test class Per review: cudagraphs are CUDA-specific behavior, so `instantiate_device_type_tests(allow_xpu=True)` + `skipXPUIf(True, ...)` was the wrong fit. Move the test into a dedicated `TestCompilerBisectorCuda` class tagged `hw_classification = HardwareClassification.CUDA`, keeping `@requires_cuda`. Part of the orthogonal split for pytorch#191435; remaining tests migrate in their sibling PRs. Test Plan: module import + collection verified on torch 2.15.0.dev cpu nightly (1 test in the CUDA class, old class unaffected); ruff check/format clean.
… last) Part of splitting pytorch#191435. Final cleanup of the generic class: remove the 8 device-dependent tests (they now live in TestCompilerBisectorDevice, added by the migration PRs), drop the device-only scaffolding (@unittest.skipIf(not HAS_GPU) guard, GPU_TYPE/HAS_GPU, requires_cuda and Library imports, dead get_lib), declare hw_classification = HardwareClassification.GENERIC, and rename test_ns -> bisector_ns. Merge last, on top of the 8 migration PRs; after rebase the removal hunks drop out and only the old-class cleanup remains in the diff.
…tantiate_device_type_tests (#198358) ## Summary Move `test_bad_lowering` 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 #191435 (refactoring this file for out-of-tree accelerator support). ## Changes `test/dynamo/test_compiler_bisector.py` (+19 -18): - `test_bad_lowering` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `#198361` already set up and `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument. ## Motivation 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` (e.g., Ascend NPU) 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. ## Notes The shared scaffold (new class + instantiation) is already on `main` via #198361, so this PR is a pure single-method move. Triton gating keeps the existing device-blind `@unittest.skipIf(not has_triton(), ...)` convention already used by `test_bisect_run_debuginfo` on `main`; a fully device-aware gate needs a Triton `Capability` in the registry (follow-up). ## Test Plan - CPU (`torch-2.15-cpu`, pytest --collect-only): 9 tests collected, identical to `main` baseline; `pytest -q` -> 9 skipped (guard unchanged on CPU). - NPU real hardware (Ascend 910B4, CANN 9.1.0, `torch-2.15-npu`, triton-ascend): `pytest -k test_bad_lowering_npu` -> **1 passed** (previously this test never executed on NPU). - `pycodestyle --select E3` clean; `ruff format --diff` shows no findings in the touched region. ## Dependencies Part of the #191435 split series (#198353 ~ #198362); independent of its siblings, each moves one test method. Pull Request resolved: #198358 Approved by: https://github.com/guilhermeleobas
Summary
Refactor
test/dynamo/test_compiler_bisector.pyto use the device-agnostic test pattern withinstantiate_device_type_testsandhw_classification, replacing the restrictive@skipIf(not HAS_GPU)class-level guard and@requires_cudamethod-level decorator.Changes
test/dynamo/test_compiler_bisector.py(+128 -122):TestCompilerBisectorinto two classes:TestCompilerBisector(GENERIC): 3 tests that do not require an accelerator (test_pre_grad,test_crossref,test_eager_backend)TestCompilerBisectorDevice(ACCELERATOR): 8 tests that require an accelerator, instantiated viainstantiate_device_type_tests(except_for="cpu", allow_xpu=True)@skipIf(not HAS_GPU)withexcept_for="cpu"class-level guarddevice=GPU_TYPEreferences withdeviceparameter (injected byinstantiate_device_type_tests)test_cudagraph_bisect_maxon XPU with the device-aware@skipXPUIf(fromcommon_device_type) instead of the global@skipIfXpuhw_classification = HardwareClassification.GENERIC|ACCELERATORto each classimport unittest,requires_cuda,GPU_TYPE,HAS_GPUimportstest_nstobisector_ns(class attributes starting with "test" are picked up byinstantiate_device_type_tests)test/dynamo/_test_compiler_bisector_run_helper.py(+16 -2):TORCH_BISECT_TEST_DEVICEenvironment variable (avoids collision with the existingTORCH_TEST_DEVICESused bycommon_device_type)torch.accelerator.current_accelerator()and fail loudly if no accelerator is available, instead of hardcoding a deviceMotivation
The
@skipIf(not HAS_GPU)guard usesHAS_GPU, defined asHAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON. Out-of-tree accelerators registered viaPrivateUse1(e.g., Ascend NPU) are not included in this list, causing the entire test class to be skipped even though the tests only need a generic accelerator with Triton support.By using
instantiate_device_type_testswithexcept_for="cpu", the tests run on all non-CPU device types that are registered in the test framework, including out-of-tree backends. Thehw_classificationattribute provides metadata for--hw-classificationfiltering (introduced in #186918).Notes
@unittest.skipIf(not has_triton(), ...). A fully device-aware gate needs a Triton capability registered in theCapabilityregistry and surfaced by each backend's_capabilities(); that mechanism is not finished yet, so it is left for a follow-up.test_cudagraph_bisect_maxstill relies on CUDA cudagraph trees; it is kept for the accelerator variants and only excludes XPU (which lacks cudagraph support). NPU support is expected to work through the out-of-tree backend and is not excluded.HAS_GPUcould resolve to MTIA. There is noMTIATestBaseregistered withinstantiate_device_type_tests, so no MTIA variant is generated. This is a coverage change to note, not a regression on currently-tested devices (MPS was never inHAS_GPUeither).Dependencies
Test Plan
Verified on Ascend 910B4 with CANN 9.1.0 GA, torch 2.15.0.dev20260819, torch_npu 2.15.0, triton-ascend 3.6.0: