Skip to content

[Testcase Refactoring] Make test_bisect_pre_grad_graph device-agnostic via instantiate_device_type_tests - #198359

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m6-bisect_pre_grad_graph
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:cb2/m6-bisect_pre_grad_graph

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

test/dynamo/test_compiler_bisector.py gated its accelerator tests with
@unittest.skipIf(not HAS_GPU, ...) and built tensors on the module-level GPU_TYPE,
so one import-time boolean decided the inventory for every device. The device-dependent
classes are now instantiated through
instantiate_device_type_tests(<cls>, globals(), except_for="cpu", allow_xpu=True) -- the
form test/inductor/test_selective_lowering.py and test/inductor/test_symm_mem_registry.py
already use -- each test takes device, and the Triton requirement is checked per device
with has_triton_for_device(self.device_type) instead of the process-wide HAS_GPU.
except_for rather than only_for because test/REVIEW.md Rule 4 forbids only_for on an
ACCELERATOR class.

Two things this revision deliberately does not carry, both because they landed elsewhere
first:

  • The per-device Triton probe is not re-implemented here. has_triton_for_device and its
    interface-level helper are already in torch/utils/_triton.py on main, together with the
    registry-contract, index-awareness and error-propagation cases in
    test/inductor/test_utils.py, so this file only consumes them.
  • Consequently only this test file is touched.

Measured on the base commit's tree: not run locally. The wheels available here predate the
has_triton_for_device that now lives on main, so importing this file against them would
test an environment that no longer matches the PR's base; the CI shards are the evidence
for execution, and the description claims nothing beyond what the code does.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @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 - OUTDATED (earlier commit) - Ready for human review:

The PR moves `test_bisect_pre_grad_graph` into the device-instantiated
`TestCompilerBisectorDevice` and replaces the host-wide `has_triton()`
decorators with a per-device `setUp` gate built on a new
`has_triton_for_device()`. Three problems remain: a compatibility gap in the
per-device path, a missing regression test for the no-argument aggregate path,
and an MTIA coverage drop nobody has signed off. Recommendation: Needs
Discussion.

Findings (3):

[minor] test/dynamo/test_compiler_bisector.py:383
Moving this test still drops MTIA coverage, and nobody has agreed to that. The
old `HAS_GPU` guard let MTIA through via `HAS_MTIA_AND_TRITON`, with `GPU_TYPE`
resolving to `mtia`. `common_device_type.py` has no MTIA test base (only CPU,
CUDA, Lazy, MPS, XPU, HPU and PrivateUse1), so no MTIA variant gets created now.
The PR description records the drop and the author asked @​ can-gaa-hou to
confirm, but nobody with maintainer access has answered. An earlier reply from
the author (4430799618) said MTIA stays covered; that was wrong, and the author
later corrected it. Needed: sign-off from an MTIA or compiler-bisector owner, or
keep a `HAS_MTIA_AND_TRITON`-gated copy in the legacy class. Low confidence: I
could not confirm whether any MTIA CI job ran the old test.

