Skip to content

[Testcase Refactoring] Make test_compiler_bisector device-agnostic via instantiate_device_type_tests - #191435

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:test/compiler-bisector-device-agnostic-v3
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:test/compiler-bisector-device-agnostic-v3

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactor test/dynamo/test_compiler_bisector.py to use the device-agnostic test pattern with instantiate_device_type_tests and hw_classification, replacing the restrictive @skipIf(not HAS_GPU) class-level guard and @requires_cuda method-level decorator.

Changes

test/dynamo/test_compiler_bisector.py (+128 -122):

  • Split TestCompilerBisector into 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 via instantiate_device_type_tests(except_for="cpu", allow_xpu=True)
  • Replace @skipIf(not HAS_GPU) with except_for="cpu" class-level guard
  • Replace 7 device=GPU_TYPE references with device parameter (injected by instantiate_device_type_tests)
  • Gate test_cudagraph_bisect_max on XPU with the device-aware @skipXPUIf (from common_device_type) instead of the global @skipIfXpu
  • Add hw_classification = HardwareClassification.GENERIC|ACCELERATOR to each class
  • Remove import unittest, requires_cuda, GPU_TYPE, HAS_GPU imports
  • Rename test_ns to bisector_ns (class attributes starting with "test" are picked up by instantiate_device_type_tests)

test/dynamo/_test_compiler_bisector_run_helper.py (+16 -2):

  • Receive the device from the parent test process via the TORCH_BISECT_TEST_DEVICE environment variable (avoids collision with the existing TORCH_TEST_DEVICES used by common_device_type)
  • When run standalone, resolve the device dynamically via torch.accelerator.current_accelerator() and fail loudly if no accelerator is available, instead of hardcoding a device

Motivation

The @skipIf(not HAS_GPU) 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 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_tests with except_for="cpu", the tests run on all non-CPU device types that are registered in the test framework, including out-of-tree backends. The hw_classification attribute provides metadata for --hw-classification filtering (introduced in #186918).

Notes

  • The Triton requirement on the ACCELERATOR tests is still gated by a device-blind @unittest.skipIf(not has_triton(), ...). A fully device-aware gate needs a Triton capability registered in the Capability registry and surfaced by each backend's _capabilities(); that mechanism is not finished yet, so it is left for a follow-up.
  • test_cudagraph_bisect_max still 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.
  • MTIA coverage: previously HAS_GPU could resolve to MTIA. There is no MTIATestBase registered with instantiate_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 in HAS_GPU either).

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:

Environment Tests Passed Failed
torch-2.15-cpu 3 (GENERIC) 3 0
torch-2.15-npu 11 (all) 11 0
# CPU (GENERIC tests only)
conda run -n torch-2.15-cpu python3 -m pytest test/dynamo/test_compiler_bisector.py -v
# Result: 3 passed

# NPU (all tests)
conda run -n torch-2.15-npu python3 -m pytest test/dynamo/test_compiler_bisector.py -v
# Result: 11 passed

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

🔗 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.

⚠️ 4 Awaiting Approval

As of commit 213f6ef with merge base 66eef30 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module:tests/graph"

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Didn't find following labels among repository labels: module:tests/graph

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module:tests/graph"

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Didn't find following labels among repository labels: module:tests/graph

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label module:tests/graph

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Didn't find following labels among repository labels: module:tests/graph

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label module: tests/graph

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Didn't find following labels among repository labels: module:,tests/graph

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: tests/graph"

@pytorch-bot pytorch-bot Bot added the module: tests/graph This label covers all test cases within the Graph sheet. label Jul 29, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot ciflow

@pytorch-bot

pytorch-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: argument command: invalid choice: 'ciflow' (choose from 'merge', 'revert', 'rebase', 'label', 'drci', 'lint', 'fix-lint', 'apply-lint', 'cherry-pick')

usage: @pytorchbot [-h]
                   
                   {merge,revert,rebase,label,drci,lint,fix-lint,apply-lint,cherry-pick}
                   ...

Try @pytorchbot --help for more info.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @fffrog, this PR removes the redundant @requires_cuda decorator from test_compiler_bisector.py as part of the test refactoring tracked in #185590. Could you please help trigger CI and review? Thanks!

@drisspg drisspg added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 29, 2026
@drisspg
drisspg requested a review from fffrog July 29, 2026 04:50
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Jul 29, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

The lint failure appears to be a CI infrastructure issue (FileNotFoundError in clangtidy_linter.py on c10/macros/ headers, which exist in the repo). The log shows "No lint issues" before the crash. Could a maintainer please re-run the lint job?

@gavinwang269

Copy link
Copy Markdown
Contributor Author

All 12 CI failures appear to be infrastructure issues, not code issues:

  • 10 build failures: pod failed to come online / backoff timeout (runner pods never started)
  • 2 lint failures: FileNotFoundError in clangtidy_linter.py (log shows "No lint issues" before crash)

Could a maintainer please re-run the failed jobs? Thanks!

Comment thread test/dynamo/test_compiler_bisector.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAS_GPU is also needed to refactor here for device-agnostic?

@gavinwang269 gavinwang269 Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/dynamo/test_compiler_bisector.py Outdated
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want this test to run on PU1, you may also want to refactor GPU_TYPE here.

@gavinwang269 gavinwang269 Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gavinwang269
gavinwang269 force-pushed the test/compiler-bisector-device-agnostic-v3 branch from d4bafe0 to c7f4c6a Compare July 31, 2026 14:01
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot

pytorch-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

-i flag is only allowed for users with write permissions

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

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.

@github-project-automation github-project-automation Bot moved this from Backlog to Done in PyTorch Test Refactoring Sep 22, 2026
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 24, 2026
…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]>
pytorchmergebot pushed a commit that referenced this pull request Sep 28, 2026
… 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]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 28, 2026
…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.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 28, 2026
… 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.
pytorchmergebot pushed a commit that referenced this pull request Oct 2, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor module: dynamo module: inductor module: tests/graph This label covers all test cases within the Graph sheet. open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants