Skip to content

[Testcase Refactoring] Make test_joint_graph device-agnostic via instantiate_device_type_tests - #198355

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m2-joint_graph
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m2-joint_graph

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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 [Testcase Refactoring] Split test_cudagraph_bisect_max into a CUDA-classified test class #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.

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

PR Status: Approved 🚀

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

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

This PR moves `test_joint_graph` from the `HAS_GPU`-gated `TestCompilerBisector`
into the device-instantiated `TestCompilerBisectorDevice`, so it also runs on
XPU and PrivateUse1 backends. Recommendation: Approve. Nothing blocks the
change, but the author should confirm the MTIA coverage question before merging.

Findings (1):

[minor] test/dynamo/test_compiler_bisector.py:391
(Low confidence, carried over from the earlier review and still unanswered) MTIA
hosts may lose this test. Before: `HAS_GPU` included `HAS_MTIA_AND_TRITON`
(`torch/testing/_internal/inductor_utils.py:76,82`) and the test ran on
`GPU_TYPE`, so it ran on MTIA+Triton hosts. After:
`instantiate_device_type_tests` has no MTIA test base. In fbcode with
`TEST_WITH_MTIA`, `get_device_type_test_bases` also deliberately leaves out
`CUDATestBase` (`common_device_type.py:1028-1037`). On those hosts no
`test_joint_graph_*` variant is created, and nothing reports the lost coverage.
The siblings moved in # 198361 already have the same gap, and this PR plus the
rest of the # 198353#198362 series makes it wider. Ask: confirm that MTIA CI
doesn't run this file. If it does, keep an MTIA path, e.g. leave an MTIA-only
copy under the old guard or add MTIA handling to the instantiation.

Reviewed commit: 82979b4 (NOT the current head 0f4b6c5)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit 0f4b6c5 with merge base 50d50e7 (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 requested a review from fffrog September 25, 2026 18:21
@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/m2-joint_graph branch 2 times, most recently from b4047eb to ebde5b1 Compare September 28, 2026 08:53
@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 0s —— View job


The code move itself is correct, but I'm recommending Request Changes: lint is failing on the moved method, and the PR description still describes adding the new test class, which is already on main.

PR Review: #198355

Summary

The PR moves test_joint_graph from the HAS_GPU-guarded TestCompilerBisector into the existing TestCompilerBisectorDevice, which instantiate_device_type_tests already creates for each device type. The move is correct. Two things need fixing before merge.

Code Quality

  • Lint is failing on the moved method. Two blank-line problems cause the failing lintrunner-noclang-partial job:
    • test/dynamo/test_compiler_bisector.py:388: there is no blank line between the end of test_bisect_run_debuginfo and the @unittest.skipIf on test_joint_graph (E301).
    • :425-427: there are three blank lines before instantiate_device_type_tests(...) where there should be two (PYFMT).
    • Run lintrunner -a to fix both.
  • The PR description doesn't match the diff. It says the PR "includes the new-class scaffold (imports, TestCompilerBisectorDevice, the instantiate_device_type_tests call)". Those already exist on main (from the earlier test_bisect_run_debuginfo migration). This diff only moves one method. Please update the description so reviewers and the eventual commit message are accurate. The NPU row in the test plan is also for the "whole refactor applied", not this PR alone.
  • :390: from torch._inductor import config inside the method is redundant, since the same module is already imported at file scope (:10). The method is being moved anyway, so drop it here.
  • :404: the uuid() string "TestCompilerBisector.test_joint_graph.pass_class" still names the old class. Rename it to TestCompilerBisectorDevice... so it stays unique and doesn't mislead readers.

Testing

  • The generated test IDs change from TestCompilerBisector.test_joint_graph to TestCompilerBisectorDevice.test_joint_graph_{cuda,xpu}. I found no disable or skip lists in the repo that use the old name. Anyone tracking the old ID on HUD should know it has been renamed. This is informational and doesn't block the PR.

Recommendation

Request Changes

The move is correct, but the lint failure must be fixed and the description corrected before merge.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Addressed the review:

  1. Blank line before the moved method and the blank count before instantiate_device_type_tests — fixed (E301/PYFMT); pycodestyle --select E3 is clean on the new head.
  2. PR description rewritten to match the diff — this is now a pure single-method move; the scaffold is already on main via [Testcase Refactoring] Make test_bisect_run_debuginfo device-agnostic via instantiate_device_type_tests #198361, and the Test Plan reflects the actual CPU (9 skipped) + NPU (test_joint_graph_npu 1 passed on Ascend 910B4) results for this PR alone.
  3. Dropped the redundant in-method from torch._inductor import config (file scope already imports it).
  4. Updated CustomPostPass.uuid() to name TestCompilerBisectorDevice.

Rebased head 3cb616f. 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]>
Comment thread test/dynamo/test_compiler_bisector.py Resolved
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 30, 2026
github-actions[bot]

