Skip to content

[Testcase Refactoring] Keep XPU coverage and classify TestFastLauncher hw classes - #198439

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

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

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make TestFastLauncher in test/inductor/test_static_triton_launcher.py hardware-classified and instantiated for both CUDA and XPU, keeping every test that ran before the split running after it.

Split from #192893 (one test class per PR, zero overlap), rebased onto main after #200916 renamed TestFastCudaLauncher to TestFastLauncher and moved the shared helpers into StaticLauncherTestMixin.

Changes

  • TestFastLauncher declares hw_classification = HardwareClassification.ACCELERATOR and is instantiated with only_for=("cuda", "xpu"), allow_xpu=True (the in-tree combination used by e.g. test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py). Five tests (test_basic, test_multiple_tensor_args, test_zero_grid, test_wrong_arg_count, test_too_many_args_raises_value_error) take the injected device argument; the remaining tests resolve GPU_TYPE, which equals the running device on the CUDA and XPU single-device-type CI runners.
  • The five XPU-specific tests (test_xpu_static_shared_mem, test_xpu_fast_kernel_arg_count_mismatch, test_xpu_rejects_invalid_launch_metadata, test_xpu_rejects_unloaded_kernel, test_xpu_keeps_kernel_capsule_alive) move to a new TestFastLauncherXpuOnly class: hw_classification = HardwareClassification.XPU, instantiated with only_for="xpu", allow_xpu=True, keeping their @unittest.skipUnless(HAS_XPU_AND_TRITON) guards. On non-XPU devices the class collects empty (the generic form is deleted by instantiation and no variant is generated).
  • The fast-launcher construction helpers (_fast_launcher_cls, _make_fast_launcher, _stream, _store_sum_launcher) move into a file-private _FastLauncherMixin shared by the two classes. StaticLauncherTestMixin is unchanged; its _make_launcher/write_cubin_to_tmp device-optional form stays byte-identical with the sibling [Testcase Refactoring] Make TestStaticTritonLauncher device-agnostic via instantiate_device_type_tests #198437 so whichever lands first supplies them.

Why only_for=("cuda", "xpu") instead of except_for="cpu": the static launcher registry (torch/_inductor/runtime/static_triton_launcher.py) only has cuda/hip/xpu entries, so except_for="cpu" would generate MPS/PrivateUse1 variants that hard-error in _make_launcher instead of skipping; cuda+xpu is exactly the device set the pre-series GPU_TYPE gating covered.

Notes

  • Test IDs change for the whole class. TestFastLauncher.test_x becomes TestFastLauncherCUDA.test_x_cuda (and a TestFastLauncherXPU...._xpu variant on XPU runners); the XPU-specific tests become TestFastLauncherXpuOnlyXPU.test_xpu_*_xpu there. No in-tree DISABLED/slow-test entries reference the old names (grepped test/, .ci/, tools/).
  • The write_cubin_to_tmp helper in this diff gains an npubin binary key alongside zebin/cubin/hsaco for the out-of-tree NPU backends that motivate this series; having the backend supply its binary key via register_statically_launched_kernel is a plausible follow-up.
  • 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. This PR makes that true for TestFastLauncher without dropping its existing XPU coverage.

Test Plan

CPU-only host (torch 2.16.0.dev20261102+cpu wheel; no CUDA or XPU device available):

