Skip to content

[Testcase Refactoring] Clean up old TestCompilerBisector class after device migrations - #198362

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/f10-oldclass-final
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/f10-oldclass-final

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Final leftover cleanup of the old TestCompilerBisector class in test/dynamo/test_compiler_bisector.py, split from #191435 (refactoring this file for out-of-tree accelerator support).

Scope reduced after rebase: the previously planned deletion of the seven still-present device-dependent tests and the HAS_GPU class-guard removal are dropped from this PR — several sibling move PRs in the series (#198354–#198360, #198359) are still open, so those deletions would drop coverage today ("must merge LAST" premise still unmet). They can be revisited once the remaining siblings land; the file will then be naturally clean without needing this PR to delete anything.

Changes (minimal remainder)

test/dynamo/test_compiler_bisector.py only (+6/−13):

  1. Rename test_ns → bisector_ns for clarity (a helper, not a test).
  2. Delete dead get_lib() and the Library import name (the only caller test_crossref uses the _scoped_library context manager).
  3. Slim tearDown to the remaining live cleanups.

Kept as-is (genuinely generic): test_pre_grad, test_crossref, test_eager_backend.

Test plan

python -m pytest test/dynamo/test_compiler_bisector.py -k "crossref or pre_grad or eager_backend" -v

Sibling series status

Merged: #198361 (test_bisect_run_debuginfo), #198358 (test_bad_lowering). Still open: #198354, #198355, #198356, #198357, #198359, #198360. This PR no longer depends on them for coverage reasons since the deletion part was dropped; it is safe to review/merge independently.

Notes

Part of the hardware-decoupling effort tracking RFC #189138. Split from #191435.

@pytorch-bot

pytorch-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

PR Status: draft

This PR is waiting for its author to mark it ready for review. Pre-review does not advance while the PR is a draft.

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 889b674 with merge base 0563a22 (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.

@pytorch-bot

pytorch-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@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
@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 25, 2026
@gavinwang269
gavinwang269 force-pushed the cb2/f10-oldclass-final branch 2 times, most recently from 396914d to 8466505 Compare September 28, 2026 08:58
@jansel

jansel commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 1m 5s —— View job


Don't merge this yet: on current main it deletes 7 GPU bisector tests that have not been re-added anywhere else.

PR Review: #198362

Summary

The PR removes the device-dependent tests, the dead get_lib(), and the HAS_GPU guard from the old TestCompilerBisector class, and renames test_ns to bisector_ns. The PR body says it depends on sibling migration PRs landing first. Only one of them has landed: #198361 (test_bisect_run_debuginfo). The branch is based on that state, so merging now loses test coverage.

Testing

  • 7 GPU tests would be deleted with no replacement. On origin/main and on this branch's base (be43976), TestCompilerBisectorDevice (test/dynamo/test_compiler_bisector.py:139) only contains test_bisect_run_debuginfo. The PR deletes these tests and nothing else in the tree re-adds them device-aware:

    • test_bad_decomp
    • test_joint_graph
    • test_rng
    • test_emulate_precision_casts
    • test_bad_lowering
    • test_bisect_pre_grad_graph
    • test_cudagraph_bisect_max

    If this merges before the sibling PRs, CUDA/XPU CI loses all coverage of the decomposition, joint-graph, RNG-fallback, emulate-precision-casts, lowering, pre-grad-graph and cudagraph bisect subsystems. Ways to fix:

    • Rebase onto the landed sibling PRs and link them in the description, or
    • Stack this with ghstack on top of them so it cannot merge first, or
    • Fold the removals into the PRs that re-add each test, so every test moves atomically.
  • The PR description lists test_bisect_run_debuginfo among the tests removed from the old class. It is not in the diff because [Testcase Refactoring] Make test_bisect_run_debuginfo device-agnostic via instantiate_device_type_tests #198361 already moved it. Please correct the description so reviewers can check the removals against the migrations.

Code Quality

  • The Lint failure in CI comes from these deletions, not from the rebase note in the description:

    • The removed tests leave behind top-level imports that are now unused at this head: contextmanager, import_module, torch._prims_common as utils, preserve_rng_state, and module-level config. config is unused because test_pre_grad imports it locally.
    • There are runs of 3-4 blank lines at lines 37-39, 77-79, 124-126 and 135-138.
    • There is no blank line between bisector_ns and def tearDown (line 30-31).

    Some of these imports come back into use once the sibling tests land, which is another reason to rebase on them. The blank-line problems need fixing either way.

Recommendation

Request Changes

Merging now permanently drops 7 GPU tests. After rebasing on the landed migration PRs, only the lint cleanup remains to fix.

@gavinwang269
gavinwang269 marked this pull request as draft September 30, 2026 02:52
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Follow-up on @claude's review (triggered by @jansel) — all three points confirmed and addressed:

  1. "Merging now drops 7 GPU tests": correct. This piece is the tail of the bisector split; the sibling move pieces ([Testcase Refactoring] Make test_bad_decomp device-agnostic via instantiate_device_type_tests #198354–[Testcase Refactoring] Split test_cudagraph_bisect_max into a CUDA-classified test class #198360) are all still open. I have converted this PR back to draft so it cannot be merged until every sibling has landed, and added an explicit dependency table to the description mapping each removed test to the PR that re-adds it device-aware. The description also no longer lists test_bisect_run_debuginfo among the removals — [Testcase Refactoring] Make test_bisect_run_debuginfo device-agnostic via instantiate_device_type_tests #198361 already moved it to main, as the review noted.

  2. Lint. Fixed: the five orphaned module-level imports (contextmanager, import_module, _prims_common as utils, preserve_rng_state, module-level config) are removed — each move sibling brings back exactly what it uses, so keeping them here would only re-add dead imports to the final state — and the 3-4 blank-line runs plus the bisector_ns/tearDown E301 are normalized. pycodestyle/ruff come back clean locally on this head.

  3. The inductor-cpu-test unstable shard failures are pre-existing inductor_aoti_fallback flakes (job marked unstable) in files this PR does not touch.

PTAL again once the chain ahead of this merges.

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
gavinwang269 force-pushed the cb2/f10-oldclass-final branch from f203644 to d507bcb Compare October 31, 2026 09:03
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
…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

Copy link
Copy Markdown
Contributor Author

Content migrated into #198360 at @can-gaa-hou's request (same file, and the two reviews would otherwise have to be re-run against each other). Closing here; the change is the second half of the commit on #198360, with the collection-count check (10 tests before and after) recorded on that thread.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Superseded by #198360, which now carries this cleanup as requested in review.

@github-project-automation github-project-automation Bot moved this from Backlog to Done in PyTorch Test Refactoring Nov 3, 2026
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
pytorchmergebot pushed a commit that referenced this pull request Nov 9, 2026
…antiate_device_type_tests (#198355)

## Summary

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 #191435 (refactoring this file for out-of-tree accelerator support).

## Changes

`test/dynamo/test_compiler_bisector.py` (+36 -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 base class itself is untouched here; the GENERIC declaration belongs to #198360 alone (review note).

## 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`, so this PR is a pure single-method move. Triton gating for `TestCompilerBisectorDevice` lives on the class-level `@unittest.skipIf(not has_triton(), ...)` decorator, the convention already used on `main`; a fully device-aware gate needs a Triton `Capability` in the registry (follow-up).

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

Rebased onto latest main after #198358 landed; the class-level Triton gate arrives with #198357 and this PR will inherit it on the next rebase.

## Dependencies

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

Pull Request resolved: #198355
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
…antiate_device_type_tests (pytorch#198355)

## Summary

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

## Changes

`test/dynamo/test_compiler_bisector.py` (+36 -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 base class itself is untouched here; the GENERIC declaration belongs to pytorch#198360 alone (review note).

## 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`, so this PR is a pure single-method move. Triton gating for `TestCompilerBisectorDevice` lives on the class-level `@unittest.skipIf(not has_triton(), ...)` decorator, the convention already used on `main`; a fully device-aware gate needs a Triton `Capability` in the registry (follow-up).

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

Rebased onto latest main after pytorch#198358 landed; the class-level Triton gate arrives with pytorch#198357 and this PR will inherit it on the next rebase.

## 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#198355
Approved by: https://github.com/lizhihai137, https://github.com/jansel
pytorchmergebot pushed a commit that referenced this pull request Nov 11, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor module: dynamo 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

None yet

Development

Successfully merging this pull request may close these issues.

5 participants