Skip to content

[Testcase Refactoring] Declare TestStaticTritonLauncherUnit as a GENERIC hardware-classification class - #198436

Open
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:stl/p-unit
Open

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:stl/p-unit

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Declare TestStaticTritonLauncherUnit as a GENERIC hardware-classification class.

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:

  • TestStaticTritonLauncherUnit gets hw_classification = HardwareClassification.GENERIC:
    its tests run without any accelerator (pure unit checks of StaticallyLaunchedCudaKernel
    plumbing), so they must be selectable under --hw-classification generic and stay
    un-instantiated.

Notes

  • This PR is self-contained: it adds the module scaffold (import of instantiate_device_type_tests / HardwareClassification / has_triton) that its class needs, so it is testable standalone. Sibling pieces of this split touch only their own classes; where two pieces add the same import line, rebasing converges automatically, and where both append instantiate_device_type_tests(...) calls at the file end, resolution is a one-line keep-both.
  • This PR only imports HardwareClassification; it does not touch the other classes.

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.

Test Plan

Environment Result
CPU-only (torch-2.15-cpu) pytest test/inductor/test_static_triton_launcher.py -> 8 passed, 33 skipped — identical to main (no behavior change)
NPU (Ascend 910B4, CANN 9.1.0 GA, torch 2.14.0.dev + torch_npu 2.14 + triton-ascend 3.6.0) all 8 unit tests pass

ruff 0.14.4 (CI-pinned): check and format clean on this branch. This split is byte-for-byte convergent: merging all pieces of the split reproduces exactly #192893's final state.

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

Anchor note (updated 2026-11-17): this PR is the strict-last step of the split series and also deletes tools/linter/adapters/test_linter_allowlist.json's entry for the file, so TEST_LINTER runs in enforcement mode on the whole file at this PR's head. As pushed it reports 12 errors there - none in TestStaticTritonLauncherUnit, this PR's own class: 2 missing hw_classification declarations owned by #198437/#198438 and 10 device_param/only_for errors owned by #205277. That head lint failure is the expected pre-state of the merge-last ordering, not a regression introduced by this diff. Once all siblings land this PR is rebased onto main, where the same enforcement simulation reports zero errors for the file; it stays draft until then.

Linked issue or supporting maintainer

Part of #185590 (test case refactoring initiative) - hardware-decoupling slice.

@pytorch-bot

pytorch-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

PR Status: in progress

Please address review feedback on your PR either with a code/PR description change. If a review comment is irrelevant, react with 👎 on that specific comment to reject it, and leave a short reply explaining why. The change must pass any running CI and existing failures must be classified as unrelated (see status below in this comment).

Passing automated review does not guarantee that this PR will be merged. It still requires maintainer review and may be closed if its design or direction does not align with the project.

To minimize iteration time, feel free to run the pr-review skill from the repo locally. To trigger a fresh automated review, make a new push or comment @pytorchbot review. To bypass automated review, please add the "no automated review" label.

⚪ AUTOMATED REVIEW - Review did not complete:

reason: model_error

Reviewed commit: 4f1208f