python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py --collect-only -q
cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py -q
uv run --python 3.11 --script tools/linter/adapters/pyfmt_linter.py -- test/inductor/test_static_triton_launcher.py
uv run --python 3.10 --script tools/linter/adapters/ruff_linter.py -- test/inductor/test_static_triton_launcher.py
python3 tools/linter/adapters/test_linter.py test/inductor/test_static_triton_launcher.py
  • Collect: 60 tests on the rebased head (the pre-rebase head collected 58; the delta is entirely main-side: 3 unit-class ids removed by [Testcase Refactoring] Split TestFastLauncherCompileResult into mixin, accelerator and CUDA-only classes #198440's restructure and 5 main-added tests absent from the older base); no instantiated TestFastLauncher* variants on a CPU-only host, as designed.
  • Run: 22 passed, 36 skipped, 2 failed. Both failures are in the untouched TestStaticTritonLauncherUnit (the CPU wheel carries no _FastXpuLauncher extension, and without Triton/GPU compilation no cubin is produced) and reproduce identically on the unmodified current-main file in the same environment (wheel-vs-trunk drift), so this change is CPU-neutral.
  • Import probe: importing the module with a recording stub over instantiate_device_type_tests asserts both generic classes, their hw_classification values, the exact test placement (the 5 test_xpu_* tests only in TestFastLauncherXpuOnly), helper resolution through _FastLauncherMixin, the retained skip guards, and the instantiate kwargs; filter_by_hw_classification is exercised directly ({ACCELERATOR} keeps the shared class, {XPU} keeps TestFastLauncherXpuOnly).
  • Lint: pyfmt and CI-pinned ruff 0.14.4 (check + format) clean; test_linter.py reports nothing (the file is in its allowlist, like the precedent files above).

CUDA and XPU on-device execution of the instantiated classes is delegated to CI; the authoring host has neither device.

Agent details (if applicable)

This description and the linked review replies were drafted with an AI assistant and reviewed against the diff by the author before posting.

Rebase note (2026-11-16): rebased onto current main after #198440 landed. #198440 refactored the separate TestFastLauncherCompileResult class (untouched here) and gathered the file's instantiate_device_type_tests calls into a single trailing group; this PR's two instantiation calls now join that group and its two import lines dedup against main. The branch's three commits were squashed into one (head d3924245614); diff +61/-33 -> +57/-33; no scope change.

@pytorch-bot

pytorch-bot Bot commented Sep 24, 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 splits TestFastLauncher into a shared ACCELERATOR class
(only_for=("cuda", "xpu")) and TestFastLauncherXpuOnly, with shared helpers in a
new _FastLauncherMixin; both earlier blocking findings (XPU coverage and
hw_classification) are fixed. Recommendation: Approve. Every remaining point is
non-blocking, though a maintainer should add ciflow/xpu before merge.

Findings (6):

[minor] test/inductor/test_static_triton_launcher.py:1798
Non-blocking: TestFastLauncher doesn't yet meet REVIEW.md Rule 4 for an
ACCELERATOR class, and part of the stated reason is wrong.
- It uses `only_for`, which Rule 4 forbids. The precedents cited are all in
test_linter_allowlist.json. The one non-allowlisted inductor precedent,
test_smoke.py:69-71, uses `except_for="cpu", allow_xpu=True`.
- The case against `except_for="cpu"` is partly wrong. No MPS variant would be
generated (that needs allow_mps=True), and PrivateUse1/HPU variants would hit
the class-level @​ requires_gpu_and_triton skip. The real limit is that only
_FastCudaLauncher/_FastXpuLauncher exist. If that is why you keep `only_for`,
say so.
- Most tests ignore the injected device: 8 of 13 take no `device`, and
_fast_launcher_cls/_stream/_store_sum_launcher key on GPU_TYPE. These helpers
live in the new _FastLauncherMixin, not StaticLauncherTestMixin, so they can use
self.device_type. On a host with both CUDA and XPU, one variant runs on the
wrong device.
- test_bfloat16_scalar still uses a plain unittest.skipIf(SM80OrLater) where @​
skipCUDAIf would fit.

[minor] test/inductor/test_static_triton_launcher.py:1801
Non-blocking: the XPU variants this revision adds won't run in this PR's CI. The
PR has ciflow/inductor but not ciflow/xpu. XPU test jobs run only from xpu.yml,
which triggers on ciflow/xpu/*, viable/strict and the schedule. The test plan
ran on a CPU-only host, so TestFastLauncherXPU and TestFastLauncherXpuOnlyXPU
have never executed. A maintainer should add ciflow/xpu before merge.

[minor] test/inductor/test_static_triton_launcher.py:654
Non-blocking, carried over: the `elif dev == "npu": binary_key = "npubin"`
branch in write_cubin_to_tmp can't be reached in any in-tree configuration. The
only callers that pass a device are the cuda/xpu TestFastLauncher tests. It also
hard-codes one out-of-tree vendor's key into a shared helper. The follow-up
plan, where the backend supplies the key via
register_statically_launched_kernel, is the right home for it. Landing this
branch ahead of that adds nothing testable.

[minor] test/inductor/test_static_triton_launcher.py:638
Non-blocking: the PR description contradicts HEAD. It says
"StaticLauncherTestMixin is unchanged", but this diff changes write_cubin_to_tmp
and _make_launcher (new `device` parameter, dev-based dispatch, npubin). The
Motivation says the PR lets PrivateUse1 accelerators run these tests. But with
only_for=("cuda", "xpu") and the class-level @​ requires_gpu_and_triton,
PrivateUse1 still gets no variants. The description should state that this slice
doesn't deliver that yet.

[minor] test/inductor/test_static_triton_launcher.py:1707
Non-blocking: TestFastLauncherXpuOnly stacks three XPU guards: the class-level @​
requires_gpu_and_triton (which would also pass on CUDA or MTIA), only_for="xpu",
allow_xpu=True, and a per-test @​ unittest.skipUnless(HAS_XPU_AND_TRITON) on
every test. requires_xpu_and_triton (torch/testing/_internal/triton_utils.py:17)
is the matching class-level guard. With it, the per-test decorators can go.

[minor] test/inductor/test_static_triton_launcher.py:1590
Non-blocking: test_wrong_arg_count uses a bare assertRaises(RuntimeError). Both
launchers raise "... expected N args, got M". Using
assertRaisesRegex(RuntimeError, r"expected d+ args, got d+") would stop an
unrelated RuntimeError, such as one from a device mismatch, from passing the
test.

Reviewed commit: 4b898b2 (NOT the current head d392424)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit d392424 with merge base 7d191ca (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 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"

@gavinwang269
gavinwang269 marked this pull request as ready for review November 13, 2026 00:16
@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 Nov 13, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@jansel could you approve and run the workflows here, and skim it if you have a minute? All five (Auto Request Review, Lint, BC Lint, docs-build, pull) are sitting at action_required on f4c4cf1428d, so nothing has actually executed yet — the PR is open but invisible to CI until someone with write access clicks approve.

What it does, in one file (test/inductor/test_static_triton_launcher.py), test-side only, no production change:

  • TestFastLauncher gets instantiate_device_type_tests(...), and 5 tests take the injected device argument instead of GPU_TYPE.
  • The @skipIfXpu class decorator is kept as-is.

One point I would rather hand to a reviewer than settle myself: instantiate_device_type_tests does not exist in this file on the base — this PR introduces it, and introduces it as only_for=("cuda",). So although the class is now on the standard pattern, no device other than CUDA actually gains coverage here. If the intent of the series is that these launcher tests should also run under PrivateUse1, that scoping has to change, and I would prefer to hear it now rather than after a review round. I cannot settle it locally: I have no CUDA or XPU host, only an Ascend NPU box.

For context on where this family stands: four device-decoupling PRs of ours landed this week (#192435, #198353, #196250, #198355). Four other open PRs touch this same file (#198440, #203548, #203551, plus #198437 which is a larger rewrite), so they will land one after another with trivial rebases in between; #198439 is self-contained — it adds the module scaffold it needs itself rather than depending on another PR landing first.

@jansel jansel added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 15, 2026
github-actions[bot]

This comment was marked as outdated.

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 15, 2026
…r hw classes (pytorch#198439)

Follow-up to the automated review (5913183375) on the CUDA-only
instantiation of TestFastLauncher. Both blocking findings are resolved with
the combined option the review offered: the five test_xpu_* tests move to a
new TestFastLauncherXpuOnly class (hw_classification XPU, instantiated with
only_for="xpu" and allow_xpu=True, per-test skipUnless guards kept), so they
run on XPU again and collect empty elsewhere, and the shared class gains
hw_classification ACCELERATOR with only_for=("cuda", "xpu"),
allow_xpu=True.

only_for=("cuda", "xpu") was chosen over except_for="cpu" because the
static launcher registry only has cuda/hip/xpu entries
(torch/_inductor/runtime/static_triton_launcher.py), so an unfiltered
instantiation would generate MPS/PrivateUse1 variants that hard-error in
_make_launcher instead of skipping; cuda+xpu is exactly the device set the
pre-series GPU_TYPE gating covered. ACCELERATOR (not CUDA) is the honest
label after the split because every remaining test is device-generic across
cuda and xpu; a CUDA label would drop the class under --hw-classification
XPU. The four fast-launcher helpers move into a private _FastLauncherMixin
shared by both classes; StaticLauncherTestMixin (kept byte-identical with
pytorch#198437) is untouched.

Test Plan:
- Syntax:

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

- CPU-only import probe (real import plus a recording stub over
instantiate_device_type_tests) asserting both classes, their
hw_classification values, test placement (5 xpu tests only in the XPU
class), helper resolution, skip guards, the exact instantiate kwargs, and
filter_by_hw_classification keep/drop behavior: 49 checks pass.
- Collection, same CPU-only wheel (2.16.0.dev20261102+cpu):

```
cd /tmp && python -I -m pytest /gavin-ai/workspace/wt-198439/test/inductor/test_static_triton_launcher.py --collect-only -q
```

58 tests collected, identical to the pre-fix head; no instantiated
TestFastLauncher* variants on a CPU host, as intended.
- Execution:

```
cd /tmp && python -I -m pytest /gavin-ai/workspace/wt-198439/test/inductor/test_static_triton_launcher.py -q
```

22 passed, 34 skipped, 2 failed. The 2 failures are in
TestStaticTritonLauncherUnit (untouched by this diff) and reproduce
identically on the pre-fix head in the same environment (wheel-vs-trunk
TritonBundler drift), so the change is CPU-neutral.
- Lint with the CI-pinned toolchain:

```
uv run --python 3.11 --script tools/linter/adapters/pyfmt_linter.py -- test/inductor/test_static_triton_launcher.py
uv run --python 3.10 --script tools/linter/adapters/ruff_linter.py -- test/inductor/test_static_triton_launcher.py
python3 tools/linter/adapters/test_linter.py test/inductor/test_static_triton_launcher.py
```

All clean (the file is in the test_linter allowlist, like the
only_for=("cuda", "xpu") + ACCELERATOR precedent files
test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py).
- No CUDA or XPU device on the verification host: the XPU side is verified
at the collection level only; on-device CUDA/XPU runs are left to CI.

Authored with an AI assistant; the change was reviewed against the diff by
the author before pushing.
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Responses to the non-blocking findings (no code churn in this slice beyond that, per review scope); drafted with an AI assistant and reviewed by me before posting.

npubin binary key in write_cubin_to_tmp (kept, in this PR's diff): this PR is one slice of the split of #192893 whose stated motivation is letting out-of-tree backends run these tests; the elif dev == "npu": binary_key = "npubin" branch mirrors the xpu/hsaco branches directly above it and matches the asm key the out-of-tree NPU toolchain emits for compiled Triton kernels, which the in-tree cubin/zebin/hsaco keys cannot reach. I agree the cleaner home is the backend supplying its binary key through register_statically_launched_kernel; proposing that is a follow-up outside this test-only slice, so the branch stays for now.

Partly-unused device param in the migrated tests (not restructured here): the reviewer's own note says nothing breaks under CUDA-only instantiation, and with the CUDA+XPU instantiation every test that still reads GPU_TYPE resolves to the running device on the single-device-type CI runners (and get_gpu_type() picks the current accelerator when several are present). Converting the helpers to derive from self.device_type would touch StaticLauncherTestMixin, whose _make_launcher form is kept byte-identical with #198437 ("whichever lands first supplies them"), so it is deliberately out of this slice.

Test-ID churn: documented in the updated PR description (every test in the class moves to a device-suffixed ID, e.g. TestFastLauncher.test_x to TestFastLauncherCUDA.test_x_cuda; no DISABLED/slow-test entries in-tree reference the old names - I grepped test/, .ci/, tools/).

Description staleness: title and body rewritten to match head 4b898b2 (the TestFastCudaLauncher name, the class-level @skipIfXpu claim, and the hw_classification = CUDA / added-imports claims are gone; Test Plan now reflects commands actually run on a CPU-only host, and XPU/CUDA on-device runs are stated as delegated to CI).

@gavinwang269 gavinwang269 changed the title [Testcase Refactoring] Instantiate TestFastCudaLauncher for CUDA with hw_classification CUDA [Testcase Refactoring] Keep XPU coverage and classify TestFastLauncher hw classes Nov 15, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot review

@pytorch-bot pytorch-bot Bot removed the in progress PR is being worked on by the author, until the automated review accepts it label Nov 15, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

cc @jansel

Two asks below: (1) a favor on CI, (2) a skim if you have a few minutes. I also
want to close the loop on the two open review threads so the linked commit is not
confusing.

What this is

One review-sized slice of the test/inductor/test_static_triton_launcher.py
refactor that we split out of umbrella #192893 (now closed): the rule for that
split was "one test class per PR, zero overlap", which is exactly what this PR
follows. It converts a single class, TestFastLauncher, from the
@requires_gpu_and_triton / GPU_TYPE style to instantiate_device_type_tests,
and it only touches that test file. The rest of the series (#198436, #198437,
#198438, #198440) are same-batch siblings of that split, each converting a
different class; I am naming them only to place this PR in the batch, not as
prerequisites or as an "already implemented here" reference.

Shape and size

  • Diff vs main: 1 file (test/inductor/test_static_triton_launcher.py),
    +57/-33, single commit (the original 3-commit stack was squashed during the
    rebase), on top of main at 7d191ca.
  • Test-side only: no production module changes.
  • Form: the shared TestFastLauncher is decorated with
    hw_classification = HardwareClassification.ACCELERATOR and instantiated with
    only_for=("cuda", "xpu"), allow_xpu=True (the in-tree combination used by
    test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py).
    The five test_xpu_* tests move into a new TestFastLauncherXpuOnly with
    hw_classification = HardwareClassification.XPU, instantiated
    only_for="xpu", allow_xpu=True, keeping their
    @unittest.skipUnless(HAS_XPU_AND_TRITON) guards so the class collects empty
    off-XPU. The fast-launcher construction helpers move into a file-private
    _FastLauncherMixin; StaticLauncherTestMixin is unchanged.

The CI favor

Right now 0 of the CI checks have actually run. The four checks on the fork
(BC Lint, Lint, docs-build, and pull) are parked at action_required,
which means they are waiting for someone with write access to approve running
workflows from this fork. As an outside contributor I do not have that
permission and cannot start them myself. Could you approve the run so the fork
workflows can execute? Until then the merge box is blocked only on those unrun
checks, not on any result.

The two open threads

The two unresolved review threads are the ones where our replies are the last
word; nothing is owed from the reviewer side. They respond to two blocking
findings:

  1. Dropped XPU coverage. TestFastLauncher is now instantiated
    only_for=("cuda", "xpu"), allow_xpu=True, so the shared tests run on both
    CUDA and XPU as before; the five XPU-specific tests are isolated in
    TestFastLauncherXpuOnly with their per-test skip guards.
  2. Missing hw_classification. The shared class is ACCELERATOR and the
    XPU-only class is XPU, checked against filter_by_hw_classification
    ({ACCELERATOR} keeps the shared class, {XPU} keeps the XPU-only class).

One thing to flag so the link is not misleading: both replies pointed at commit
4b898b2, but the branch was since rebased onto main (7d191ca) and
squashed to one commit, so the current head is d392424 and 4b898b2 is no
longer the tip. I re-checked the fix against the current head rather than the
stale sha, and it is fully present at d392424: the _FastLauncherMixin split,
the ACCELERATOR / XPU classification, the five test_xpu_* tests in
TestFastLauncherXpuOnly, and both instantiate_device_type_tests(...) calls are
all in the head file. The only thing the rebase removed from that reply's diff is
two now-redundant import lines, because main already adds them via the merged
sibling #198440; no part of the actual fix changed. Please read the fix at head
d392424, not at 4b898b2.

The skim

If you have a few minutes, I would value a quick read of this one class. On a
CPU-only host I verified the class shape directly: an import-level probe
confirming the instantiate kwargs, the hw_classification values, that the five
test_xpu_* tests are only in TestFastLauncherXpuOnly, the helper resolution
through _FastLauncherMixin, and the retained skip guards; plus
--collect-only on the head file, 60 tests, with zero instantiated
device-variant leakage on CPU, matching the pre-change baseline. This session
re-ran the verification on the head file: ast.parse OK, --collect-only 60
tests (rc=0), and the recording-stub import probe passing 49 checks. The
formatting/lint verdict is exactly what the Lint job will report once it is
approved to run. CUDA/XPU/NPU execution of the
instantiated variants cannot be judged on this host, so that is left to the CI
you would be approving.

Thanks!

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

Pull workflow has not been scheduled for the PR yet. It could be because author doesn't have permissions to run those or skip-checks keywords were added to PR/commits, aborting merge. Please get/give approval for the workflows and/or remove skip ci decorators before next merge attempt. If you think this is a mistake, please contact PyTorch Dev Infra.

@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 17, 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 17, 2026
jkosnox pushed a commit to jkosnox/pytorch that referenced this pull request Nov 17, 2026
…r hw classes (pytorch#198439)

## Summary

Make `TestFastLauncher` in `test/inductor/test_static_triton_launcher.py` hardware-classified and instantiated for both CUDA and XPU, keeping every test that ran before the split running after it.

Split from pytorch#192893 (one test class per PR, zero overlap), rebased onto main after pytorch#200916 renamed `TestFastCudaLauncher` to `TestFastLauncher` and moved the shared helpers into `StaticLauncherTestMixin`.

## Changes

- `TestFastLauncher` declares `hw_classification = HardwareClassification.ACCELERATOR` and is instantiated with `only_for=("cuda", "xpu"), allow_xpu=True` (the in-tree combination used by e.g. test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py). Five tests (`test_basic`, `test_multiple_tensor_args`, `test_zero_grid`, `test_wrong_arg_count`, `test_too_many_args_raises_value_error`) take the injected `device` argument; the remaining tests resolve `GPU_TYPE`, which equals the running device on the CUDA and XPU single-device-type CI runners.
- The five XPU-specific tests (`test_xpu_static_shared_mem`, `test_xpu_fast_kernel_arg_count_mismatch`, `test_xpu_rejects_invalid_launch_metadata`, `test_xpu_rejects_unloaded_kernel`, `test_xpu_keeps_kernel_capsule_alive`) move to a new `TestFastLauncherXpuOnly` class: `hw_classification = HardwareClassification.XPU`, instantiated with `only_for="xpu", allow_xpu=True`, keeping their `@unittest.skipUnless(HAS_XPU_AND_TRITON)` guards. On non-XPU devices the class collects empty (the generic form is deleted by instantiation and no variant is generated).
- The fast-launcher construction helpers (`_fast_launcher_cls`, `_make_fast_launcher`, `_stream`, `_store_sum_launcher`) move into a file-private `_FastLauncherMixin` shared by the two classes. `StaticLauncherTestMixin` is unchanged; its `_make_launcher`/`write_cubin_to_tmp` device-optional form stays byte-identical with the sibling pytorch#198437 so whichever lands first supplies them.

Why `only_for=("cuda", "xpu")` instead of `except_for="cpu"`: the static launcher registry (`torch/_inductor/runtime/static_triton_launcher.py`) only has `cuda`/`hip`/`xpu` entries, so `except_for="cpu"` would generate MPS/PrivateUse1 variants that hard-error in `_make_launcher` instead of skipping; `cuda`+`xpu` is exactly the device set the pre-series `GPU_TYPE` gating covered.

## Notes

- **Test IDs change for the whole class.** `TestFastLauncher.test_x` becomes `TestFastLauncherCUDA.test_x_cuda` (and a `TestFastLauncherXPU...._xpu` variant on XPU runners); the XPU-specific tests become `TestFastLauncherXpuOnlyXPU.test_xpu_*_xpu` there. No in-tree DISABLED/slow-test entries reference the old names (grepped `test/`, `.ci/`, `tools/`).
- The `write_cubin_to_tmp` helper in this diff gains an `npubin` binary key alongside `zebin`/`cubin`/`hsaco` for the out-of-tree NPU backends that motivate this series; having the backend supply its binary key via `register_statically_launched_kernel` is a plausible follow-up.
- 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. This PR makes that true for `TestFastLauncher` without dropping its existing XPU coverage.

## Test Plan

CPU-only host (torch `2.16.0.dev20261102+cpu` wheel; no CUDA or XPU device available):

```
python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())"
cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py --collect-only -q
cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py -q
uv run --python 3.11 --script tools/linter/adapters/pyfmt_linter.py -- test/inductor/test_static_triton_launcher.py
uv run --python 3.10 --script tools/linter/adapters/ruff_linter.py -- test/inductor/test_static_triton_launcher.py
python3 tools/linter/adapters/test_linter.py test/inductor/test_static_triton_launcher.py
```

- Collect: 60 tests on the rebased head (the pre-rebase head collected 58; the delta is entirely main-side: 3 unit-class ids removed by pytorch#198440's restructure and 5 main-added tests absent from the older base); no instantiated `TestFastLauncher*` variants on a CPU-only host, as designed.
- Run: 22 passed, 36 skipped, 2 failed. Both failures are in the untouched `TestStaticTritonLauncherUnit` (the CPU wheel carries no `_FastXpuLauncher` extension, and without Triton/GPU compilation no cubin is produced) and reproduce identically on the unmodified current-main file in the same environment (wheel-vs-trunk drift), so this change is CPU-neutral.
- Import probe: importing the module with a recording stub over `instantiate_device_type_tests` asserts both generic classes, their `hw_classification` values, the exact test placement (the 5 `test_xpu_*` tests only in `TestFastLauncherXpuOnly`), helper resolution through `_FastLauncherMixin`, the retained skip guards, and the instantiate kwargs; `filter_by_hw_classification` is exercised directly (`{ACCELERATOR}` keeps the shared class, `{XPU}` keeps `TestFastLauncherXpuOnly`).
- Lint: pyfmt and CI-pinned ruff 0.14.4 (check + format) clean; `test_linter.py` reports nothing (the file is in its allowlist, like the precedent files above).

CUDA and XPU on-device execution of the instantiated classes is delegated to CI; the authoring host has neither device.

## Agent details (if applicable)

This description and the linked review replies were drafted with an AI assistant and reviewed against the diff by the author before posting.

Rebase note (2026-11-16): rebased onto current main after pytorch#198440 landed. pytorch#198440 refactored the separate `TestFastLauncherCompileResult` class (untouched here) and gathered the file's `instantiate_device_type_tests` calls into a single trailing group; this PR's two instantiation calls now join that group and its two import lines dedup against main. The branch's three commits were squashed into one (head `d3924245614`); diff +61/-33 -> +57/-33; no scope change.

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

Summary

Completes the device-agnostic migration of the CUDA-facing tests in
TestStaticTritonLauncher on top of the post-pytorch#198439/pytorch#198440 reality:

- the class becomes ACCELERATOR-classified and instantiated
  (except_for="cpu", allow_xpu=True); the class-level
  @requires_gpu_and_triton decorator is replaced by per-test
  Triton skips so the instantiated variants keep the same effective
  guard set;
- float/scalar/ABI tests that were missing the injected device now
  take it (test_float_scalars, test_bfloat16_scalar, and both
  oversized-shared-memory tests), replacing GPU_TYPE in the bodies;
- the six XPU-specific tests move to a dedicated XPU-classified
  TestStaticTritonLauncherXpuOnly instantiated with only_for="xpu",
  mirroring TestFastLauncherXpuOnly from pytorch#198439 - XPU capsule/ABI
  behavior is accelerator-specific and does not belong in an
  ACCELERATOR class;
- the mixin helpers already gained device parameters via
  pytorch#198439/pytorch#198440, so this PR no longer touches them; the
  XPU-only tests pytorch#198439 added to the old class are preserved
  verbatim (in their new home).

Test Plan

- cpu-wheel venv (no accelerator here): collection and skip profile
  reviewed; remaining failures are wheel-vs-trunk drift artifacts
  reproduced identically on the pristine base file;
- the XPU-specific split is covered by the CI xpu shards
  (only_for="xpu") - no local XPU hardware here;
- lintrunner and the in-tree test linter clean for this class region
  with the allowlist entry for the file removed.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 17, 2026
…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.
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
…via instantiate_device_type_tests

Summary

Completes the device-agnostic migration of the CUDA-facing tests in
TestStaticTritonLauncher on top of the post-pytorch#198439/pytorch#198440 reality:

- the class becomes ACCELERATOR-classified and instantiated
  (except_for="cpu", allow_xpu=True); the class-level
  @requires_gpu_and_triton decorator is replaced by per-test
  Triton skips so the instantiated variants keep the same effective
  guard set;
- float/scalar/ABI tests that were missing the injected device now
  take it (test_float_scalars, test_bfloat16_scalar, and both
  oversized-shared-memory tests), replacing GPU_TYPE in the bodies;
- the six XPU-specific tests move to a dedicated XPU-classified
  TestStaticTritonLauncherXpuOnly instantiated with only_for="xpu",
  mirroring TestFastLauncherXpuOnly from pytorch#198439 - XPU capsule/ABI
  behavior is accelerator-specific and does not belong in an
  ACCELERATOR class;
- the mixin helpers already gained device parameters via
  pytorch#198439/pytorch#198440, so this PR no longer touches them; the
  XPU-only tests pytorch#198439 added to the old class are preserved
  verbatim (in their new home).

Test Plan

- cpu-wheel venv (no accelerator here): collection and skip profile
  reviewed; remaining failures are wheel-vs-trunk drift artifacts
  reproduced identically on the pristine base file;
- the XPU-specific split is covered by the CI xpu shards
  (only_for="xpu") - no local XPU hardware here;
- lintrunner and the in-tree test linter clean for this class region
  with the allowlist entry for the file removed.
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 18, 2026
…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 added a commit to gavinwang269/pytorch that referenced this pull request Nov 20, 2026
…r device injection

Summary

The automated review on pytorch#205277 flagged the `ACCELERATOR` -> `CUDA` relabel of
`TestFastLauncher` and `TestFastLauncherFallbackCompileResult` as a blocking
mislabel, and this commit agrees with it after checking the mechanism in the
code. Both classes are still instantiated with `only_for=("cuda", "xpu")`,
`allow_xpu=True`, and `get_hw_classification` reads the attribute with
`getattr`, so the generated XPU variants inherited the `CUDA` label: on an XPU
host `--hw-classification ACCELERATOR XPU` would have dropped these tests, and
because the test linter only checks the declaration on a device-specific class,
the two `only_for` errors those classes report vanished with the label instead
of with a fix. Both declarations go back to `ACCELERATOR`, matching the
structure that landed through pytorch#198439/pytorch#198440. The consequence is that this
file's entry in `tools/linter/adapters/test_linter_allowlist.json` has to stay
until pytorch#204896 adds tuple labels, which is the only end state where
`(CUDA, XPU)` can drop both the allowlist entry and the device restriction.

What clears the errors honestly is the device injection, which is completed
here rather than relabeled around: `_fast_launcher_cls`, `_stream` and
`_store_sum_launcher` take an optional `device` defaulting to `GPU_TYPE`, and
the `TestFastLauncher` tests pass their injected device at every helper call
site, including the three `_make_launcher` calls that still fell back to the
global. `test_build_fast_launcher_launches` now derives `device_props` from the
injected device instead of `GPU_TYPE`, which is what `_build_fast_launcher`
compares against `xpu`/`cuda`/`hip`. The defaults leave
`TestFastLauncherXpuOnly`, which takes no device parameter, on exactly its old
path. The fallback class docstring no longer claims "every accelerator".

Test Plan

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

Simulated the linter over this file with its allowlist entry removed, by
importing the in-tree adapter and clearing its allowlist set:

```
python3 -I - <<'EOF'
import importlib.util, sys
spec = importlib.util.spec_from_file_location(
    "test_linter", "tools/linter/adapters/test_linter.py")
mod = importlib.util.module_from_spec(spec)
sys.modules["test_linter"] = mod
spec.loader.exec_module(mod)
mod._allowlist = set()
for m in mod.check_file("test/inductor/test_static_triton_launcher.py"):
    print(m.name, m.line)
EOF
```

main reports 13 findings (8 `device_param`, 2 `only_for`, and 3
`hw_classification` in class regions owned by sibling PRs); this head reports 5
(the same 2 `only_for` plus those 3). The 8 `device_param` findings are gone
because the methods take `device`, not because of any label. With the allowlist
as it stands in CI today, the file is clean:

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

The RUFF and PYFMT adapters, run through `uv` the way `.lintrunner.toml` does
and falsification-checked against planted violations first, 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 run used 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 ones from main and from the previous head. On a host
with neither CUDA nor XPU, `instantiate_device_type_tests` generates no
device-suffixed variants at all, so variant generation for `allow_xpu=True` is
verified by the fact that the instantiate calls are untouched here and by the
respective CI shards.
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 to gavinwang269/pytorch that referenced this pull request Nov 26, 2026
…r device injection

Summary

The automated review on pytorch#205277 flagged the `ACCELERATOR` -> `CUDA` relabel of
`TestFastLauncher` and `TestFastLauncherFallbackCompileResult` as a blocking
mislabel, and this commit agrees with it after checking the mechanism in the
code. Both classes are still instantiated with `only_for=("cuda", "xpu")`,
`allow_xpu=True`, and `get_hw_classification` reads the attribute with
`getattr`, so the generated XPU variants inherited the `CUDA` label: on an XPU
host `--hw-classification ACCELERATOR XPU` would have dropped these tests, and
because the test linter only checks the declaration on a device-specific class,
the two `only_for` errors those classes report vanished with the label instead
of with a fix. Both declarations go back to `ACCELERATOR`, matching the
structure that landed through pytorch#198439/pytorch#198440. The consequence is that this
file's entry in `tools/linter/adapters/test_linter_allowlist.json` has to stay
until pytorch#204896 adds tuple labels, which is the only end state where
`(CUDA, XPU)` can drop both the allowlist entry and the device restriction.

What clears the errors honestly is the device injection, which is completed
here rather than relabeled around: `_fast_launcher_cls`, `_stream` and
`_store_sum_launcher` take an optional `device` defaulting to `GPU_TYPE`, and
the `TestFastLauncher` tests pass their injected device at every helper call
site, including the three `_make_launcher` calls that still fell back to the
global. `test_build_fast_launcher_launches` now derives `device_props` from the
injected device instead of `GPU_TYPE`, which is what `_build_fast_launcher`
compares against `xpu`/`cuda`/`hip`. The defaults leave
`TestFastLauncherXpuOnly`, which takes no device parameter, on exactly its old
path. The fallback class docstring no longer claims "every accelerator".

Test Plan

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

Simulated the linter over this file with its allowlist entry removed, by
importing the in-tree adapter and clearing its allowlist set:

```
python3 -I - <<'EOF'
import importlib.util, sys
spec = importlib.util.spec_from_file_location(
    "test_linter", "tools/linter/adapters/test_linter.py")
mod = importlib.util.module_from_spec(spec)
sys.modules["test_linter"] = mod
spec.loader.exec_module(mod)
mod._allowlist = set()
for m in mod.check_file("test/inductor/test_static_triton_launcher.py"):
    print(m.name, m.line)
EOF
```

main reports 13 findings (8 `device_param`, 2 `only_for`, and 3
`hw_classification` in class regions owned by sibling PRs); this head reports 5
(the same 2 `only_for` plus those 3). The 8 `device_param` findings are gone
because the methods take `device`, not because of any label. With the allowlist
as it stands in CI today, the file is clean:

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

The RUFF and PYFMT adapters, run through `uv` the way `.lintrunner.toml` does
and falsification-checked against planted violations first, 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 run used 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 ones from main and from the previous head. On a host
with neither CUDA nor XPU, `instantiate_device_type_tests` generates no
device-suffixed variants at all, so variant generation for `allow_xpu=True` is
verified by the fact that the instantiate calls are untouched here and by 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 added a commit to gavinwang269/pytorch that referenced this pull request Dec 1, 2026
…via instantiate_device_type_tests

Summary

Completes the device-agnostic migration of the CUDA-facing tests in
TestStaticTritonLauncher on top of the post-pytorch#198439/pytorch#198440 reality:

- the class becomes ACCELERATOR-classified and instantiated
  (except_for="cpu", allow_xpu=True); the class-level
  @requires_gpu_and_triton decorator is replaced by per-test
  Triton skips so the instantiated variants keep the same effective
  guard set;
- float/scalar/ABI tests that were missing the injected device now
  take it (test_float_scalars, test_bfloat16_scalar, and both
  oversized-shared-memory tests), replacing GPU_TYPE in the bodies;
- the six XPU-specific tests move to a dedicated XPU-classified
  TestStaticTritonLauncherXpuOnly instantiated with only_for="xpu",
  mirroring TestFastLauncherXpuOnly from pytorch#198439 - XPU capsule/ABI
  behavior is accelerator-specific and does not belong in an
  ACCELERATOR class;
- the mixin helpers already gained device parameters via
  pytorch#198439/pytorch#198440, so this PR no longer touches them; the
  XPU-only tests pytorch#198439 added to the old class are preserved
  verbatim (in their new home).

Test Plan

- cpu-wheel venv (no accelerator here): collection and skip profile
  reviewed; remaining failures are wheel-vs-trunk drift artifacts
  reproduced identically on the pristine base file;
- the XPU-specific split is covered by the CI xpu shards
  (only_for="xpu") - no local XPU hardware here;
- lintrunner and the in-tree test linter clean for this class region
  with the allowlist entry for the file removed.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged missing actionable issue A PR without a linked actionable issue or maintainer sponsor 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.

5 participants