Skip to content

[Testcase Refactoring] Make test_emulate_precision_casts device-agnostic via instantiate_device_type_tests - #198357

Closed
gavinwang269 wants to merge 2 commits into
pytorch:mainfrom
gavinwang269:cb2/m4-emulate_precision_casts
Closed

gavinwang269 wants to merge 2 commits into
pytorch:mainfrom
gavinwang269:cb2/m4-emulate_precision_casts

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

@pytorch-bot

pytorch-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

The PR moves test_emulate_precision_casts from the HAS_GPU-gated
TestCompilerBisector into the device-instantiated TestCompilerBisectorDevice,
and moves the has_triton() skip from each method up to the class.
Recommendation: Needs Discussion. Someone needs to explicitly decide that losing
MTIA coverage is acceptable, for this PR and the rest of the series, and the
description needs to mention the decorator move.

Findings (2):

[minor] test/dynamo/test_compiler_bisector.py:404
The test no longer runs on MTIA. This is still true at HEAD. Before, it ran
under the class guard HAS_GPU, which includes HAS_MTIA_AND_TRITON
(inductor_utils.py:82), so on an MTIA host GPU_TYPE was "mtia" and the test ran.
common_device_type.py has no MTIATestBase. When TEST_WITH_MTIA is set,
get_device_type_test_bases() (common_device_type.py:1028-1039) adds only
CPUTestBase in fbcode, because the `not TEST_WITH_MTIA` condition leaves out
CUDATestBase. except_for="cpu" then removes that CPU base, so an MTIA host gets
zero variants of this test. The landed siblings # 198361 and # 198358 made the
same trade, so this is really a question for the whole series, and neither those
PRs nor this description says so. Fix: either keep MTIA coverage (e.g. a
HAS_MTIA_AND_TRITON-gated variant until an MTIA device base exists), or state in
the PR that dropping MTIA coverage is intended and get the MTIA owners to agree.
(The review couldn't check offline whether any MTIA CI job actually runs this
file.)

[minor] test/dynamo/test_compiler_bisector.py:346
The PR description no longer matches the diff. It calls this "a pure
single-method move" and says it keeps the per-method @​ unittest.skipIf(not
has_triton(), ...) convention "already used by test_bisect_run_debuginfo". At
HEAD, the PR instead deletes that decorator from test_bisect_run_debuginfo and
test_bad_lowering and puts one on the TestCompilerBisectorDevice class. That
changes the gating for two tests the PR says it doesn't touch. The new behaviour
is equivalent: the generated per-device classes inherit __unittest_skip__ via
type(class_name, (base, generic_test_class), {}) at common_device_type.py:1289.
Still, the description and the "+23 -22" line count need updating so that
reviewers and the commit message describe what actually lands.

Reviewed commit: 502cef6

Review run

🔗 Helpful Links

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

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

✅ No Failures

As of commit 502cef6 with merge base 109544c (image):
💚 Looks good so far! There are no failures yet. 💚

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 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/m4-emulate_precision_casts branch 2 times, most recently from 078b27a to 82ca2de Compare September 28, 2026 08:55
@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 38s —— View job


The method move itself is correct, but a blank-line mistake at the insertion point is failing lint and has to be fixed before this can merge.

PR Review: #198357

Summary

This PR moves test_emulate_precision_casts from TestCompilerBisector (which is skipped unless HAS_GPU) into the device-instantiated TestCompilerBisectorDevice, and replaces GPU_TYPE with the injected device. The test body is unchanged apart from that. The only blocking problem is how the method was inserted, which is the cause of the lintrunner-noclang-partial failure.

Code Quality

  • test/dynamo/test_compiler_bisector.py:402-403: The new @unittest.skipIf(...) decorator comes straight after self.assertIn(expected_result, output.stdout) from test_bisect_run_debuginfo with no blank line between them (flake8 E301). After the new method, at :425-427, there are three blank lines before instantiate_device_type_tests( where there should be two (PYFMT diff). Add one blank line before the decorator and remove one after the method. lintrunner -a will fix both.

Testing

  • test/dynamo/test_compiler_bisector.py:403: has_triton() does not check which device the test is running on, so on a host with both CUDA/XPU and a PrivateUse1 backend that has no Triton support, the PrivateUse1 variant will run and fail instead of being skipped. The PR description already notes this as a follow-up, and test_bisect_run_debuginfo next to it uses the same guard, so this doesn't block the PR. Please link a tracking issue for the device-aware Triton gate so the whole series gets fixed in one place.

Recommendation

Request Changes: fix the blank lines so lint passes. After that the change is a straightforward mechanical move.

@gavinwang269
gavinwang269 force-pushed the cb2/m4-emulate_precision_casts branch from 82ca2de to 9a06110 Compare September 29, 2026 08:38
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Fixed the blank-line findings (blank line before the moved method, two blanks before instantiate_device_type_tests); pycodestyle --select E3 clean and ruff format has no findings in the touched region. Body Test Plan updated with the per-PR numbers (CPU 9 skipped; NPU test_emulate_precision_casts_npu 1 passed on Ascend 910B4). New head 9a06110. 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]>

@can-gaa-hou can-gaa-hou left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, please fix the conflict first

@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 Oct 9, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • Dynamo (guilhermeleobas, rtimpe, trichmo, hameerabbasi)
  • Testing (Temporarily used for test refactoring) (fffrog)
  • Metamates (aditvenk, AmesingFlank, angelayi, anshul-si, aorenste, ...)
  • Greenlight Review Bot (pytorchgreenlight)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @fffrog — this PR failed @pytorchbot merge only because the current approval (from can-gaa-hou) isn't in the merge-rule approver sets for test refactoring, not due to any CI failure.

It's the same mechanical move pattern as the already-landed siblings (#198361, #198358): test_emulate_precision_casts moves into the device-instantiated TestCompilerBisectorDevice class with GPU_TYPE replaced by the injected device, and the blank-line lint findings from @jansel's review are already fixed on the current head. The only remaining red checks are the pre-existing inductor_aoti_fallback (unstable) shard flakes in files this PR does not touch; the merge bot's rebase will re-run them.

Could you (or @guilhermeleobas, who approved the sibling #198358) drop an approval from a merge-rule-set so this can proceed? Re-triggering @pytorchbot merge right after. cc @jansel for visibility.

@gavinwang269
gavinwang269 force-pushed the cb2/m4-emulate_precision_casts branch from 9a06110 to 502cef6 Compare October 30, 2026 02:49

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of 502cef6: nothing blocking; ready for human review.

The PR moves test_emulate_precision_casts from the HAS_GPU-gated TestCompilerBisector into the device-instantiated TestCompilerBisectorDevice, and moves the has_triton() skip from each method up to the class. Recommendation: Needs Discussion. Someone needs to explicitly decide that losing MTIA coverage is acceptable, for this PR and the rest of the series, and the description needs to mention the decorator move.

⚪ 2 non-blocking findings

def test_emulate_precision_casts(self, device):

The test no longer runs on MTIA. This is still true at HEAD. Before, it ran under the class guard HAS_GPU, which includes HAS_MTIA_AND_TRITON (inductor_utils.py:82), so on an MTIA host GPU_TYPE was "mtia" and the test ran. common_device_type.py has no MTIATestBase. When TEST_WITH_MTIA is set, get_device_type_test_bases() (common_device_type.py:1028-1039) adds only CPUTestBase in fbcode, because the not TEST_WITH_MTIA condition leaves out CUDATestBase. except_for="cpu" then removes that CPU base, so an MTIA host gets zero variants of this test. The landed siblings # 198361 and # 198358 made the same trade, so this is really a question for the whole series, and neither those PRs nor this description says so. Fix: either keep MTIA coverage (e.g. a HAS_MTIA_AND_TRITON-gated variant until an MTIA device base exists), or state in the PR that dropping MTIA coverage is intended and get the MTIA owners to agree. (The review couldn't check offline whether any MTIA CI job actually runs this file.)


@unittest.skipIf(not has_triton(), "requires Triton")

The PR description no longer matches the diff. It calls this "a pure single-method move" and says it keeps the per-method @ unittest.skipIf(not has_triton(), ...) convention "already used by test_bisect_run_debuginfo". At HEAD, the PR instead deletes that decorator from test_bisect_run_debuginfo and test_bad_lowering and puts one on the TestCompilerBisectorDevice class. That changes the gating for two tests the PR says it doesn't touch. The new behaviour is equivalent: the generated per-device classes inherit unittest_skip via type(class_name, (base, generic_test_class), {}) at common_device_type.py:1289. Still, the description and the "+23 -22" line count need updating so that reviewers and the commit message describe what actually lands.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

@github-actions
github-actions Bot dismissed their stale review October 30, 2026 02:53

Withdrawn: the automated review of 502cef6 found nothing blocking.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 30, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • MPS (malfet, kurtamohler, jhavukainen, Isalia20)
  • Dynamo (guilhermeleobas, rtimpe, trichmo, hameerabbasi, riccardofelluga, ...)
  • ROCm (jeffdaily, jithunnair-amd, jgong5)
  • Testing (Temporarily used for test refactoring) (fffrog)
  • Metamates (aditvenk, andrewor14, angelayi, anshul-si, aorenste, ...)
  • Greenlight Review Bot (pytorchgreenlight)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@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

@github-project-automation github-project-automation Bot moved this from Backlog to Done in PyTorch Test Refactoring Nov 2, 2026
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
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
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
…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
…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 ready for review Automated review passed, ready for a final review by a maintainer. 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.

7 participants