This comment was marked as outdated.

@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 82979b4: nothing blocking; ready for human review.

This PR moves test_joint_graph from the HAS_GPU-gated TestCompilerBisector into the device-instantiated TestCompilerBisectorDevice, so it also runs on XPU and PrivateUse1 backends. Recommendation: Approve. Nothing blocks the change, but the author should confirm the MTIA coverage question before merging.

⚪ 1 non-blocking finding

def test_joint_graph(self, device):

(Low confidence, carried over from the earlier review and still unanswered) MTIA hosts may lose this test. Before: HAS_GPU included HAS_MTIA_AND_TRITON (torch/testing/_internal/inductor_utils.py:76,82) and the test ran on GPU_TYPE, so it ran on MTIA+Triton hosts. After: instantiate_device_type_tests has no MTIA test base. In fbcode with TEST_WITH_MTIA, get_device_type_test_bases also deliberately leaves out CUDATestBase (common_device_type.py:1028-1037). On those hosts no test_joint_graph_* variant is created, and nothing reports the lost coverage. The siblings moved in # 198361 already have the same gap, and this PR plus the rest of the # 198353#198362 series makes it wider. Ask: confirm that MTIA CI doesn't run this file. If it does, keep an MTIA path, e.g. leave an MTIA-only copy under the old guard or add MTIA handling to the instantiation.

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 31, 2026 03:56

Withdrawn: the automated review of 82979b4 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 31, 2026
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 8, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Command git -C /home/runner/work/pytorch/pytorch merge --squash __pull-request-198355__init__ returned non-zero exit code 1

Auto-merging test/dynamo/test_compiler_bisector.py
CONFLICT (content): Merge conflict in test/dynamo/test_compiler_bisector.py
Squash commit -- not updating HEAD
Automatic merge failed; fix conflicts and then commit the result.
Details for Dev Infra team

Raised by workflow job

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase --onto refs/remotes/origin/viable/strict f9ed292d232cd96bb2a88ec4ee89eb0a9d3ce5a4 pull/198355/head returned non-zero exit code 1

Rebasing (1/1)
Auto-merging test/dynamo/test_compiler_bisector.py
CONFLICT (content): Merge conflict in test/dynamo/test_compiler_bisector.py
error: could not apply a89323444cf... [Testcase Refactoring] Move test_joint_graph to device-agnostic class
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply a89323444cf... # [Testcase Refactoring] Move test_joint_graph to device-agnostic class

Raised by https://github.com/pytorch/pytorch/actions/runs/42486161524

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