Review run

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 4f1208f with merge base 270998c (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Sep 24, 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 24, 2026
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Sep 24, 2026
@gavinwang269
gavinwang269 marked this pull request as ready for review October 13, 2026 08:57
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 13, 2026
@soulitzer soulitzer added missing actionable issue A PR without a linked actionable issue or maintainer sponsor and removed missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Oct 15, 2026
@gavinwang269
gavinwang269 marked this pull request as draft October 30, 2026 08:34
@gavinwang269
gavinwang269 requested a review from fffrog November 5, 2026 04:03
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 5, 2026
…via instantiate_device_type_tests

Part of splitting pytorch#192893 (one class per PR, zero overlap).

Also splits the device-gated unit tests (Triton-gated autotuner retries + five ROCm-gated tests, with their shared _can_statically_launch helper) out of TestStaticTritonLauncherUnit into an instantiated ACCELERATOR TestStaticTritonLauncherUnitDevice, and lifts _global_scratch_kernel to module level, per pytorch#198436 review: what remains in the unit class is strictly device-independent. Base-vs-split parity verified on cpu wheel and NPU host (identical failing sets).
@gavinwang269
gavinwang269 marked this pull request as ready for review November 5, 2026 06:28
…RIC hardware-classification class

Part of splitting pytorch#192893 (one class per PR, zero overlap).

Last PR of the static-launcher split series: as the final step it also
drops the file's entry from tools/linter/adapters/test_linter_allowlist.json,
so the in-tree test linter runs in enforcement mode on the whole file once
the sibling slices (pytorch#198437, pytorch#198438, pytorch#198439, pytorch#198440, pytorch#203548, pytorch#203550,
pytorch#203551, pytorch#205277) have landed - each of which owns its own class region.
This PR is meant to merge strictly last.

Test Plan

- the Unit class body contains no accelerator API usage, so the GENERIC
  declaration is clean under the linter's AcceleratorApiRule (verified
  with the allowlist entry removed);
- with all sibling PRs applied, TEST_LINTER reports zero errors for the
  file in enforcement mode.
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @fffrog — re-review request for the current head 4f1208f3869e (just rebased onto main; the linter-allowlist conflict is resolved and the PR is mergeable again).

Recap of your "split it first" note on TestStaticTritonLauncherUnit (inline comment 4476406536): the six device-gated members are split out into the sibling PRs #203548, #203550, #203551 and #198437, which are still under review; this PR is deliberately designed to merge strictly last, once those land. What remains in the class here are the mock-only legs (CPU-runnable mock.Mock/SimpleNamespace plumbing over CUDA-flavored internals), and the class now declares hw_classification = HardwareClassification.GENERIC with its test_linter_allowlist.json entry dropped.

Nothing is left open on our side for this head — would you like to re-review when convenient, or would you prefer we hold the GENERIC declaration until the sibling splits merge?

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 20, 2026
… Triton device

Summary

Review feedback: test_launcher_keeps_module_owner_alive_until_release
builds fake kernel-owner and launcher objects, never touches the device
argument it receives, and only checks weakref/gc lifetime behavior, yet
it lived in TestStaticTritonLauncher, whose except_for="cpu"
instantiation and per-test Triton skip mean the ownership check cannot
run on a CPU-only shard.

Upstream has no host launcher test file yet, so move the test as-is
into TestStaticTritonLauncherUnit in the same file, the device-agnostic
unit class that already hosts the adjacent fake-owner lifetime checks,
and drop the unused device parameter and the Triton gate. The test body
is otherwise byte-identical.

Test Plan

- python -m py_compile on the patched file;
- in-tree test linter (tools/linter/adapters/test_linter.py) with the
  file's allowlist entry removed: 11 findings on the patched file,
  identical to the previous head (all pre-existing, attributed to
  pytorch#198436 Unit hw_classification declaration, pytorch#198438 and pytorch#205277),
  i.e. zero new violations from this move;
- AST scan: single definition of the moved test, no undefined names, no
  doubled decorators; gc/weakref/has_triton imports remain referenced
  elsewhere in the file;
- no built torch in this environment, so the moved test was not
  executed locally; as a device-less unit test it now runs in CI on CPU
  shards.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 20, 2026
… XPU-only launcher class

Summary

Two inline review items at bef2f7b:

TestStaticTritonLauncher gates its compile-on-device launcher cases with a
process-wide has_triton() skipIf, but the class is instantiated for multiple
backends, so a backend without Triton would still run these cases whenever
any other accelerator has Triton. Replace the thirteen per-test decorators
with one per-device gate in setUp using has_triton_for_device, the same
convention _StaticTritonCompileResultMixin already uses in this file; the
two compiling cases that carried no Triton gate (test_float_scalars,
test_bfloat16_scalar) are covered as a side effect, and skipping ahead of
super() keeps the mixin's XPU JITFunction patch from being applied.

The instantiate_device_type_tests call for TestStaticTritonLauncherXpuOnly
passed only_for="xpu" without allow_xpu, so no XPU class was ever emitted:
XPUTestBase joins the candidate bases only under allow_xpu=True, and the
filter then removed everything else. Pass allow_xpu=True, matching the
file's five other instantiations, so the restored XPU-only launcher tests
collect on XPU shards.

Test Plan

- python -m py_compile and ast.parse on the patched file.
- CPU wheel venv (torch 2.16.0.dev20261029+cpu, torch_npu installed so
  PrivateUse1=npu instantiates): module collection is 50 tests with no
  loader errors, unchanged from the pre-change head; the instantiated
  TestStaticTritonLauncherNPU test now skips via the new gate ("requires
  Triton on npu"); the device-free TestStaticTritonLauncherUnit result set
  is identical to the pre-change head (28 run, 23 pass, 3 skip, 2 known
  wheel-vs-trunk drift failures).
- allow_xpu verified against the helper with XPU availability simulated:
  get_desired_device_type_test_bases(only_for="xpu") returns no bases
  without allow_xpu and the xpu base with it; instantiating a dummy
  template with the new kwargs emits its XPU class while the old kwargs
  emit none. This host has no XPU hardware, so real XPU collection runs
  on the CI XPU shards.
- in-tree test linter (tools/linter/adapters/test_linter.py) with the
  file's allowlist entry removed: 11 findings on the patched file,
  identical to the previous head (all pre-existing, attributed to
  pytorch#198436 Unit hw_classification declaration, pytorch#198438 and pytorch#205277),
  i.e. zero new violations from these fixes.

Authored with the assistance of an AI coding assistant.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 24, 2026
Follow-up to @KarhouTam's review:

- test_float_scalars and test_bfloat16_scalar normalize the injected
  device via torch.device(device).type before get_interface_for_device,
  matching the class's other tests (a cuda:N/xpu:N value raised
  NotImplementedError);
- the two oversized-shared-memory tests move out of the ACCELERATOR
  class into a new CUDA-classified TestStaticTritonLauncherCudaOversized
  (they read torch.cuda.get_device_properties via
  _oversized_shared_mem_limits, which is accelerator-specific; the
  @skipIfXpu decorator plus body-level guard was the wrong shape);
- TestStaticTritonLauncher.setUp gains the same
  is_registered_static_launch_device(device_type) gate the
  compile-result mixin uses, so devices without a registered static
  launcher skip instead of raising;
- the unused module-level _global_scratch_kernel duplicate is deleted
  (every caller uses the unit-class staticmethod);
- TestStaticTritonLauncherXpuOnly drops the
  use_static_triton_launcher/strict config patch its tests never read.

Test Plan

- python -m py_compile;
- formatting scan of the changed regions: no module-level run of three
  or more blank lines, no trailing whitespace, no line over 120 columns;
- in-tree test linter with the file's allowlist entry removed: zero
  findings in the classes touched here (TestStaticTritonLauncher, the
  new TestStaticTritonLauncherCudaOversized, TestStaticTritonLauncherXpuOnly);
  the 11 remaining findings are pre-existing and attributed to pytorch#198436
  (the device-free Unit class's missing hw_classification) and pytorch#205277
  (TestFastLauncher device_param and instantiate_device_type_tests
  only_for) -- an identical findings set to the pre-fix head, reconfirmed
  by running the linter on this tree and on fe64feb.
pytorchmergebot pushed a commit to gavinwang269/pytorch that referenced this pull request Nov 26, 2026
…align hw classifications

Summary

Follow-up to pytorch#198439/pytorch#198440 for the fast-launcher classes, in
preparation for removing the file's test-linter allowlist entry:

- the eight tests in TestFastLauncher that still picked their device
  from the GPU_TYPE global (float/scalar/ABI families) now take the
  injected device parameter used by their siblings;
- TestFastLauncher and TestFastLauncherFallbackCompileResult are
  reclassified ACCELERATOR -> CUDA. Both classes only generate cuda
  and xpu variants (their instantiate calls, kept untouched, use
  only_for=("cuda","xpu")), and their extension selection requires
  _FastCudaLauncher/_FastXpuLauncher - a promise no PrivateUse1
  backend has signed. The ACCELERATOR label overpromised, and the
  test linter accordingly forbids only_for on ACCELERATOR classes.
  Once pytorch#204896 lands the tuple labels, the honest end state is
  (CUDA, XPU) and this classification follows suit;
- TestFastLauncherXpuOnly, the mixins and the CUDA-only compile
  class are unchanged.

Test Plan

- TEST_LINTER simulated with the file's allowlist entry removed: all
  ten errors owned by these two classes (eight device_param plus two
  only_for) clear; the remaining file errors belong to sibling PRs
  pytorch#198437/pytorch#198438/pytorch#198436;
- cpu-wheel venv: skip/pass profile consistent with the pristine
  base (wheel-vs-trunk drift artifacts reproduce identically);
  CUDA/XPU legs run on the respective CI shards.
pytorchmergebot pushed a commit that referenced this pull request Nov 26, 2026
…mixin helpers (#205277)

## Summary

Follow-up to #198439/#198440 for the fast-launcher classes: the `TestFastLauncher` tests build their launcher, stream and C extension from the injected `device` instead of the `GPU_TYPE` global.

An earlier version of this PR also relabeled `TestFastLauncher` and `TestFastLauncherFallbackCompileResult` from `ACCELERATOR` to `CUDA`. That relabel is reverted here: both classes are back at `ACCELERATOR`, which is what #198439/#198440 landed. Both classes generate cuda *and* xpu variants (`only_for=("cuda", "xpu")`, `allow_xpu=True`), and `get_hw_classification` reads the attribute with `getattr`, so a `CUDA` label is inherited by the generated XPU variants: on an XPU host `--hw-classification ACCELERATOR XPU` would drop these tests, and because the test linter checks nothing beyond the declaration on a device-specific class, the label hid the two `only_for` findings these classes produce instead of resolving them.

`CUDA` is still where these classes belong long term: their extension selection needs `_FastCudaLauncher`/`_FastXpuLauncher`, a promise no PrivateUse1 backend has signed, so `ACCELERATOR` overpromises. The label that says both is the tuple `(CUDA, XPU)` from #204896, which is open and still under discussion. Until that lands, `ACCELERATOR` plus this file's entry in `tools/linter/adapters/test_linter_allowlist.json` is the correct interim state, and **the allowlist entry has to stay**: an `ACCELERATOR` class may not pass `only_for`, so removing the entry before #204896 would fail the lint on those two findings. Removing this file's entry is therefore a follow-up after #204896, not part of this PR, and this PR does not touch the allowlist.

## Changes

One file, `test/inductor/test_static_triton_launcher.py`: 80 additions, 76 deletions against the base. No `hw_classification` line differs from the base after the revert, and the four `instantiate_device_type_tests` calls are untouched.

- `_FastLauncherMixin._fast_launcher_cls`, `_stream` and `_store_sum_launcher` take an optional `device` that defaults to `GPU_TYPE`; `_make_fast_launcher` forwards it. `TestFastLauncherXpuOnly` passes no device, so it keeps its current behavior.
- All 13 `TestFastLauncher` tests pass their injected device to the helpers they call, including the three `_make_launcher` calls that previously fell back to the global (`test_float_scalars`, `test_bfloat16_scalar`, `test_grid_2d`). `test_build_fast_launcher_launches` derives `device_props.type` from the injected device, which is the value `_build_fast_launcher` matches against `xpu`/`cuda`/`hip`.
- The `TestFastLauncherFallbackCompileResult` docstring says the behavior is shared by the CUDA and XPU fast launchers rather than by "every accelerator", which is what the `ACCELERATOR` label claims.

## Motivation

Part of #185590: tests should take their device from the instantiation machinery instead of a process-wide global, so the same class can be selected for more than one accelerator, and a hardware classification must describe the variants a class actually generates.

## Test Plan

Checked on a CPU-only host; the CUDA and XPU legs run on the respective CI shards.

Simulated the test linter over this file with its allowlist entry removed, by importing `tools/linter/adapters/test_linter.py` and clearing its `_allowlist` set (the allowlist file itself is unchanged in this PR):

- base: 13 findings. 8 `device_param` and 2 `only_for` belong to these two classes; the other 3 are `hw_classification` findings on `TestStaticTritonLauncherUnit`, `TestStaticTritonLauncher` and `TestStaticTritonCompileResult`, in class regions this PR does not touch (owned by #198436/#198437, and for the compile-result class a declaration that has since landed on main).
- the head before this round, with the `CUDA` labels: 3 findings, i.e. all 10 class-owned findings were gone, 8 of them from the device parameters and 2 from the label alone.
- the current head, `ACCELERATOR` plus full injection: 5 findings, the 2 `only_for` ones that the allowlist suppresses until #204896 plus those same 3.

So this PR clears 8 findings with the signatures, and the remaining 2 of its own are the ones only a tuple label can clear.

With the allowlist as it stands in CI today, the file reports nothing, using the same command lintrunner runs:

```
python3 tools/linter/adapters/test_linter.py -- test/inductor/test_static_triton_launcher.py
```

The RUFF and PYFMT adapters, invoked through `uv` the way `.lintrunner.toml` does and checked against planted violations first to confirm they are not no-ops, report nothing on this file.

```
python3 -I -m py_compile test/inductor/test_static_triton_launcher.py
python -m pytest --collect-only -q test_static_triton_launcher.py
```

The collection ran in the nightly cpu-wheel venv (`env-pytorch-2.16-20261029-cpu`), from outside the source tree so the wheel `torch` is the one imported: 60 tests collected, no errors, and the collected set is identical to the base and to the previous head. On a host with neither CUDA nor XPU, `instantiate_device_type_tests` generates no device-suffixed variants for these classes at all, so variant generation for `allow_xpu=True` rests on the untouched instantiate calls here and on the respective CI shards.

## Linked issue or supporting maintainer

Part of #185590 (test case refactoring initiative) - hardware-decoupling slice.

Pull Request resolved: #205277
Approved by: https://github.com/lizhihai137, https://github.com/jansel
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 26, 2026
…mixin helpers (pytorch#205277)

## Summary

Follow-up to pytorch#198439/pytorch#198440 for the fast-launcher classes: the `TestFastLauncher` tests build their launcher, stream and C extension from the injected `device` instead of the `GPU_TYPE` global.

An earlier version of this PR also relabeled `TestFastLauncher` and `TestFastLauncherFallbackCompileResult` from `ACCELERATOR` to `CUDA`. That relabel is reverted here: both classes are back at `ACCELERATOR`, which is what pytorch#198439/pytorch#198440 landed. Both classes generate cuda *and* xpu variants (`only_for=("cuda", "xpu")`, `allow_xpu=True`), and `get_hw_classification` reads the attribute with `getattr`, so a `CUDA` label is inherited by the generated XPU variants: on an XPU host `--hw-classification ACCELERATOR XPU` would drop these tests, and because the test linter checks nothing beyond the declaration on a device-specific class, the label hid the two `only_for` findings these classes produce instead of resolving them.

`CUDA` is still where these classes belong long term: their extension selection needs `_FastCudaLauncher`/`_FastXpuLauncher`, a promise no PrivateUse1 backend has signed, so `ACCELERATOR` overpromises. The label that says both is the tuple `(CUDA, XPU)` from pytorch#204896, which is open and still under discussion. Until that lands, `ACCELERATOR` plus this file's entry in `tools/linter/adapters/test_linter_allowlist.json` is the correct interim state, and **the allowlist entry has to stay**: an `ACCELERATOR` class may not pass `only_for`, so removing the entry before pytorch#204896 would fail the lint on those two findings. Removing this file's entry is therefore a follow-up after pytorch#204896, not part of this PR, and this PR does not touch the allowlist.

## Changes

One file, `test/inductor/test_static_triton_launcher.py`: 80 additions, 76 deletions against the base. No `hw_classification` line differs from the base after the revert, and the four `instantiate_device_type_tests` calls are untouched.

- `_FastLauncherMixin._fast_launcher_cls`, `_stream` and `_store_sum_launcher` take an optional `device` that defaults to `GPU_TYPE`; `_make_fast_launcher` forwards it. `TestFastLauncherXpuOnly` passes no device, so it keeps its current behavior.
- All 13 `TestFastLauncher` tests pass their injected device to the helpers they call, including the three `_make_launcher` calls that previously fell back to the global (`test_float_scalars`, `test_bfloat16_scalar`, `test_grid_2d`). `test_build_fast_launcher_launches` derives `device_props.type` from the injected device, which is the value `_build_fast_launcher` matches against `xpu`/`cuda`/`hip`.
- The `TestFastLauncherFallbackCompileResult` docstring says the behavior is shared by the CUDA and XPU fast launchers rather than by "every accelerator", which is what the `ACCELERATOR` label claims.

## Motivation

Part of pytorch#185590: tests should take their device from the instantiation machinery instead of a process-wide global, so the same class can be selected for more than one accelerator, and a hardware classification must describe the variants a class actually generates.

## Test Plan

Checked on a CPU-only host; the CUDA and XPU legs run on the respective CI shards.

Simulated the test linter over this file with its allowlist entry removed, by importing `tools/linter/adapters/test_linter.py` and clearing its `_allowlist` set (the allowlist file itself is unchanged in this PR):

- base: 13 findings. 8 `device_param` and 2 `only_for` belong to these two classes; the other 3 are `hw_classification` findings on `TestStaticTritonLauncherUnit`, `TestStaticTritonLauncher` and `TestStaticTritonCompileResult`, in class regions this PR does not touch (owned by pytorch#198436/pytorch#198437, and for the compile-result class a declaration that has since landed on main).
- the head before this round, with the `CUDA` labels: 3 findings, i.e. all 10 class-owned findings were gone, 8 of them from the device parameters and 2 from the label alone.
- the current head, `ACCELERATOR` plus full injection: 5 findings, the 2 `only_for` ones that the allowlist suppresses until pytorch#204896 plus those same 3.

So this PR clears 8 findings with the signatures, and the remaining 2 of its own are the ones only a tuple label can clear.

With the allowlist as it stands in CI today, the file reports nothing, using the same command lintrunner runs:

```
python3 tools/linter/adapters/test_linter.py -- test/inductor/test_static_triton_launcher.py
```

The RUFF and PYFMT adapters, invoked through `uv` the way `.lintrunner.toml` does and checked against planted violations first to confirm they are not no-ops, report nothing on this file.

```
python3 -I -m py_compile test/inductor/test_static_triton_launcher.py
python -m pytest --collect-only -q test_static_triton_launcher.py
```

The collection ran in the nightly cpu-wheel venv (`env-pytorch-2.16-20261029-cpu`), from outside the source tree so the wheel `torch` is the one imported: 60 tests collected, no errors, and the collected set is identical to the base and to the previous head. On a host with neither CUDA nor XPU, `instantiate_device_type_tests` generates no device-suffixed variants for these classes at all, so variant generation for `allow_xpu=True` rests on the untouched instantiate calls here and on the respective CI shards.

## Linked issue or supporting maintainer

Part of pytorch#185590 (test case refactoring initiative) - hardware-decoupling slice.

Pull Request resolved: pytorch#205277
Approved by: https://github.com/lizhihai137, https://github.com/jansel
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @fffrog — re-review ping for the current head 4f1208f (last ping 11-18, head unchanged since; diff remains the HardwareClassification import plus the hw_classification = GENERIC declaration on TestStaticTritonLauncherUnit). Per your "split it first" note, the device-gated members were re-cut into the sibling PRs referenced in the review thread: #203548 (Triton-gated autotuner tests, now APPROVED), #203550 and #203551 (open). Could you take a look when you get a chance, or let us know if anything is still missing on this head?

pytorchmergebot pushed a commit that referenced this pull request Dec 1, 2026
… into a CUDA-classified class (#203548)

## Summary

Slice 1 of 4 of the static-launcher re-cut (original monolith #198437 at 505 lines; all slices independent, any merge order) per #198436's review request.

Moves the Triton-gated autotuner unit test (`test_tensor_memory_autotuner_retries_without_pipelining`) out of `TestStaticTritonLauncherUnit` into a new **CUDA-classified, non-instantiated** class `TestStaticTritonLauncherUnitCuda`. The body exercises `CUDAAutotuner` / `StaticallyLaunchedCudaKernel` internals through mocks and is RoCm-skipped -- CUDA-family-specific, so device-variant instantiation (XPU/PrivateUse1 copies) would add noise, not coverage. The shared helpers (`_global_scratch_kernel`, `_can_statically_launch`) stay on the unit class and are delegated by reference (staticmethod-wrapped so signatures hold); nothing is copied.

(+74/-52, one file)

## Test Plan

- [x] cpu wheel venv: failure set identical to the untouched file (the 2 pre-existing wheel-vs-trunk artifacts)
- [x] in-tree test linter + lintrunner clean
- siblings: #203550 (RoCm scratch trio), #203551 (cubin metadata pair), #198437 (launcher migration)

Rebase note (2026-11-06): replayed onto current main after #200916 touched the same file; slice content unchanged (+77/-54).

## Linked issue or supporting maintainer

Part of #185590 (test case refactoring initiative) - hardware-decoupling slice.

Pull Request resolved: #203548
Approved by: https://github.com/lizhihai137, https://github.com/jansel
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
…t in static launcher tests

Summary

Follow-up fixups on the rebased head of this PR; restores content this
PR's own description says is present but the current pushed head lacks:

- the rebase conflict resolution dropped the module-level
  `from pathlib import Path` import while `Path(compile_path)` is still
  used in test_make_launcher_reuses_loaded_kernel_after_cache_context
  (latent NameError);
- the two oversized-shared-memory tests lost their per-device
  conversion (injected device argument, CUDA-only SkipTest guard ahead
  of the shared helper's torch.cuda.current_device(), per-test Triton
  gate);
- TestStaticTritonLauncherXpuOnly did not inherit
  StaticLauncherTestMixin although its tests call self._make_launcher
  and self.write_cubin_to_tmp (AttributeError on the XPU shard);
- two XPU-specific tests, test_xpu_non_default_warp_size and
  test_xpu_launch_rejects_non_kernel_capsule, were deleted instead of
  moved when the XPU-only tests split into that class; they are
  restored verbatim, so the class holds all eight XPU-specific tests
  of the old launcher class.

Test Plan

- python -m py_compile on the patched file;
- in-tree test linter (tools/linter/adapters/test_linter.py) with the
  file's allowlist entry removed: zero errors in this PR's class
  regions; the remaining 12 file errors belong to pytorch#198436 (Unit
  declaration), pytorch#198438 (CompileResult) and pytorch#205277 (fast launcher),
  identical to the pre-fixup attribution;
- cpu wheel (torch-2.16.0.dev20261102+cpu) venv run of the patched
  file: failure set byte-identical to the unpatched pushed head (10
  known wheel-vs-trunk drift artifacts), i.e. no regression;
- the eight XpuOnly tests execute on the CI XPU shards only
  (only_for="xpu"); no local XPU hardware here.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
… Triton device

Summary

Review feedback: test_launcher_keeps_module_owner_alive_until_release
builds fake kernel-owner and launcher objects, never touches the device
argument it receives, and only checks weakref/gc lifetime behavior, yet
it lived in TestStaticTritonLauncher, whose except_for="cpu"
instantiation and per-test Triton skip mean the ownership check cannot
run on a CPU-only shard.

Upstream has no host launcher test file yet, so move the test as-is
into TestStaticTritonLauncherUnit in the same file, the device-agnostic
unit class that already hosts the adjacent fake-owner lifetime checks,
and drop the unused device parameter and the Triton gate. The test body
is otherwise byte-identical.

Test Plan

- python -m py_compile on the patched file;
- in-tree test linter (tools/linter/adapters/test_linter.py) with the
  file's allowlist entry removed: 11 findings on the patched file,
  identical to the previous head (all pre-existing, attributed to
  pytorch#198436 Unit hw_classification declaration, pytorch#198438 and pytorch#205277),
  i.e. zero new violations from this move;
- AST scan: single definition of the moved test, no undefined names, no
  doubled decorators; gc/weakref/has_triton imports remain referenced
  elsewhere in the file;
- no built torch in this environment, so the moved test was not
  executed locally; as a device-less unit test it now runs in CI on CPU
  shards.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
… XPU-only launcher class

Summary

Two inline review items at bef2f7b:

TestStaticTritonLauncher gates its compile-on-device launcher cases with a
process-wide has_triton() skipIf, but the class is instantiated for multiple
backends, so a backend without Triton would still run these cases whenever
any other accelerator has Triton. Replace the thirteen per-test decorators
with one per-device gate in setUp using has_triton_for_device, the same
convention _StaticTritonCompileResultMixin already uses in this file; the
two compiling cases that carried no Triton gate (test_float_scalars,
test_bfloat16_scalar) are covered as a side effect, and skipping ahead of
super() keeps the mixin's XPU JITFunction patch from being applied.

The instantiate_device_type_tests call for TestStaticTritonLauncherXpuOnly
passed only_for="xpu" without allow_xpu, so no XPU class was ever emitted:
XPUTestBase joins the candidate bases only under allow_xpu=True, and the
filter then removed everything else. Pass allow_xpu=True, matching the
file's five other instantiations, so the restored XPU-only launcher tests
collect on XPU shards.

Test Plan

- python -m py_compile and ast.parse on the patched file.
- CPU wheel venv (torch 2.16.0.dev20261029+cpu, torch_npu installed so
  PrivateUse1=npu instantiates): module collection is 50 tests with no
  loader errors, unchanged from the pre-change head; the instantiated
  TestStaticTritonLauncherNPU test now skips via the new gate ("requires
  Triton on npu"); the device-free TestStaticTritonLauncherUnit result set
  is identical to the pre-change head (28 run, 23 pass, 3 skip, 2 known
  wheel-vs-trunk drift failures).
- allow_xpu verified against the helper with XPU availability simulated:
  get_desired_device_type_test_bases(only_for="xpu") returns no bases
  without allow_xpu and the xpu base with it; instantiating a dummy
  template with the new kwargs emits its XPU class while the old kwargs
  emit none. This host has no XPU hardware, so real XPU collection runs
  on the CI XPU shards.
- in-tree test linter (tools/linter/adapters/test_linter.py) with the
  file's allowlist entry removed: 11 findings on the patched file,
  identical to the previous head (all pre-existing, attributed to
  pytorch#198436 Unit hw_classification declaration, pytorch#198438 and pytorch#205277),
  i.e. zero new violations from these fixes.

Authored with the assistance of an AI coding assistant.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
Follow-up to @KarhouTam's review:

- test_float_scalars and test_bfloat16_scalar normalize the injected
  device via torch.device(device).type before get_interface_for_device,
  matching the class's other tests (a cuda:N/xpu:N value raised
  NotImplementedError);
- the two oversized-shared-memory tests move out of the ACCELERATOR
  class into a new CUDA-classified TestStaticTritonLauncherCudaOversized
  (they read torch.cuda.get_device_properties via
  _oversized_shared_mem_limits, which is accelerator-specific; the
  @skipIfXpu decorator plus body-level guard was the wrong shape);
- TestStaticTritonLauncher.setUp gains the same
  is_registered_static_launch_device(device_type) gate the
  compile-result mixin uses, so devices without a registered static
  launcher skip instead of raising;
- the unused module-level _global_scratch_kernel duplicate is deleted
  (every caller uses the unit-class staticmethod);
- TestStaticTritonLauncherXpuOnly drops the
  use_static_triton_launcher/strict config patch its tests never read.

Test Plan

- python -m py_compile;
- formatting scan of the changed regions: no module-level run of three
  or more blank lines, no trailing whitespace, no line over 120 columns;
- in-tree test linter with the file's allowlist entry removed: zero
  findings in the classes touched here (TestStaticTritonLauncher, the
  new TestStaticTritonLauncherCudaOversized, TestStaticTritonLauncherXpuOnly);
  the 11 remaining findings are pre-existing and attributed to pytorch#198436
  (the device-free Unit class's missing hw_classification) and pytorch#205277
  (TestFastLauncher device_param and instantiate_device_type_tests
  only_for) -- an identical findings set to the pre-fix head, reconfirmed
  by running the linter on this tree and on fe64feb.
pytorchmergebot pushed a commit that referenced this pull request Dec 3, 2026
…via instantiate_device_type_tests (#198437)

## Current state (2026-12-02)

- Head `879a6d25a2f3`, rebased onto main on Dec 1. One file changed: `test/inductor/test_static_triton_launcher.py`.
- All 213 checks on the head are completed with nothing failing (208 success, 4 skipped, 1 neutral), and none waiting for approval.
- All 16 review threads are resolved. Each carries a reply, and the two that still cited a pre-rebase head were re-verified against this head today with line numbers.
- Labels: `topic: not user facing`, `ready for review`, `module: tests/graph`, `ciflow/inductor`, `ciflow/xpu`.
- Waiting on one approving review from a member of the merge-rules approver lists. The two content approvals so far (lizhihai137 on Nov 2, KarhouTam on Dec 1) are from contributors outside those lists, so the merge bot still reports the PR as needing additional approval.

## Summary

Launcher-migration slice of the static-launcher file (the original #192893 monolith has been re-cut into dependency-free, review-sized PRs per #198436's review request; this PR is +363/-324 in one file; the unit-class splits are in #203548 (Triton-gated autotuner), #203550 (RoCm scratch trio), #203551 (cubin metadata pair), each with its own correctly-scoped class; merge in any order).

## Changes (one file: test/inductor/test_static_triton_launcher.py)

`TestStaticTritonLauncher` on main is a `@requires_gpu_and_triton` class with 24 test methods bound to `GPU_TYPE`. It is made device-agnostic via `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` with `hw_classification = HardwareClassification.ACCELERATOR`. All 24 tests are kept; where each one lives:

- 13 general launcher tests stay in `TestStaticTritonLauncher` (ACCELERATOR). All 13 now take the injected `device` and pass it to `self._make_launcher(compiled_kernel, device)`, so the binary key (`cubin`/`zebin`/`npubin`/`hsaco`), the launcher class and the load interface resolve from the device under test instead of `GPU_TYPE`. `test_bfloat16_scalar` swaps its process-wide `@skipIfRocm` / `@unittest.skipIf(not HAS_XPU_AND_TRITON and not SM80OrLater, ...)` guards for the device-aware `@skipCUDAIfRocm` / `@skipCUDAIf(not SM80OrLater, ...)` from `common_device_type`.
- The removed class-level `@requires_gpu_and_triton` is replaced by a `setUp` gate that is per-device rather than process-wide: `has_triton_for_device(self.device_type)` so a backend without Triton skips even when another backend has it, and `is_registered_static_launch_device(self.device_type)` (only cuda, hip and xpu register a static launcher) so Triton-capable but launcher-less backends skip instead of raising.
- The 8 `test_xpu_*` tests move to a new `TestStaticTritonLauncherXpuOnly` (`hw_classification = XPU`, keeps the class-level `@requires_gpu_and_triton` and its per-test `@unittest.skipUnless(HAS_XPU_AND_TRITON, ...)` decorators), instantiated `only_for="xpu", allow_xpu=True`, mirroring `TestFastLauncherXpuOnly` from #198439.
- The two oversized-shared-memory tests (`test_oversized_shared_mem`, `test_too_high_oversized_shared_mem`, both on main via #199309; their helper reads `torch.cuda.get_device_properties`) move to a new `TestStaticTritonLauncherCudaOversized` (`hw_classification = CUDA`), instantiated `only_for=("cuda",)` with a `setUp` skip for `self.device_type != "cuda"` (plus a runtime `has_triton_for_device` skip), the way `TestCudaStaticTritonCompileResult` is scoped. Their `@skipIfRocm` is kept; `@skipIfXpu` and the body-level `SkipTest` guards are dropped because the class is CUDA-only.
- `test_launcher_keeps_module_owner_alive_until_release` moves into `TestStaticTritonLauncherUnit`, the host-side unit class, so the module-owner lifetime check runs once without a working Triton device.
- The `instantiate_device_type_tests` calls for the three launcher classes sit in the file's single trailing group, the shape #198440 established.

No helper or other class is touched: `StaticLauncherTestMixin` already takes optional `device` arguments on main (landed via #198439/#198440), and `TestFastLauncher` plus the compile-result classes keep their current scoping.

## Notes

- No dependency on the sibling split PRs; the overlapping import lines collapse to one copy at rebase.
- MTIA: the ACCELERATOR class is instantiated for accelerator device types with `except_for="cpu"`; no MTIA base is registered, so no MTIA variants are generated. This is a coverage note for #198436's open question, not a regression on currently-tested devices.

## Verification

- [x] CPU wheel env (torch 2.16.0.dev20261029+cpu): `TestStaticTritonLauncherUnit` failure set identical to the pre-change head (28 tests; the two failures are preexisting wheel-vs-trunk artifacts already present before this PR's edits, 3 skips)

```
python test/inductor/test_static_triton_launcher.py TestStaticTritonLauncherUnit
```

- [x] `ast.parse` clean; ruff 0.14.4 with the repo config: `check` and `format --check` clean on the file; in-tree `test_linter` run with this file's allowlist entry temporarily removed: no findings in this PR's three launcher classes (the remaining file-level findings belong to the unit-class and fast-launcher regions tracked in #198436 and the fast-launcher follow-up)
- [ ] `ciflow/xpu` label requested so this PR's CI actually exercises the XPU instantiations (the 13 ACCELERATOR tests on xpu and the 8-test XPU-only class); CUDA CI covers the cuda instantiations and the new CUDA-only class
- No XPU, CUDA or NPU device is available in this environment, so the device-generic skips above are static-reasoning plus CI, not test-run evidence.

## Linked issue or supporting maintainer

Part of #185590 (test case refactoring initiative), hardware-decoupling slice.
Pull Request resolved: #198437
Approved by: https://github.com/lizhihai137, https://github.com/KarhouTam, https://github.com/jansel
@gavinwang269
gavinwang269 marked this pull request as ready for review December 3, 2026 09:11
@pytorch-bot pytorch-bot Bot removed the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Dec 3, 2026
@pytorch-bot pytorch-bot Bot added bot-retriage Re-run Auto PR Triage and removed bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Dec 3, 2026
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Dec 3, 2026
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Dec 3, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Status update for @fffrog: the "split it first" request from Nov 5 is now fully landed, and this PR shrank to exactly what is left of it:

This branch was previously deployed

1 inactive deployment
bedrock — 4f1208f3 Deployed Dec 3, 2026 by pytorch-bot[bot] via analyze #48514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-retriage Re-run Auto PR Triage bot-triaged This is a label only to be used by the auto triage bot ciflow/inductor in progress PR is being worked on by the author, until the automated review accepts it module: inductor module: tests/graph This label covers all test cases within the Graph sheet. open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

5 participants