Skip to content

[Testcase Refactoring] Make test_bad_lowering device-agnostic via instantiate_device_type_tests - #198358

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m5-bad_lowering
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m5-bad_lowering

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

@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/198358

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

✅ You can merge normally! (4 Unrelated Failures)

As of commit 1243bfc with merge base be43976 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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
@janeyx99
janeyx99 requested review from fffrog and guilhermeleobas and removed request for fffrog September 25, 2026 18:25
@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/m5-bad_lowering branch 2 times, most recently from 5a50a79 to 753ab4d Compare September 28, 2026 08:56
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @guilhermeleobas — just a gentle ping for review on this device-agnostic refactor piece.

Context: the series was rebased onto the latest main after #198361 landed the shared scaffold, so this PR is now a pure method move (method body unchanged verbatim; only ownership moves into the instantiated device class). Diff is small and mechanical.

Series reference: #198354 ~ #198362 (one test method per PR, each kept small for review).

@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 59s —— View job


This PR moves test_bad_lowering into TestCompilerBisectorDevice without changing its logic. It needs a whitespace fix, which is also why lint is failing, and the PR description should be updated. Once both are done it's fine to merge.

Full review

PR Review: #198358

Summary

The PR moves test_bad_lowering out of the HAS_GPU-gated TestCompilerBisector and into the device-instantiated TestCompilerBisectorDevice. The only change to the test itself is that GPU_TYPE becomes the injected device. triton.inject_relu_bug_TESTING_ONLY is read in torch/_inductor/codegen/triton.py:1585, which works the same way for any Triton-capable device. So the test logic moves over correctly. Two problems remain: whitespace around the moved method, and a description that no longer matches the commit.

Code Quality

  • test/dynamo/test_compiler_bisector.py:406-425: the whitespace around the method is wrong in two places:

    • There is no blank line between the end of test_bisect_run_debuginfo (self.assertIn(expected_result, output.stdout)) and the new @unittest.skipIf(...) decorator.
    • There are three blank lines before instantiate_device_type_tests( where there should be two.

    This is the reason for the FLAKE8 E301 and PYFMT failure in lintrunner-noclang-partial. Running lintrunner -a (or spin fixlint) will fix it.

  • The PR description no longer matches the commit. The description says the PR "includes the new-class scaffold (imports, TestCompilerBisectorDevice, the instantiate_device_type_tests call)". The commit message says the scaffold already landed in [Testcase Refactoring] Make test_bisect_run_debuginfo device-agnostic via instantiate_device_type_tests #198361 and that this is a pure method move. The diff agrees with the commit message: it only adds and removes the method. Please update the description so the merged commit message is accurate.

Testing

  • Low confidence. @unittest.skipIf(not has_triton(), ...) gets its value once, when the module is imported, and it checks all registered device interfaces. If any one device is Triton-capable, the check passes for every instantiated device class. This includes HPUTestBase, which get_desired_device_type_test_bases adds automatically whenever TEST_HPU is true. So on a host with CUDA+Triton alongside a device that has no Triton backend, that device's variant runs and fails instead of being skipped. The PR description already notes this as a follow-up, and the sibling test_bisect_run_debuginfo has the same gate. It should be fixed across the whole series, for example by checking get_interface_for_device(device).is_triton_capable() inside the test, rather than in this PR only.

Recommendation

Request Changes. Fix the whitespace so lint passes, and update the PR description to match the commit.

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

Copy link
Copy Markdown
Contributor Author

Fixed the blank-line findings (E301 + extra blank before instantiate). Body updated: it now describes the actual diff — a pure method move with the scaffold already on main via #198361 — and the Test Plan reports this PR's own results (CPU 9 skipped; NPU test_bad_lowering_npu 1 passed on Ascend 910B4). New head 1243bfc. PTAL, thanks!

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]>
@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

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

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 1, 2, mt-l-x86iamx-8-64, unstable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 2, 2, mt-l-x86iamx-8-64, unstable)

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

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 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 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]>
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
…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
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 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants