Skip to content

[Testcase Refactoring] Make test_bisect_run_debuginfo device-agnostic via instantiate_device_type_tests - #198361

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m8-bisect_run_debuginfo
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m8-bisect_run_debuginfo

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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 [Testcase Refactoring] Make test_compiler_bisector device-agnostic via instantiate_device_type_tests #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.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @FFrog

…ted TestCompilerBisectorDevice (self-contained)

Co-Authored-By: Claude Code <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198361

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 5d63778 with merge base d602395 (image):

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

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

@pytorch-bot

pytorch-bot Bot commented Sep 23, 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 added the module: tests/graph This label covers all test cases within the Graph sheet. label Sep 23, 2026
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Sep 23, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 28, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 28, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 29, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Addresses claude[bot] review:
- add blank line between the debuginfo test and the moved method (E301)
- collapse the extra blank line before instantiate_device_type_tests (PYFMT)
- drop the redundant in-method `from torch._inductor import config` (already at file scope)
- update the uuid() string to name TestCompilerBisectorDevice after the move

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 29, 2026
…nostic class

Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 29, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 29, 2026
…stic class

Rebased onto latest main: the Device-class scaffold already exists (merged
via pytorch#198361), so this piece is a pure method move -- it drops the CUDA-bound
test_bisect_pre_grad_graph from the HAS_GPU-guarded TestCompilerBisector and
re-adds it on TestCompilerBisectorDevice as a device-parameterized test.

Addresses claude[bot] review: add the missing has_triton skipIf gate (the
bisected bug is injected via triton.inject_relu_bug_TESTING_ONLY, so the
test cannot pass without Triton) and fix blank-line spacing so lint passes.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 30, 2026
…device_type_tests

Rebased onto latest main: the Device-class scaffold already exists (merged
via pytorch#198361). `test_rng` is moved out of the CPU-excluded base class into a
dedicated device-instantiated class.

`torch._dynamo.utils.preserve_rng_state` only saves and restores CPU, CUDA
and XPU RNG state, so the eager-vs-compiled RNG comparison `test_rng` relies
on is only meaningful on CUDA and XPU. The new class is instantiated with
`only_for=("cuda", "xpu")` so out-of-tree backends that lack RNG save/restore
are excluded at instantiation time instead of silently diverging. A follow-up
could generalize `preserve_rng_state` via `torch.get_device_module(device)`
to widen this coverage.

Also fixes the E301/E303 lint issues flagged on the previous revision.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Sep 30, 2026
…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]>
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
cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…tantiate_device_type_tests (pytorch#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 pytorch#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 `pytorch#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 pytorch#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 pytorch#191435 split series (pytorch#198353 ~ pytorch#198362); independent of its siblings, each moves one test method.

Pull Request resolved: pytorch#198358
Approved by: https://github.com/guilhermeleobas
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 12, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 12, 2026
## 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` (+59 -56, a pure method move):
- `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)`, scaffold landed via pytorch#198361).
- The hardcoded `device=GPU_TYPE` inside the method becomes the `device` argument injected by instantiation.
- The Triton requirement stays gated by the same device-blind `@unittest.skipIf(not has_triton(), "requires Triton")` guard used by the other methods of the class; 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.

## 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 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 (conda env `torch-2.15-cpu`, wheel build, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -q
# result: 8 skipped (collection identical to main minus the moved test,
# which now only instantiates for non-CPU devices: main collects 9)
```

NPU (Ascend 910B4, CANN 9.1.0, conda env `torch-2.15-npu` with torch_npu and triton-ascend, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -v --tb=short
# result: TestCompilerBisectorDevicePRIVATEUSE1::test_bad_decomp_npu PASSED
```

Lint (CI-pinned tools): `ruff format` clean, `pycodestyle --select E301,E302,E303,E305,E306` clean.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @fffrog
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 13, 2026
## 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` (+59 -56, a pure method move):
- `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)`, scaffold landed via pytorch#198361).
- The hardcoded `device=GPU_TYPE` inside the method becomes the `device` argument injected by instantiation.
- The Triton requirement stays gated by the same device-blind `@unittest.skipIf(not has_triton(), "requires Triton")` guard used by the other methods of the class; 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.

## 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 (conda env `torch-2.15-cpu`, wheel build, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -q
# result: 8 skipped (collection identical to main minus the moved test,
# which now only instantiates for non-CPU devices: main collects 9)
```

NPU (Ascend 910B4, CANN 9.1.0, conda env `torch-2.15-npu` with torch_npu and triton-ascend, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -v --tb=short
# result: TestCompilerBisectorDevicePRIVATEUSE1::test_bad_decomp_npu PASSED
```

Lint (CI-pinned tools): `ruff format` clean, `pycodestyle --select E301,E302,E303,E305,E306` clean.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @fffrog
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 30, 2026
…nostic class

Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 31, 2026
## 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` (+59 -56, a pure method move):
- `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)`, scaffold landed via pytorch#198361).
- The hardcoded `device=GPU_TYPE` inside the method becomes the `device` argument injected by instantiation.
- The Triton requirement stays gated by the same device-blind `@unittest.skipIf(not has_triton(), "requires Triton")` guard used by the other methods of the class; 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.

## 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 (conda env `torch-2.15-cpu`, wheel build, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -q
# result: 8 skipped (collection identical to main minus the moved test,
# which now only instantiates for non-CPU devices: main collects 9)
```

NPU (Ascend 910B4, CANN 9.1.0, conda env `torch-2.15-npu` with torch_npu and triton-ascend, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -v --tb=short
# result: TestCompilerBisectorDevicePRIVATEUSE1::test_bad_decomp_npu PASSED
```

Lint (CI-pinned tools): `ruff format` clean, `pycodestyle --select E301,E302,E303,E305,E306` clean.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @fffrog
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 31, 2026
…stic class

Rebased onto latest main: the Device-class scaffold already exists (merged
via pytorch#198361), so this piece is a pure method move -- it drops the CUDA-bound
test_bisect_pre_grad_graph from the HAS_GPU-guarded TestCompilerBisector and
re-adds it on TestCompilerBisectorDevice as a device-parameterized test.

Addresses claude[bot] review: add the missing has_triton skipIf gate (the
bisected bug is injected via triton.inject_relu_bug_TESTING_ONLY, so the
test cannot pass without Triton) and fix blank-line spacing so lint passes.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 31, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Addresses claude[bot] review:
- add blank line between the debuginfo test and the moved method (E301)
- collapse the extra blank line before instantiate_device_type_tests (PYFMT)
- drop the redundant in-method `from torch._inductor import config` (already at file scope)
- update the uuid() string to name TestCompilerBisectorDevice after the move

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 31, 2026
…device_type_tests

Rebased onto latest main: the Device-class scaffold already exists (merged
via pytorch#198361). `test_rng` is moved out of the CPU-excluded base class into a
dedicated device-instantiated class.

`torch._dynamo.utils.preserve_rng_state` only saves and restores CPU, CUDA
and XPU RNG state, so the eager-vs-compiled RNG comparison `test_rng` relies
on is only meaningful on CUDA and XPU. The new class is instantiated with
`only_for=("cuda", "xpu")` so out-of-tree backends that lack RNG save/restore
are excluded at instantiation time instead of silently diverging. A follow-up
could generalize `preserve_rng_state` via `torch.get_device_module(device)`
to widen this coverage.

Also fixes the E301/E303 lint issues flagged on the previous revision.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Oct 31, 2026
…isector class

Re-derived on top of merged reality. The original revision of this PR also
dropped seven methods (bad_decomp, joint_graph, rng, emulate_precision_casts,
bad_lowering, bisect_pre_grad_graph, cudagraph_bisect_max) whose device-agnostic
replacements arrive in sibling PRs, and declared the remaining class GENERIC.
Since then only pytorch#198358 (test_bad_lowering) and pytorch#198361 (test_bisect_run_debuginfo)
have landed: deleting the still-present six methods now would remove their only
coverage before their replacements merge, and labeling the class GENERIC would be
wrong while six GPU-bound tests remain under its HAS_GPU gate. Those parts are
therefore obsolete-after-merge / premature and were dropped from this PR.

What remains valid independently of the sibling series:

- Rename the class attribute test_ns -> bisector_ns. An attribute whose name
  starts with the "test" prefix is a latent test-collection footgun (it would be
  picked up by instantiate_device_type_tests or prefix-based loaders).
- Remove get_lib(), which is dead code after pytorch#198358 (no callers left), together
  with the Library import and the self.lib teardown it required.

Authored with an AI assistant.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 1, 2026
…ssified class

Rebased onto latest main: scaffold from pytorch#198361 is kept; this piece only moves the
cudagraph test (which needs CUDA graphs) into TestCompilerBisectorCuda.

Signed-off-by: gavinwang269 <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Nov 2, 2026
…tic via instantiate_device_type_tests (#198357)

## Summary

Move `test_emulate_precision_casts` 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` (+23 -24):
- `test_emulate_precision_casts` 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.
- The Triton gate moves from per-method decorators to `TestCompilerBisectorDevice` itself: every test in the class requires Triton, so a single class-level `@unittest.skipIf(not has_triton(), "requires Triton")` replaces the three duplicated method-level decorators (per review).

## 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` 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 the move itself is a single method transfer. The Triton gate stays device-blind (`has_triton()`); a fully device-aware gate needs a Triton `Capability` in the registry (follow-up). Class-level `skipIf` survives `instantiate_device_type_tests` because the device-specific classes inherit from the template class, verified on real hardware below.

## Test Plan

- CPU (`torch-2.16-cpu` nightly wheel): collection identical to baseline modulo the moved test.

```
python -m pytest test/dynamo/test_compiler_bisector.py --collect-only -q
# 11 tests collected; TestCompilerBisectorDevicePRIVATEUSE1 now owns test_emulate_precision_casts_npu
```

- `lintrunner test/dynamo/test_compiler_bisector.py` -> `ok No lint issues.`

- NPU real hardware (Ascend 910B4):

```
python -m pytest test/dynamo/test_compiler_bisector.py -v
# 3 passed, 8 skipped
```

### Verification Report

| Hardware | Cases | Passed | Failed | Skipped | Result |
|----------|-------|--------|--------|---------|--------|
| CPU (no accelerator) | 11 collected | - | - | - | Collect-only; 11 items, device class now owns `test_emulate_precision_casts_npu` |
| NPU (Ascend 910B4) | 11 | 3 | 0 | 8 | `test_emulate_precision_casts_npu` passes (previously never executed on NPU); 8 skips are the `HAS_GPU`-guarded legacy class, expected |

Gate behavior verified both directions on NPU: with Triton installed all three tests in the device class run and pass; with Triton absent the class skips with `requires Triton`.

### Environment

| Item | Version |
|------|---------|
| CANN | 9.2.0 (GA) |
| driver | 26.1.1 |
| PyTorch | 2.16.0.dev20261029+cpu (nightly wheel, same day as trunk) |
| torch_npu | 2.16.0.dev20261029+git737bb43 (source build from master) |
| Python | 3.12.15 |
| triton-ascend | 3.6.0+git0cfb1708 |

## Dependencies

Part of the #191435 split series (#198353 ~ #198362); independent of its siblings, each moves one test method.

Pull Request resolved: #198357
Approved by: https://github.com/can-gaa-hou, https://github.com/lizhihai137, https://github.com/jansel
pytorchmergebot pushed a commit that referenced this pull request Nov 2, 2026
…device_type_tests (#198356)

## Summary

Move `test_rng` out of the guard-skipped `TestCompilerBisector` class into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old `@unittest.skipIf(not HAS_GPU)` class guard.

Split from #191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the `instantiate_device_type_tests` scaffold already landed via #198361.

## Changes

`test/dynamo/test_compiler_bisector.py` (+38 -20):
1. Add `TestCompilerBisectorRNG(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`) containing the moved `test_rng`; the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by instantiation, and the Triton gate sits on the class (same pattern as #198357).
2. Instantiate with `except_for="cpu"` (per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix via `only_for`). `test_rng` relies on `torch._dynamo.utils.preserve_rng_state`, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU: `do_bisect` reports `eager` instead of `inductor`). Such devices now skip explicitly via `@skipPRIVATEUSE1` rather than being silently excluded from instantiation.

## Notes

- Generalizing `preserve_rng_state` via `torch.get_device_module(device)` would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate.
- Test IDs change from `TestCompilerBisector.test_rng` to per-device variants (`test_rng_cuda`, `test_rng_xpu`, `test_rng_npu` [skipped], ...). I checked the `test/dynamo_skips/` and `test/dynamo_expected_failures/` entries and the slow-test lists in `main`: nothing is keyed on the old `TestCompilerBisector.test_rng` name.

## Motivation

The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU = 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 test was skipped even where it can run. `instantiate_device_type_tests` gives each supported device its own variant, and `hw_classification` provides metadata for `--hw-classification` filtering.

## Test Plan

| Environment | Result |
|---|---|
| CPU (`env-pytorch-2.16-20261029-cpu`) | `pytest --collect-only -q` -> **11 tests collected** (the moved test no longer appears un-instantiated) |
| NPU (`env-pytorch-2.16-20261029-npu`, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0) | `test_rng_npu` is instantiated and **skips cleanly (0.009s)** via `@skipPRIVATEUSE1` instead of being silently absent |
| CUDA / XPU execution | covered by the ciflow trunk jobs |
| lint | `lintrunner` (includes in-tree TEST_LINTER): no issues |

Pull Request resolved: #198356
Approved by: https://github.com/lizhihai137, https://github.com/jansel
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 2, 2026
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` (+59 -56, a pure method move):
- `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)`, scaffold landed via pytorch#198361).
- The hardcoded `device=GPU_TYPE` inside the method becomes the `device` argument injected by instantiation.
- The Triton requirement stays gated by the same device-blind `@unittest.skipIf(not has_triton(), "requires Triton")` guard used by the other methods of the class; 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 `@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.
- CUDA and XPU keep the same effective guard set they had before the move (accelerator instantiation plus the Triton skip).

CPU (conda env `torch-2.15-cpu`, wheel build, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -q
```

NPU (Ascend 910B4, CANN 9.1.0, conda env `torch-2.15-npu` with torch_npu and triton-ascend, run from a directory outside the source tree):

```bash
python -m pytest test_compiler_bisector.py -v --tb=short
```

Lint (CI-pinned tools): `ruff format` clean, `pycodestyle --select E301,E302,E303,E305,E306` clean.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @fffrog
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 2, 2026
Rebased onto latest main: the Device-class scaffold already exists
(merged via pytorch#198361), so this piece is a pure method move.

Signed-off-by: gavinwang269 <[email protected]>

Addresses claude[bot] review:
- add blank line between the debuginfo test and the moved method (E301)
- collapse the extra blank line before instantiate_device_type_tests (PYFMT)
- drop the redundant in-method `from torch._inductor import config` (already at file scope)
- update the uuid() string to name TestCompilerBisectorDevice after the move

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 2, 2026
…ssified class

Rebased onto latest main: scaffold from pytorch#198361 is kept; this piece only moves the
cudagraph test (which needs CUDA graphs) into TestCompilerBisectorCuda.

Signed-off-by: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 2, 2026
…stic class

Rebased onto latest main: the Device-class scaffold already exists (merged
via pytorch#198361), so this piece is a pure method move -- it drops the CUDA-bound
test_bisect_pre_grad_graph from the HAS_GPU-guarded TestCompilerBisector and
re-adds it on TestCompilerBisectorDevice as a device-parameterized test.

Addresses claude[bot] review: add the missing has_triton skipIf gate (the
bisected bug is injected via triton.inject_relu_bug_TESTING_ONLY, so the
test cannot pass without Triton) and fix blank-line spacing so lint passes.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 2, 2026
…isector class

Re-derived on top of merged reality. The original revision of this PR also
dropped seven methods (bad_decomp, joint_graph, rng, emulate_precision_casts,
bad_lowering, bisect_pre_grad_graph, cudagraph_bisect_max) whose device-agnostic
replacements arrive in sibling PRs, and declared the remaining class GENERIC.
Since then only pytorch#198358 (test_bad_lowering) and pytorch#198361 (test_bisect_run_debuginfo)
have landed: deleting the still-present six methods now would remove their only
coverage before their replacements merge, and labeling the class GENERIC would be
wrong while six GPU-bound tests remain under its HAS_GPU gate. Those parts are
therefore obsolete-after-merge / premature and were dropped from this PR.

What remains valid independently of the sibling series:

- Rename the class attribute test_ns -> bisector_ns. An attribute whose name
  starts with the "test" prefix is a latent test-collection footgun (it would be
  picked up by instantiate_device_type_tests or prefix-based loaders).
- Remove get_lib(), which is dead code after pytorch#198358 (no callers left), together
  with the Library import and the self.lib teardown it required.

Authored with an AI assistant.

Signed-off-by: gavinwang269 <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…tic via instantiate_device_type_tests (pytorch#198357)

## Summary

Move `test_emulate_precision_casts` 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).

## Changes

`test/dynamo/test_compiler_bisector.py` (+23 -24):
- `test_emulate_precision_casts` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `pytorch#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.
- The Triton gate moves from per-method decorators to `TestCompilerBisectorDevice` itself: every test in the class requires Triton, so a single class-level `@unittest.skipIf(not has_triton(), "requires Triton")` replaces the three duplicated method-level decorators (per review).

## 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` 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 `pytorch#198361`, so the move itself is a single method transfer. The Triton gate stays device-blind (`has_triton()`); a fully device-aware gate needs a Triton `Capability` in the registry (follow-up). Class-level `skipIf` survives `instantiate_device_type_tests` because the device-specific classes inherit from the template class, verified on real hardware below.

## Test Plan

- CPU (`torch-2.16-cpu` nightly wheel): collection identical to baseline modulo the moved test.

```
python -m pytest test/dynamo/test_compiler_bisector.py --collect-only -q
# 11 tests collected; TestCompilerBisectorDevicePRIVATEUSE1 now owns test_emulate_precision_casts_npu
```

- `lintrunner test/dynamo/test_compiler_bisector.py` -> `ok No lint issues.`

- NPU real hardware (Ascend 910B4):

```
python -m pytest test/dynamo/test_compiler_bisector.py -v
# 3 passed, 8 skipped
```

### Verification Report

| Hardware | Cases | Passed | Failed | Skipped | Result |
|----------|-------|--------|--------|---------|--------|
| CPU (no accelerator) | 11 collected | - | - | - | Collect-only; 11 items, device class now owns `test_emulate_precision_casts_npu` |
| NPU (Ascend 910B4) | 11 | 3 | 0 | 8 | `test_emulate_precision_casts_npu` passes (previously never executed on NPU); 8 skips are the `HAS_GPU`-guarded legacy class, expected |

Gate behavior verified both directions on NPU: with Triton installed all three tests in the device class run and pass; with Triton absent the class skips with `requires Triton`.

### Environment

| Item | Version |
|------|---------|
| CANN | 9.2.0 (GA) |
| driver | 26.1.1 |
| PyTorch | 2.16.0.dev20261029+cpu (nightly wheel, same day as trunk) |
| torch_npu | 2.16.0.dev20261029+git737bb43 (source build from master) |
| Python | 3.12.15 |
| triton-ascend | 3.6.0+git0cfb1708 |

## Dependencies

Part of the pytorch#191435 split series (pytorch#198353 ~ pytorch#198362); independent of its siblings, each moves one test method.

Pull Request resolved: pytorch#198357
Approved by: https://github.com/can-gaa-hou, https://github.com/lizhihai137, https://github.com/jansel
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…device_type_tests (pytorch#198356)

## Summary

Move `test_rng` out of the guard-skipped `TestCompilerBisector` class into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old `@unittest.skipIf(not HAS_GPU)` class guard.

Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the `instantiate_device_type_tests` scaffold already landed via pytorch#198361.

## Changes

`test/dynamo/test_compiler_bisector.py` (+38 -20):
1. Add `TestCompilerBisectorRNG(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`) containing the moved `test_rng`; the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by instantiation, and the Triton gate sits on the class (same pattern as pytorch#198357).
2. Instantiate with `except_for="cpu"` (per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix via `only_for`). `test_rng` relies on `torch._dynamo.utils.preserve_rng_state`, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU: `do_bisect` reports `eager` instead of `inductor`). Such devices now skip explicitly via `@skipPRIVATEUSE1` rather than being silently excluded from instantiation.

## Notes

- Generalizing `preserve_rng_state` via `torch.get_device_module(device)` would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate.
- Test IDs change from `TestCompilerBisector.test_rng` to per-device variants (`test_rng_cuda`, `test_rng_xpu`, `test_rng_npu` [skipped], ...). I checked the `test/dynamo_skips/` and `test/dynamo_expected_failures/` entries and the slow-test lists in `main`: nothing is keyed on the old `TestCompilerBisector.test_rng` name.

## Motivation

The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU = 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 test was skipped even where it can run. `instantiate_device_type_tests` gives each supported device its own variant, and `hw_classification` provides metadata for `--hw-classification` filtering.

## Test Plan

| Environment | Result |
|---|---|
| CPU (`env-pytorch-2.16-20261029-cpu`) | `pytest --collect-only -q` -> **11 tests collected** (the moved test no longer appears un-instantiated) |
| NPU (`env-pytorch-2.16-20261029-npu`, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0) | `test_rng_npu` is instantiated and **skips cleanly (0.009s)** via `@skipPRIVATEUSE1` instead of being silently absent |
| CUDA / XPU execution | covered by the ciflow trunk jobs |
| lint | `lintrunner` (includes in-tree TEST_LINTER): no issues |

Pull Request resolved: pytorch#198356
Approved by: https://github.com/lizhihai137, https://github.com/jansel
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…tic via instantiate_device_type_tests (pytorch#198357)

## Summary

Move `test_emulate_precision_casts` 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).

## Changes

`test/dynamo/test_compiler_bisector.py` (+23 -24):
- `test_emulate_precision_casts` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `pytorch#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.
- The Triton gate moves from per-method decorators to `TestCompilerBisectorDevice` itself: every test in the class requires Triton, so a single class-level `@unittest.skipIf(not has_triton(), "requires Triton")` replaces the three duplicated method-level decorators (per review).

## 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` 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 `pytorch#198361`, so the move itself is a single method transfer. The Triton gate stays device-blind (`has_triton()`); a fully device-aware gate needs a Triton `Capability` in the registry (follow-up). Class-level `skipIf` survives `instantiate_device_type_tests` because the device-specific classes inherit from the template class, verified on real hardware below.

## Test Plan

- CPU (`torch-2.16-cpu` nightly wheel): collection identical to baseline modulo the moved test.

```
python -m pytest test/dynamo/test_compiler_bisector.py --collect-only -q
# 11 tests collected; TestCompilerBisectorDevicePRIVATEUSE1 now owns test_emulate_precision_casts_npu
```

- `lintrunner test/dynamo/test_compiler_bisector.py` -> `ok No lint issues.`

- NPU real hardware (Ascend 910B4):

```
python -m pytest test/dynamo/test_compiler_bisector.py -v
# 3 passed, 8 skipped
```

### Verification Report

| Hardware | Cases | Passed | Failed | Skipped | Result |
|----------|-------|--------|--------|---------|--------|
| CPU (no accelerator) | 11 collected | - | - | - | Collect-only; 11 items, device class now owns `test_emulate_precision_casts_npu` |
| NPU (Ascend 910B4) | 11 | 3 | 0 | 8 | `test_emulate_precision_casts_npu` passes (previously never executed on NPU); 8 skips are the `HAS_GPU`-guarded legacy class, expected |

Gate behavior verified both directions on NPU: with Triton installed all three tests in the device class run and pass; with Triton absent the class skips with `requires Triton`.

### Environment

| Item | Version |
|------|---------|
| CANN | 9.2.0 (GA) |
| driver | 26.1.1 |
| PyTorch | 2.16.0.dev20261029+cpu (nightly wheel, same day as trunk) |
| torch_npu | 2.16.0.dev20261029+git737bb43 (source build from master) |
| Python | 3.12.15 |
| triton-ascend | 3.6.0+git0cfb1708 |

## Dependencies

Part of the pytorch#191435 split series (pytorch#198353 ~ pytorch#198362); independent of its siblings, each moves one test method.

Pull Request resolved: pytorch#198357
Approved by: https://github.com/can-gaa-hou, https://github.com/lizhihai137, https://github.com/jansel
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…device_type_tests (pytorch#198356)

## Summary

Move `test_rng` out of the guard-skipped `TestCompilerBisector` class into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old `@unittest.skipIf(not HAS_GPU)` class guard.

Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the `instantiate_device_type_tests` scaffold already landed via pytorch#198361.

## Changes

`test/dynamo/test_compiler_bisector.py` (+38 -20):
1. Add `TestCompilerBisectorRNG(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`) containing the moved `test_rng`; the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by instantiation, and the Triton gate sits on the class (same pattern as pytorch#198357).
2. Instantiate with `except_for="cpu"` (per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix via `only_for`). `test_rng` relies on `torch._dynamo.utils.preserve_rng_state`, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU: `do_bisect` reports `eager` instead of `inductor`). Such devices now skip explicitly via `@skipPRIVATEUSE1` rather than being silently excluded from instantiation.

## Notes

- Generalizing `preserve_rng_state` via `torch.get_device_module(device)` would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate.
- Test IDs change from `TestCompilerBisector.test_rng` to per-device variants (`test_rng_cuda`, `test_rng_xpu`, `test_rng_npu` [skipped], ...). I checked the `test/dynamo_skips/` and `test/dynamo_expected_failures/` entries and the slow-test lists in `main`: nothing is keyed on the old `TestCompilerBisector.test_rng` name.

## Motivation

The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU = 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 test was skipped even where it can run. `instantiate_device_type_tests` gives each supported device its own variant, and `hw_classification` provides metadata for `--hw-classification` filtering.

## Test Plan

| Environment | Result |
|---|---|
| CPU (`env-pytorch-2.16-20261029-cpu`) | `pytest --collect-only -q` -> **11 tests collected** (the moved test no longer appears un-instantiated) |
| NPU (`env-pytorch-2.16-20261029-npu`, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0) | `test_rng_npu` is instantiated and **skips cleanly (0.009s)** via `@skipPRIVATEUSE1` instead of being silently absent |
| CUDA / XPU execution | covered by the ciflow trunk jobs |
| lint | `lintrunner` (includes in-tree TEST_LINTER): no issues |

Pull Request resolved: pytorch#198356
Approved by: https://github.com/lizhihai137, https://github.com/jansel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo module: tests/graph This label covers all test cases within the Graph sheet. open source topic: not user facing topic category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants