Skip to content

[Testcase Refactoring] Make _test_compiler_bisector_run_helper.py device-agnostic - #198353

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/p1-helper
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/p1-helper

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make test/dynamo/_test_compiler_bisector_run_helper.py device-agnostic by passing the device in explicitly: the parent test appends its instantiated device to the subprocess command line, the helper's test_fn(device) uses it for the tensor allocation, and the GPU_TYPE import is gone with its last user.

Split from #191435 (refactoring the compiler-bisector tests for out-of-tree accelerator support).

Changes (+5 -4, two files)

  • test/dynamo/_test_compiler_bisector_run_helper.py: test_fn() takes a device parameter, device=GPU_TYPE becomes device=device, __main__ passes sys.argv[1], and the GPU_TYPE import is removed.
  • test/dynamo/test_compiler_bisector.py: the test_bisect_run_debuginfo subprocess call passes device as the final command-line argument (one added line, per review).

Earlier revisions of the helper (an env-var + accelerator-probe design) were reverted entirely per review: keeping accelerator selection out of module globals and out of implicit environment state.

Test Plan

  • python test/dynamo/_test_compiler_bisector_run_helper.py cpu exits 1 (the bad decomposition still produces NaN through the compiled path), matching the in-process equivalent; the subprocess leg runs on the device shards.
  • pytest --collect-only test/dynamo/test_compiler_bisector.py: 11 tests, unchanged.
  • lintrunner clean on both files.

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

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

The PR makes test/dynamo/_test_compiler_bisector_run_helper.py device-agnostic:
the parent test now passes its `device` on the subprocess command line, and the
helper's `test_fn(device)` uses it in place of `GPU_TYPE`. Recommendation:
Approve. One non-blocking cleanup remains, and every maintainer request has been
addressed at HEAD.

Findings (1):

[minor] test/dynamo/test_compiler_bisector.py:217
Non-blocking: an env var is set but never read. The `patch.dict` at line 206
still sets `"TORCH_BISECT_TEST_DEVICE": device`, but nothing in the tree reads
that variable. The helper now gets the device from `sys.argv[1]`, and
torch/_inductor/compiler_bisector.py only reads TORCH_BISECT_BACKEND,
TORCH_BISECT_SUBSYSTEM and TORCH_BISECT_MAX. # 198361 added the variable for the
env-var design of this helper, and this PR dropped that design. Line 206 is
unchanged code, but this PR is what makes it permanently dead. If it stays, the
device has two channels and only one of them works, and a reader may assume the
helper still uses the env var. That is the kind of implicit state fffrog asked
to avoid, and the PR description says the PR removes it. Fix: delete line 206
and keep only TORCH_BISECT_BACKEND in the `patch.dict`.