[minor] torch/utils/_triton.py:295
The comment above says the hooks are called with no arguments so that
third-party interfaces still work when they override `is_triton_capable()` /
`raise_if_triton_unavailable()` without a `device` parameter.
`has_triton_for_device()` breaks that rule: it always passes a concrete device,
so it always takes the `device=` keyword path. An out-of-tree interface with a
no-argument override gets a `TypeError` out of `has_triton_for_device()`. In
`TestCompilerBisectorDevice.setUp` that shows up as an error rather than a skip,
on exactly the out-of-tree backends this series targets. The base class does
declare `device`, so either accept that contract on both paths and drop the
compatibility claim from the comment, or use the same fallback here: retry with
no arguments on `TypeError`, or treat the device as unsupported. Low confidence:
I could not check whether any out-of-tree interface (e.g. torch_npu's) actually
overrides these hooks without the parameter.

[minor] test/inductor/test_utils.py:1751
No test pins the behaviour the last round changed: the aggregate `has_triton()`
path must call `is_triton_capable()` and `raise_if_triton_unavailable()` with no
arguments. `_make_triton_interface` declares `device=None` on both hooks, and
`_run` never checks how they were called. So if someone goes back to forwarding
`device=None`, every existing test still passes. Fix: add a case to `_run` that
registers a `MagicMock` interface and asserts
`is_triton_capable.assert_called_once_with()` and
`raise_if_triton_unavailable.assert_called_once_with()`, mirroring
`test_for_device_forwards_index_to_capability_probe`.

Reviewed commit: a3f35d4 (NOT the current head 20908a7)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit 20908a7 with merge base 38a1839 (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/m6-bisect_pre_grad_graph branch 2 times, most recently from c9ff297 to 3f7bd77 Compare September 28, 2026 08:56
@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 50s —— View job


Requesting changes: when test_bisect_pre_grad_graph moved into the device class it lost its Triton gate, and the lint job is failing on blank lines at the new insertion point.

Full review

PR Review: #198359

Summary

This PR moves test_bisect_pre_grad_graph out of TestCompilerBisector, which is guarded by HAS_GPU, and into the device-generic TestCompilerBisectorDevice. The test uses the injected device instead of GPU_TYPE. Two problems:

  • The moved test has no Triton skip.
  • The PR description doesn't match the diff. It says the PR adds the class scaffold (imports, TestCompilerBisectorDevice, and the instantiate_device_type_tests call). Those already exist on main. The only change here is moving one method.

Infrastructure

  • Missing Triton gate (test/dynamo/test_compiler_bisector.py:372-378). The description says "The Triton requirement stays gated by a device-blind @unittest.skipIf(not has_triton(), "requires Triton")", but the moved test has no such decorator. Before this PR, the Triton requirement came from the class-level @unittest.skipIf(not HAS_GPU, "requires GPU and Triton"). That guard doesn't apply to TestCompilerBisectorDevice, so the test now has no gate at all.
    • The test needs Triton. It relies on config.patch("triton.inject_relu_bug_TESTING_ONLY", "accuracy") in Inductor's Triton codegen to produce the mismatch that the bisector finds.
    • Without Triton, the test gets instantiated for every non-CPU device. It then errors, or fails the out.backend == "inductor" / subsystem == "pre_grad_graph" asserts, instead of skipping.
    • Fix: add @unittest.skipIf(not has_triton(), "requires Triton") above the @config.patch(...), matching test_bisect_run_debuginfo at line 336.
    • Fix this →

Code Quality

  • Blank lines (test/dynamo/test_compiler_bisector.py:371-372 and :424-426). There is no blank line between test_bisect_run_debuginfo and the moved method, and there are three blank lines before instantiate_device_type_tests(...). These are the two lines behind the failing lintrunner-noclang-partial job (FLAKE8 E301 and PYFMT). Running lintrunner -a fixes both.

Recommendation

Request Changes

Restore the Triton skip so the test's previous gating still holds on the device-generic class. Then fix the blank lines and update the PR description to say this PR only moves the method.

@gavinwang269
gavinwang269 force-pushed the cb2/m6-bisect_pre_grad_graph branch from 3f7bd77 to 0b057b8 Compare September 29, 2026 08:39
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Agreed on the Triton gate — added @unittest.skipIf(not has_triton(), ...): the bisected bug is injected via triton.inject_relu_bug_TESTING_ONLY, so the test is only meaningful when Triton is available (matches the sibling test_bad_lowering move). Blank lines fixed as well. Test Plan updated with this PR's own numbers (CPU 9 skipped; NPU test_bisect_pre_grad_graph_npu 1 passed on Ascend 910B4). New head 0b057b8. 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]>
self.assertIn(expected_result, output.stdout)

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Before modification, the feature in Triton belonged to the class level, but now it is refined to the test case level. If all test cases require it, it can remain consistent with the previous approach and be placed at the class level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same story as #198357: the class-level Triton gate lands there; after it merges, this PR rebases onto main and inherits the class-level decorator. The current method-level gate (09c3138) is a transitional state from resolving the rebase with #198358 bad_lowering landing on main. NPU real-hardware run: test_bisect_pre_grad_graph_npu passes (22.7s).

from torch.library import _scoped_library, Library
from torch.testing._internal.common_device_type import instantiate_device_type_tests
from torch.testing._internal.common_utils import HardwareClassification, requires_cuda
from torch.testing._internal.inductor_utils import GPU_TYPE, HAS_GPU

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the last PR, remember to delete information like GPU_TYPE, HAS_GP, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed: the GPU_TYPE/HAS_GPU imports drop in the cleanup PR #198362 once the last test leaves the legacy class.

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

@gavinwang269
gavinwang269 force-pushed the cb2/m6-bisect_pre_grad_graph branch from 0b057b8 to 09c3138 Compare October 31, 2026 03:46
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

The two findings from the latest automated review are addressed in 3a532a9:

  • The gate is now device-aware: the test body checks get_interface_for_device(device).is_triton_capable() and skips per instantiated device; the decorator keeps only the host-level package check (has_triton_package()). Verified on Ascend 910B4: test_bisect_pre_grad_graph_npu passes (30.6s) through the new gate.
  • MTIA: confirmed there is no MTIA device-type base in instantiate_device_type_tests, so coverage from the old HAS_MTIA_AND_TRITON admission is intentionally dropped; the incorrect comment is removed and the drop is now recorded in the PR description.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Ready for review of the current head (20908a771e3, rebased today from the head that passed the automated round with no blocking findings on 2026-10-31). The PR moves test_bisect_pre_grad_graph into the instantiated TestCompilerBisectorDevice class and lifts the per-device Triton capability query into production (has_triton_for_device in torch/utils/_triton.py, shared by has_triton() and the test gate); @lizhihai137 approved the pre-rebase head on 2026-10-31. A fresh automated round on this head is expected shortly. @jansel @aorenste could one of you take a look and land it if it reads well?

@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 Nov 5, 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

@github-project-automation github-project-automation Bot moved this from Backlog to Done in PyTorch Test Refactoring Nov 5, 2026
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 5, 2026
…ified class

Independent slice of the static-launcher split: moves test_global_scratch_allocation,
test_fast_launcher_rejects_global_scratch (skipIfRocm) and
test_rocm_rejects_global_scratch (ROCm-only) out of the unit class into
TestStaticTritonLauncherUnitRoCm, classified CUDA and intentionally not
instantiated (mock CUDA/ROCm-internal behavior duplicated across device classes
would be meaningless -- the shape flagged in pytorch#198359/pytorch#198360 review). Scratch-kernel
factory delegated by reference; nothing copied; no dependency on sibling slices.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 5, 2026
… into its own CUDA-classified class

First independent slice of the static-launcher split (per pytorch#198436 review: the
unit class mixes device-gated tests with a GENERIC label; original monolith
pytorch#198437 at 505 lines). Moves test_tensor_memory_autotuner_retries_without_pipelining
(CUDAAutotuner + StaticallyLaunchedCudaKernel internals, Triton-gated and RoCm-
skipped) into a new CUDA-classified class TestStaticTritonLauncherUnitCuda -- not
instantiated, since running CUDA-internal mock behavior under XPU/PrivateUse1
class variants would produce meaningless duplicates (the shape flagged in
pytorch#198359/pytorch#198360 review). Shared helpers stay on the unit class, delegated by
reference (staticmethod-wrapped); nothing is copied.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 6, 2026
… into its own CUDA-classified class

First independent slice of the static-launcher split (per pytorch#198436 review: the
unit class mixes device-gated tests with a GENERIC label; original monolith
pytorch#198437 at 505 lines). Moves test_tensor_memory_autotuner_retries_without_pipelining
(CUDAAutotuner + StaticallyLaunchedCudaKernel internals, Triton-gated and RoCm-
skipped) into a new CUDA-classified class TestStaticTritonLauncherUnitCuda -- not
instantiated, since running CUDA-internal mock behavior under XPU/PrivateUse1
class variants would produce meaningless duplicates (the shape flagged in
pytorch#198359/pytorch#198360 review). Shared helpers stay on the unit class, delegated by
reference (staticmethod-wrapped); nothing is copied.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 6, 2026
…ified class

Independent slice of the static-launcher split: moves test_global_scratch_allocation,
test_fast_launcher_rejects_global_scratch (skipIfRocm) and
test_rocm_rejects_global_scratch (ROCm-only) out of the unit class into
TestStaticTritonLauncherUnitRoCm, classified CUDA and intentionally not
instantiated (mock CUDA/ROCm-internal behavior duplicated across device classes
would be meaningless -- the shape flagged in pytorch#198359/pytorch#198360 review). Scratch-kernel
factory delegated by reference; nothing copied; no dependency on sibling slices.
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…c via instantiate_device_type_tests (pytorch#198359)

`test/dynamo/test_compiler_bisector.py` gated its accelerator tests with
`@unittest.skipIf(not HAS_GPU, ...)` and built tensors on the module-level `GPU_TYPE`,
so one import-time boolean decided the inventory for every device. The device-dependent
classes are now instantiated through
`instantiate_device_type_tests(<cls>, globals(), except_for="cpu", allow_xpu=True)` -- the
form `test/inductor/test_selective_lowering.py` and `test/inductor/test_symm_mem_registry.py`
already use -- each test takes `device`, and the Triton requirement is checked per device
with `has_triton_for_device(self.device_type)` instead of the process-wide `HAS_GPU`.
`except_for` rather than `only_for` because `test/REVIEW.md` Rule 4 forbids `only_for` on an
ACCELERATOR class.

Two things this revision deliberately does not carry, both because they landed elsewhere
first:

- The per-device Triton probe is not re-implemented here. `has_triton_for_device` and its
  interface-level helper are already in `torch/utils/_triton.py` on main, together with the
  registry-contract, index-awareness and error-propagation cases in
  `test/inductor/test_utils.py`, so this file only consumes them.
- Consequently only this test file is touched.

Measured on the base commit's tree: not run locally. The wheels available here predate the
`has_triton_for_device` that now lives on main, so importing this file against them would
test an environment that no longer matches the PR's base; the CI shards are the evidence
for execution, and the description claims nothing beyond what the code does.

Pull Request resolved: pytorch#198359
Approved by: https://github.com/lizhihai137, https://github.com/jansel
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 16, 2026
…mpileResult

Responds to the automated CHANGES_REQUESTED review on pytorch#198438.

Blocking (test/REVIEW.md Rules 1/2): test_oversized_shared_mem_mm_template and
test_basic_compile_pdl are CUDA-only (the former reads CUDA device properties
and builds a CUDAMMTemplateConfigHeuristic; the latter gates on SM90OrLater and
PDL, supported only by StaticallyLaunchedCudaKernel), so they move to a new
TestCudaStaticTritonCompileResult (hw_classification CUDA, instantiated
only_for=("cuda",)), following the merged pytorch#198440 split of
TestFastLauncherCompileResult in this file. The rebase-introduced "!= cuda"
body guard and skipIfXpu are superseded by the CUDA-only instantiation:
filter_desired_device_types normalizes out-of-tree backend names to
"privateuse1", which only_for drops, so the class is never instantiated for
PrivateUse1 and the torch.cuda reads happen only on cuda. That also resolves
the crash the guard was introduced for in the sibling pytorch#198437 rebase (a
PrivateUse1 variant raising in torch.cuda.current_device() instead of
skipping): with the tests out of the except_for="cpu" class no other
accelerator instantiates them, and the shared per-device setUp gates skip
before the body runs even if PYTORCH_TESTING_DEVICE_FOR_CUSTOM opts a
PrivateUse1 base into the CUDA class.

Non-blocking: the eight host-wide unittest.skipIf(not has_triton()) decorators
and the missing gate on test_basic_compile_pdl are replaced by one
has_triton_for_device check plus an is_registered_static_launch_device check
in the shared _StaticTritonCompileResultMixin setUp, placed before the config
patch is entered (tearDown does not run when setUp raises), following pytorch#198359;
test_disable_static_triton_launcher is exempt from the registration gate
because it runs with the launcher off, where strict mode raising
CannotStaticallyLaunchKernel was the other failure mode.
test_custom_op_bad_fake_dtype_fails_fast stays in the ACCELERATOR class; its
host-wide skipIfXpu becomes skipXPUIf from common_device_type (Rule 4), which
no longer skips the CUDA variant on TEST_XPU hosts, with a reason that no
longer claims the dtype check is CUDA launcher-specific (it comes from the
generic assert_tensor_metadata wrapper codegen); the XPU exclusion is kept
because the fail-fast path has never been verified there (Rule 6). skipIfRocm
moves with the two tests into the CUDA class, where Rule 5 adds no
requirements, and SM90OrLater keeps its decorator for the same reason. Stale
"static cuda launcher" wording in the class docstring and the disable-test
comment is corrected.

Test Plan: no working torch environment on the machine that prepared this
commit, so verification was static:

```
python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
```

plus AST checks of final class membership (ACCELERATOR keeps the seven device-agnostic tests; the CUDA class holds only the two moved tests), line-length and ASCII checks on changed lines, and grep of the instantiate wiring. CI exercises the CUDA variants of both classes.

Authored with AI assistance and reviewed by the PR owner before submission.

Co-Authored-By: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 16, 2026
…skip leak

Root cause of the blocker: instantiate_device_type_tests registers each test
under a device-suffixed name (e.g.
test_disable_static_triton_launcher_cuda) and deletes the generic names, so
comparing _testMethodName for equality against the generic name could never
fire, and the static-launcher registry gate also skipped on devices without a
registered launcher -- the out-of-tree accelerator case this PR targets.
Match on prefix instead.

The gates also move before super().setUp(): tearDown never runs when setUp
raises SkipTest, so skipping after the base setUp leaked the Dynamo trace_log
NullHandler and the check_sparse_tensor_invariants flag; gate-before-super
also matches the merged pytorch#198359 pattern in test_compiler_bisector.py. The
manual __enter__/__exit__ config-patch pair becomes enterContext (precedent:
test_nested_reduction.py), whose cleanup runs even when setUp raises, so the
mixin tearDown goes away.

TestCudaStaticTritonCompileResult gains a device_type != "cuda" skip (Rule 5
permits it in CUDA-classified classes): PYTORCH_TESTING_DEVICE_FOR_CUSTOM
re-adds matching device bases after only_for is applied, so the CUDA class
could still get a PrivateUse1 variant whose oversized-shared-memory test
would read torch.cuda device properties instead of skipping.

Test Plan: no working torch environment on the machine that prepared this
commit, so verification was static:

```
python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
```

plus grep of the class/instantiate wiring and line-length/ASCII checks on
changed lines. pytest --collect-only could not run (torch import broken). CI
exercises the CUDA variants of both classes.

Authored with AI assistance and reviewed by the PR owner before submission.

Co-Authored-By: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 17, 2026
…mpileResult

Responds to the automated CHANGES_REQUESTED review on pytorch#198438.

Blocking (test/REVIEW.md Rules 1/2): test_oversized_shared_mem_mm_template and
test_basic_compile_pdl are CUDA-only (the former reads CUDA device properties
and builds a CUDAMMTemplateConfigHeuristic; the latter gates on SM90OrLater and
PDL, supported only by StaticallyLaunchedCudaKernel), so they move to a new
TestCudaStaticTritonCompileResult (hw_classification CUDA, instantiated
only_for=("cuda",)), following the merged pytorch#198440 split of
TestFastLauncherCompileResult in this file. The rebase-introduced "!= cuda"
body guard and skipIfXpu are superseded by the CUDA-only instantiation:
filter_desired_device_types normalizes out-of-tree backend names to
"privateuse1", which only_for drops, so the class is never instantiated for
PrivateUse1 and the torch.cuda reads happen only on cuda. That also resolves
the crash the guard was introduced for in the sibling pytorch#198437 rebase (a
PrivateUse1 variant raising in torch.cuda.current_device() instead of
skipping): with the tests out of the except_for="cpu" class no other
accelerator instantiates them, and the shared per-device setUp gates skip
before the body runs even if PYTORCH_TESTING_DEVICE_FOR_CUSTOM opts a
PrivateUse1 base into the CUDA class.

Non-blocking: the eight host-wide unittest.skipIf(not has_triton()) decorators
and the missing gate on test_basic_compile_pdl are replaced by one
has_triton_for_device check plus an is_registered_static_launch_device check
in the shared _StaticTritonCompileResultMixin setUp, placed before the config
patch is entered (tearDown does not run when setUp raises), following pytorch#198359;
test_disable_static_triton_launcher is exempt from the registration gate
because it runs with the launcher off, where strict mode raising
CannotStaticallyLaunchKernel was the other failure mode.
test_custom_op_bad_fake_dtype_fails_fast stays in the ACCELERATOR class; its
host-wide skipIfXpu becomes skipXPUIf from common_device_type (Rule 4), which
no longer skips the CUDA variant on TEST_XPU hosts, with a reason that no
longer claims the dtype check is CUDA launcher-specific (it comes from the
generic assert_tensor_metadata wrapper codegen); the XPU exclusion is kept
because the fail-fast path has never been verified there (Rule 6). skipIfRocm
moves with the two tests into the CUDA class, where Rule 5 adds no
requirements, and SM90OrLater keeps its decorator for the same reason. Stale
"static cuda launcher" wording in the class docstring and the disable-test
comment is corrected.

Test Plan: no working torch environment on the machine that prepared this
commit, so verification was static:

```
python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
```

plus AST checks of final class membership (ACCELERATOR keeps the seven device-agnostic tests; the CUDA class holds only the two moved tests), line-length and ASCII checks on changed lines, and grep of the instantiate wiring. CI exercises the CUDA variants of both classes.

Authored with AI assistance and reviewed by the PR owner before submission.

Co-Authored-By: gavinwang269 <[email protected]>
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 17, 2026
…skip leak

Root cause of the blocker: instantiate_device_type_tests registers each test
under a device-suffixed name (e.g.
test_disable_static_triton_launcher_cuda) and deletes the generic names, so
comparing _testMethodName for equality against the generic name could never
fire, and the static-launcher registry gate also skipped on devices without a
registered launcher -- the out-of-tree accelerator case this PR targets.
Match on prefix instead.

The gates also move before super().setUp(): tearDown never runs when setUp
raises SkipTest, so skipping after the base setUp leaked the Dynamo trace_log
NullHandler and the check_sparse_tensor_invariants flag; gate-before-super
also matches the merged pytorch#198359 pattern in test_compiler_bisector.py. The
manual __enter__/__exit__ config-patch pair becomes enterContext (precedent:
test_nested_reduction.py), whose cleanup runs even when setUp raises, so the
mixin tearDown goes away.

TestCudaStaticTritonCompileResult gains a device_type != "cuda" skip (Rule 5
permits it in CUDA-classified classes): PYTORCH_TESTING_DEVICE_FOR_CUSTOM
re-adds matching device bases after only_for is applied, so the CUDA class
could still get a PrivateUse1 variant whose oversized-shared-memory test
would read torch.cuda device properties instead of skipping.

Test Plan: no working torch environment on the machine that prepared this
commit, so verification was static:

```
python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
```

plus grep of the class/instantiate wiring and line-length/ASCII checks on
changed lines. pytest --collect-only could not run (torch import broken). CI
exercises the CUDA variants of both classes.

Authored with AI assistance and reviewed by the PR owner before submission.

Co-Authored-By: gavinwang269 <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Nov 18, 2026
…stic via instantiate_device_type_tests (#198438)

## Summary

Make `TestStaticTritonCompileResult` device-agnostic via `instantiate_device_type_tests`,
and move its CUDA-only tests to a new `TestCudaStaticTritonCompileResult`.

Split from #192893 (refactoring `test/inductor/test_static_triton_launcher.py` for
out-of-tree accelerator support), one test class per PR so each piece is independent.

## Changes

`test/inductor/test_static_triton_launcher.py`:
- `TestStaticTritonCompileResult` (`hw_classification = ACCELERATOR`, :1410) keeps the seven
  device-agnostic tests and is instantiated `except_for="cpu", allow_xpu=True` (:2179-2181).
  The class-level `@requires_gpu_and_triton` decorator is gone: Triton availability is now
  checked per device in the shared setUp.
- `test_oversized_shared_mem_mm_template` and `test_basic_compile_pdl` are CUDA launcher
  features (silent recompile with `num_stages=1` on oversized shared memory; PDL via
  `StaticallyLaunchedCudaKernel`), so they move to `TestCudaStaticTritonCompileResult`
  (`hw_classification = CUDA`, :1548), instantiated `only_for=("cuda",)` (:2182-2184) —
  following the merged #198440 split of `TestFastLauncherCompileResult` in this same file,
  including the shared-mixin shape (`_StaticTritonCompileResultMixin` :1384 mirrors
  `_FastLauncherCompileMixin`).
- The mixin setUp (:1393-1407) runs both device gates before `super().setUp()` — a test
  skipped in setUp never reaches tearDown, so the base classes' setUp state must not be
  reached first (pattern per #198359, `test/dynamo/test_compiler_bisector.py:145-148`):
  `has_triton_for_device(self.device_type)` (:1394), and `is_registered_static_launch_device(self.device_type)`
  (:1401), which exempts `test_disable_static_triton_launcher` by name prefix (:1398,
  `instantiate_device_type_tests` registers device-suffixed names such as
  `test_disable_static_triton_launcher_cuda`) because that test runs with the launcher off
  and would otherwise hit `strict_static_triton_launcher` raising instead of skipping on
  unregistered devices. The config patch
  `{"use_static_triton_launcher": True, "strict_static_triton_launcher": True}` moves from
  the class decorator into setUp via `self.enterContext(...)` (:1404-1407), whose cleanup
  runs even when setUp raises.
- `TestCudaStaticTritonCompileResult.setUp` additionally skips non-`cuda` device types
  (:1555-1561): `PYTORCH_TESTING_DEVICE_FOR_CUSTOM` re-adds matching device bases after
  `only_for` is applied (`common_device_type.py:1251-1253, 1284-1287`), so without this the
  oversized-shared-memory test could get a PrivateUse1 variant reading `torch.cuda` device
  properties.
- `test_custom_op_bad_fake_dtype_fails_fast` stays in the ACCELERATOR class; its host-wide
  `@skipIfXpu` becomes `@skipXPUIf(True, ...)` (:1471), which targets the XPU instantiation
  instead of any TEST_XPU host (Rule 4), with a corrected reason: the fail-fast dtype check
  comes from the generic `assert_tensor_metadata` wrapper codegen, not a CUDA launcher path.
  The exclusion stands because the path has never run on XPU (Rule 6); happy to un-skip in a
  follow-up once verified there.

## Notes

- This PR is self-contained: it adds the three imports its classes need (`skipXPUIf`,
  `has_triton_for_device`, `is_registered_static_launch_device`); the
  `instantiate_device_type_tests` / `HardwareClassification` scaffold already lands with
  #198440 in the same file. Sibling pieces of this split touch only their own classes; where
  both append `instantiate_device_type_tests(...)` calls at the file end, resolution is a
  one-line keep-both.
- MTIA coverage: previously `GPU_TYPE`-gated classes could resolve to MTIA on MTIA
  runners; no MTIA test base is registered here, so no MTIA variants are generated. A
  coverage note, not a regression on currently-tested devices.

## Motivation

The static Triton launcher tests are gated by `@requires_gpu_and_triton` / `GPU_TYPE`,
which only recognize in-tree devices (`cuda`/`mps`/`xpu`/`mtia`): out-of-tree accelerators
registered via `PrivateUse1` never run them. Migrating each class to
`instantiate_device_type_tests` + `hw_classification` makes the tests device-agnostic and
classifiable by `--hw-classification` filtering. The registry gate keeps the
strict-launcher config from turning a missing out-of-tree static launcher into an error for
the tests that need one, while still letting
`test_disable_static_triton_launcher` exercise the launcher-off path on every Triton-capable
device.

## Test Plan

| Environment | Result |
|---|---|
| CPU-only (`torch-2.15-cpu`) | At head `5ad9c394`: `pytest test/inductor/test_static_triton_launcher.py` collects 69 tests -> **22 passed / 45 skipped / 2 failed**, both failures reproducing identically on the unmodified main file (pre-existing); this class's instantiated variants collect zero on CPU-only, as designed (earlier branch-cut-base run: 8 passed / 26 skipped). |
| NPU (Ascend 910B4, CANN 9.1.0 GA, torch 2.14.0.dev + torch_npu 2.14 + triton-ascend 3.6.0) | variants exercised in #192893's full-file run (21/24; 3 failures tracked as accelerator limitations: uint64 zero_, fp64 isinf lowering, worker-thread config propagation) |

The review-fix heads `8ed07571` (CUDA-class split) and `1ff6807ef0` (setUp gate fixes)
were verified statically — `python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"`,
AST/grep checks of final class membership and instantiate wiring, line-length/ASCII checks on
changed lines — because no working torch environment is available on the machine that prepared
them. CI exercises the CUDA variants of both classes; the per-device gates skip cleanly
elsewhere.

Authored with AI assistance and reviewed by the PR owner before submission.

Rebase note (2026-11-16): #198440 landed in this file and gathered the `instantiate_device_type_tests` calls into a single trailing group; this PR's instantiation joins that group and its import lines dedup against main. Since the branch was cut, main also added `test_any` (already in device form) and `test_oversized_shared_mem_mm_template` to this class; the latter is converted here to the device-parameter form and now lives in the CUDA-only class. Re-verified on a CPU-only wheel at that point: the file collects 69 tests (22 passed / 45 skipped / 2 failed), both failures pre-existing on current main (reproduced identically on the unmodified main file); this class's instantiated variants collect zero on CPU-only, as designed. CUDA/NPU legs delegated to CI.

Rebase note (2026-11-17): rebased onto current main after #198439/#198440 merged; the three review-round commits were squashed into one (the mixin split plus the device-suffixed exemption/skip-ordering fixes from the final round are all in). Diff unchanged in substance: mixin + TestStaticTritonCompileResult instantiation, gates skip before super().setUp(), config patch via enterContext.

Pull Request resolved: #198438
Approved by: https://github.com/lizhihai137, https://github.com/jansel
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 18, 2026
… into its own CUDA-classified class

First independent slice of the static-launcher split (per pytorch#198436 review: the
unit class mixes device-gated tests with a GENERIC label; original monolith
pytorch#198437 at 505 lines). Moves test_tensor_memory_autotuner_retries_without_pipelining
(CUDAAutotuner + StaticallyLaunchedCudaKernel internals, Triton-gated and RoCm-
skipped) into a new CUDA-classified class TestStaticTritonLauncherUnitCuda -- not
instantiated, since running CUDA-internal mock behavior under XPU/PrivateUse1
class variants would produce meaningless duplicates (the shape flagged in
pytorch#198359/pytorch#198360 review). Shared helpers stay on the unit class, delegated by
reference (staticmethod-wrapped); nothing is copied.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 18, 2026
…ified class

Independent slice of the static-launcher split: moves test_global_scratch_allocation,
test_fast_launcher_rejects_global_scratch (skipIfRocm) and
test_rocm_rejects_global_scratch (ROCm-only) out of the unit class into
TestStaticTritonLauncherUnitRoCm, classified CUDA and intentionally not
instantiated (mock CUDA/ROCm-internal behavior duplicated across device classes
would be meaningless -- the shape flagged in pytorch#198359/pytorch#198360 review). Scratch-kernel
factory delegated by reference; nothing copied; no dependency on sibling slices.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 30, 2026
…ified class

Independent slice of the static-launcher split: moves test_global_scratch_allocation,
test_fast_launcher_rejects_global_scratch (skipIfRocm) and
test_rocm_rejects_global_scratch (ROCm-only) out of the unit class into
TestStaticTritonLauncherUnitCUDA (renamed from a RoCm-specific name since the
class is classified CUDA and its bodies exercise CUDA/ROCm launcher internals
through mocks), intentionally not instantiated (mock CUDA/ROCm-internal
behavior duplicated across device classes would be meaningless -- the shape
flagged in pytorch#198359/pytorch#198360 review). Scratch-kernel factory delegated by
reference; nothing copied; no dependency on sibling slices.

Test Plan:
```bash
python -m pytest test/inductor/test_static_triton_launcher.py --collect-only -q
# 24/60 tests collected, renamed class present
```
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
…ified class

Independent slice of the static-launcher split: moves test_global_scratch_allocation,
test_fast_launcher_rejects_global_scratch (skipIfRocm) and
test_rocm_rejects_global_scratch (ROCm-only) out of the unit class into
TestStaticTritonLauncherUnitCUDA (renamed from a RoCm-specific name since the
class is classified CUDA and its bodies exercise CUDA/ROCm launcher internals
through mocks), intentionally not instantiated (mock CUDA/ROCm-internal
behavior duplicated across device classes would be meaningless -- the shape
flagged in pytorch#198359/pytorch#198360 review). Scratch-kernel factory delegated by
reference; nothing copied; no dependency on sibling slices.

Test Plan:
```bash
python -m pytest test/inductor/test_static_triton_launcher.py --collect-only -q
# 24/60 tests collected, renamed class present
```

Co-Authored-By: Claude Code <[email protected]>
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: inductor 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