`test/dynamo/test_compiler_bisector.py` (+39 -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 legacy `TestCompilerBisector` base class (retired once all methods have moved) now carries an explicit `hw_classification = HardwareClassification.ACCELERATOR` and a comment noting its import-time `HAS_GPU` gate; the declaration is identical to the sibling PR pytorch#198354 so the two branches converge.

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.

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 3 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

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 9, 2026
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 9, 2026
…ssified class

Summary

test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the
accelerator-wide TestCompilerBisector class. This moves it into a class of
its own, classified for CUDA and instantiated through
instantiate_device_type_tests.

With the move (and pytorch#198354/pytorch#198355 having landed), TestCompilerBisector
holds only device-agnostic tests, so it gains the GENERIC classification
and drops the import-time HAS_GPU gate along with the now-unused
GPU_TYPE/HAS_GPU and requires_cuda imports; @requires_cuda is not kept on
the CUDA class because the only_for="cuda" instantiation already answers
it. The dead get_lib()/test_ns scaffolding cleanup that an earlier revision
of this PR carried was dropped to keep the diff to the move itself.

Test Plan

- cpu-wheel venv (no GPU here): pytest --collect-only reports the same 10
  test IDs before and after; the CUDA leg runs on the hardware shards.
- lintrunner and the in-tree test linter clean on the file.
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
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 10, 2026
…ssified class

Summary

test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the
accelerator-wide TestCompilerBisector class. This moves it into a class of
its own, classified for CUDA and instantiated through
instantiate_device_type_tests.

With the move (and pytorch#198354/pytorch#198355 having landed), TestCompilerBisector
holds only device-agnostic tests, so it gains the GENERIC classification
and drops the import-time HAS_GPU gate along with the now-unused
GPU_TYPE/HAS_GPU and requires_cuda imports; @requires_cuda is not kept on
the CUDA class because the only_for="cuda" instantiation already answers
it. The dead get_lib()/test_ns scaffolding cleanup that an earlier revision
of this PR carried was dropped to keep the diff to the move itself.

Test Plan

- cpu-wheel venv (no GPU here): pytest --collect-only reports the same 10
  test IDs before and after; the CUDA leg runs on the hardware shards.
- lintrunner and the in-tree test linter clean on the file.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 11, 2026
…ssified class

Summary

test_cudagraph_bisect_max needs CUDA graphs, so it does not belong in the
accelerator-wide TestCompilerBisector class. This moves it into a class of
its own, classified for CUDA and instantiated through
instantiate_device_type_tests. With the move (and pytorch#198354/pytorch#198355 having
landed), TestCompilerBisector holds only device-agnostic tests, so it gains
the GENERIC classification and drops the import-time HAS_GPU gate along with
the now-unused GPU_TYPE/HAS_GPU and requires_cuda imports; the Triton gates
that remain become accelerator-aware @skipIf(..., device_type=...) forms, and
as the last PR touching this file the test-linter allowlist entry is removed.

Review-round decisions on pytorch#198360. The automated review noted that test_rng,
after losing @skipPRIVATEUSE1, now runs and fails on PrivateUse1/HPU and
asked to restore a skip via a setUp gate; the human maintainer instructed the
opposite on the same lines (discussion_r4533004167): expose the test to all
out-of-tree accelerators and let a backend that does not support it skip it
in its own instantiation rather than have upstream silently skip it. The
maintainer instruction wins: no upstream gate is added for other backends,
and the stale comment block claiming PrivateUse1 is "skipped explicitly" is
removed with nothing replacing it, so no comment asserts a skip that does not
happen. The measured consequence, stated plainly: on an Ascend 910B4
(torch_npu, triton-ascend installed) test_rng_npu now runs and fails because
preserve_rng_state (torch/_dynamo/utils.py) saves/restores only CPU, CUDA and
XPU RNG, so the eager and compiled draws diverge and do_bisect reports
backend="eager". Coverage delta is skip -> fail on backends that do not
preserve RNG state; the out-of-tree test suite is expected to opt out.

Style: the Triton gate on test_cudagraph_bisect_max drops the "xpu" entry per
the maintainer's suggestion (the class is instantiated only_for="cuda", so
the entry can never match). only_for="cuda" itself is kept: Rule 4's only_for
ban is scoped to ACCELERATOR classes, Rule 5 imposes no instantiation
requirements on CUDA-classified classes, and the in-tree linter's OnlyForRule
is registered for ACCELERATOR only (checked by running the linter plus a
deliberate-violation probe to confirm the finding fires where it should).

Test Plan

torch 2.16.0.dev20261029; the "cpu" venv autoloads torch_npu (registers
PrivateUse1), so CPU-only claims use TORCH_DEVICE_BACKEND_AUTOLOAD=0. All
pytest runs from /tmp with absolute paths.

CPU-only host, final state:

    TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest -q -rs test/dynamo/test_compiler_bisector.py
    -> collected 3 (test_pre_grad, test_crossref, test_eager_backend), 3 passed

so the 3 GENERIC tests run and pass on a GPU-less host now that the HAS_GPU
gate is gone. (Linux only; the macOS/Windows CPU shards are left to CI.)

Same file on a host with PrivateUse1 registered: collected 10 vs 11 for the
stock file; the moved test is not instantiated where no CUDA device type
exists (on CUDA builds it is
TestCompilerBisectorCudaCUDA.test_cudagraph_bisect_max_cuda). Whole file:

    python -m pytest -q -rs <file>   # final: 1 failed, 3 passed, 6 skipped
    python -m pytest -q -rs <stock>  # base commit version: 11 skipped, 0 failed

The one failure is TestCompilerBisectorRNGNPU.test_rng_npu with
AssertionError: String comparison failed: 'eager' != 'inductor', i.e. the
intended exposure above (stock skipped it via the class-level Triton gate on
this no-triton venv and via @skipPRIVATEUSE1 on the NPU machine); the 6 skips
are the pre-existing per-device "requires Triton on npu" gates.

NPU machine (8x Ascend 910B4, triton-ascend installed), final state:

    python -m pytest -q -rs test/dynamo/test_compiler_bisector.py -k test_rng
    -> 1 failed, 9 deselected

(the bisect leg diverges on RNG as above; the inductor leg additionally hits
a pre-existing torch_npu wheel codegen crash, reproduced with a plain
torch.compile of the same function and unrelated to this change). Pre-PR the
same command skips 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; a deliberate ACCELERATOR
       only_for violation makes it emit exactly the [only_for] finding)
    lintrunner test/dynamo/test_compiler_bisector.py tools/linter/adapters/test_linter_allowlist.json
    -> ok No lint issues.

Not covered here: the CUDA legs (no NVIDIA hardware on this host); the
upstream hardware shards run those.
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 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