Reviewed commit: dfeb275 (NOT the current head d510cba)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit d510cba with merge base efe07ed (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/p1-helper branch 2 times, most recently from c1d6072 to 83e9a48 Compare September 28, 2026 03:06
pytorchmergebot pushed a commit that referenced this pull request Oct 2, 2026
…tantiate_device_type_tests (#198358)

## Summary

Move `test_bad_lowering` from the `HAS_GPU`-guarded `TestCompilerBisector` into the existing device-instantiated `TestCompilerBisectorDevice` in `test/dynamo/test_compiler_bisector.py`, so it runs on out-of-tree accelerators instead of being skipped.

Split from #191435 (refactoring this file for out-of-tree accelerator support).

## Changes

`test/dynamo/test_compiler_bisector.py` (+19 -18):
- `test_bad_lowering` moves verbatim (body unchanged) into `TestCompilerBisectorDevice`, which `#198361` already set up and `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` instantiates; the hardcoded `device=GPU_TYPE` becomes the injected `device` argument.

## Motivation

The class guard `@unittest.skipIf(not HAS_GPU, ...)` treats `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`, so out-of-tree accelerators registered via `PrivateUse1` (e.g., Ascend NPU) skip the whole class even though this test only needs a generic accelerator. `instantiate_device_type_tests` with `except_for="cpu"` covers all registered non-CPU device types, and `hw_classification` metadata enables `--hw-classification` filtering.

## Notes

The shared scaffold (new class + instantiation) is already on `main` via #198361, so this PR is a pure single-method move. Triton gating keeps the existing device-blind `@unittest.skipIf(not has_triton(), ...)` convention already used by `test_bisect_run_debuginfo` on `main`; a fully device-aware gate needs a Triton `Capability` in the registry (follow-up).

## Test Plan

- CPU (`torch-2.15-cpu`, pytest --collect-only): 9 tests collected, identical to `main` baseline; `pytest -q` -> 9 skipped (guard unchanged on CPU).
- NPU real hardware (Ascend 910B4, CANN 9.1.0, `torch-2.15-npu`, triton-ascend): `pytest -k test_bad_lowering_npu` -> **1 passed** (previously this test never executed on NPU).
- `pycodestyle --select E3` clean; `ruff format --diff` shows no findings in the touched region.

## Dependencies

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

Pull Request resolved: #198358
Approved by: https://github.com/guilhermeleobas

@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

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

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "ciflow/trunk"

@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

The ciflow label(s) ciflow/trunk will be added, but CI won't be triggered until the workflows are approved (scroll to the bottom of this page).

Please ping one of the reviewers if you do not have access to approve and run workflows.

@janeyx99 janeyx99 added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 10, 2026

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

The PR makes test/dynamo/_test_compiler_bisector_run_helper.py device-agnostic: the parent test now passes its device on the subprocess command line, and the helper's test_fn(device) uses it in place of GPU_TYPE. Recommendation: Approve. One non-blocking cleanup remains, and every maintainer request has been addressed at HEAD.

⚪ 1 non-blocking finding

Non-blocking: an env var is set but never read. The patch.dict at line 206 still sets "TORCH_BISECT_TEST_DEVICE": device, but nothing in the tree reads that variable. The helper now gets the device from sys.argv\[1\], and torch/_inductor/compiler_bisector.py only reads TORCH_BISECT_BACKEND, TORCH_BISECT_SUBSYSTEM and TORCH_BISECT_MAX. # 198361 added the variable for the env-var design of this helper, and this PR dropped that design. Line 206 is unchanged code, but this PR is what makes it permanently dead. If it stays, the device has two channels and only one of them works, and a reader may assume the helper still uses the env var. That is the kind of implicit state fffrog asked to avoid, and the PR description says the PR removes it. Fix: delete line 206 and keep only TORCH_BISECT_BACKEND in the patch.dict.

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

@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 Nov 10, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@fffrog could you take another look? Your requested changes were against c68a19375f7; everything you asked for is implemented on the current head dfeb275ad4c, which you haven't seen yet:

  1. all earlier edits to test/dynamo/_test_compiler_bisector_run_helper.py reverted to their pre-PR state, then rebuilt per your recipe;
  2. test_fn() takes an explicit device parameter and GPU_TYPE is replaced by device inside the function;
  3. the GPU_TYPE import at the top of that file removed;
  4. the call site in test/dynamo/test_compiler_bisector.py passes device on the subprocess command line, matching your snippet exactly.

The PR is now +5/-4 across the two files (helper 4/4, bisector 1/0), and each of your four inline threads has been answered there and resolved since the head moved past them.

One thing this PR also needs from someone with permission: the CI workflows for this fork head have been sitting at action_required since 11-10 06:32 — pull, Lint, docs-build and BC Lint have never run on dfeb275ad4c, so no trunk coverage exists for it yet. If you could approve those runs while you are here, that would unblock the check gate as well.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Re-review request for the current head dfeb275.

All four points from @fffrog's review are implemented in dfeb275 exactly as requested: the helper file's earlier changes are reverted and rebuilt with test_fn(device) taking an explicit device parameter, GPU_TYPE (and its import) removed, and the call site in test/dynamo/test_compiler_bisector.py passing device as the extra argument to the subprocess.

Review re-requested — thanks!

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

SGTM

@fffrog fffrog moved this from Backlog to Ready for Merge in PyTorch Test Refactoring Nov 11, 2026
@fffrog fffrog added the module: tests/simple This label covers all the testcase that are very straightforward label Nov 11, 2026
…-agnostic via an explicit device argument

Summary

The run_debuginfo bisector test spawns this helper in a subprocess, and the
helper picked its device from the module-level GPU_TYPE global. Per review,
the device now arrives as an explicit argument: the instantiated test passes
its device on the subprocess command line, the helper reads sys.argv[1], and
the GPU_TYPE import is gone with its last user. The helper's own revision
history (a module-level probe) is fully reverted in favor of this shape,
keeping accelerator state out of globals.

Test Plan

- python test/dynamo/_test_compiler_bisector_run_helper.py cpu: exits 1
  (nan detected through the bad decomposition) exactly as the in-process
  equivalent; the subprocess leg itself runs on the device shards.
- pytest --collect-only test/dynamo/test_compiler_bisector.py: 11 tests,
  unchanged; lintrunner clean on both files.
@gavinwang269

gavinwang269 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

The recent consistently-failing CI job is not caused by this PR's changes; the PR diff is exactly what was reviewed.

  • The only consistent failure is macos-py3-arm64 / test (default, 1, 3, macos-m1-stable) on test/test_dynamic_shapes.py::TestPySymInt::test_guarding_hint_or_throw_float_hint0 (AssertionError: Expected an int or bool SymNode, got <class 'float'>), which is outside this PR's two changed files.
  • Root cause: the previous branch base carried [dynamic shapes] Don't truncate float expressions in guarding_hint_or_throw #202324, which main has since reverted (a68f1179481), so the branch was still carrying the reverted torch/fx changes and their test.
  • Rebased onto current main efe07ed21d8969e4ddb161dab0976ec28d3f4d57. The two changed files are byte-identical to the approved head dfeb275ad4c8, and the [dynamic shapes] Don't truncate float expressions in guarding_hint_or_throw #202324 content is dropped from the branch. New head: d510cba53a44c010d06a1673148b5ce26a8dd04d.

@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

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merege

@pytorch-bot

pytorch-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: argument command: invalid choice: 'merege' (choose from 'merge', 'revert', 'rebase', 'label', 'drci', 'review', 'triage', 'pre-review', 'lint', 'fix-lint', 'apply-lint', 'cherry-pick')

usage: @pytorchbot [-h]
                   
                   {merge,revert,rebase,label,drci,review,triage,pre-review,lint,fix-lint,apply-lint,cherry-pick}
                   ...

Try @pytorchbot --help for more info.

@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

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. module: tests/simple This label covers all the testcase that are very straightforward 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.

8 participants