Skip to content

[Testcase Refactoring] Inject device into TestFastLauncher tests and mixin helpers - #205277

Closed
gavinwang269 wants to merge 2 commits into
pytorch:mainfrom
gavinwang269:stl/p-fastdev
Closed

gavinwang269 wants to merge 2 commits into
pytorch:mainfrom
gavinwang269:stl/p-fastdev

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

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.

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

Linked issue or supporting maintainer

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

@pytorch-bot

pytorch-bot Bot commented Nov 17, 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 passes the injected `device` into the eight remaining `TestFastLauncher`
tests and into the `_FastLauncherMixin` helpers, each of which now takes an
optional `device` that defaults to `GPU_TYPE`. Recommendation: Approve. Two
non-blocking points remain, but the review asks for the PR description to be
corrected before merge.

Findings (2):

[minor] test/inductor/test_static_triton_launcher.py:1580
Non-blocking: the PR description no longer matches HEAD and should be rewritten.
- Classification: it says both classes are reclassified `ACCELERATOR` -> `CUDA`,
but at HEAD (:1624, :1991) both are still `ACCELERATOR`.
- Scope: it says the mixins are unchanged (+33/-33). In fact all four
`_FastLauncherMixin` helpers gained a `device` parameter (:1580-1617), and the
diff is about +80/-76.
- Test Plan: only the eight `device_param` linter errors clear. Both classes are
still instantiated with `only_for=("cuda", "xpu")` (:2147-2158), which
`OnlyForRule` flags and REVIEW.md Rule 4 forbids, so the file has to stay in
`test_linter_allowlist.json`. Scenario 1 accepts an interim Rule 4 gap only when
it is explained.
Fix: say that both classes stay `ACCELERATOR` with `only_for` (and the allowlist
entry) until # 204896 adds tuple labels, and consider a `# TODO(# 204896)` at
both instantiation calls. If `only_for` is later swapped for `except_for="cpu"`:
`_fast_launcher_cls` returns `_FastCudaLauncher` for every device other than
xpu, so MPS and PrivateUse1 would also need to be excluded.

[minor] test/inductor/test_static_triton_launcher.py:1670
Non-blocking: `test_bfloat16_scalar` now takes `device` in an `ACCELERATOR`
class, but it is still gated by `@​ unittest.skipIf(not HAS_XPU_AND_TRITON and
not SM80OrLater, ...)`. That condition depends on what the host has, not on the
device the test was given. On a host with XPU and a pre-SM80 CUDA GPU, the CUDA
variant is not skipped. Rule 4 lists the device-type-aware skips instead: use `@​
skipCUDAIf(not SM80OrLater, "uses bfloat16 which requires SM >= 80")` from
`common_device_type`. It is not imported yet; line 48 imports only
`instantiate_device_type_tests`.

Reviewed commit: 372e445 (NOT the current head ae7b10b)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit ae7b10b with merge base 94957ce (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 Nov 17, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

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.
@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 17, 2026
gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 18, 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 Nov 18, 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 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.
@pytorch-bot pytorch-bot Bot added open source and removed triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module bot-triaged This is a label only to be used by the auto triage bot open source missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Nov 20, 2026
@github-actions
github-actions Bot requested a review from fffrog November 20, 2026 02:07
@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 Nov 20, 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 Nov 20, 2026
github-actions[bot]

This comment was marked as outdated.

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.
@gavinwang269 gavinwang269 changed the title [Testcase Refactoring] Inject device into TestFastLauncher tests and align hw classifications [Testcase Refactoring] Inject device into TestFastLauncher tests and mixin helpers Nov 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of 372e445: nothing blocking; ready for human review.

The PR passes the injected device into the eight remaining TestFastLauncher tests and into the _FastLauncherMixin helpers, each of which now takes an optional device that defaults to GPU_TYPE. Recommendation: Approve. Two non-blocking points remain, but the review asks for the PR description to be corrected before merge.

⚪ 2 non-blocking findings

def _fast_launcher_cls(self, device: str | None = None):

Non-blocking: the PR description no longer matches HEAD and should be rewritten.

  • Classification: it says both classes are reclassified ACCELERATOR -> CUDA, but at HEAD (:1624, :1991) both are still ACCELERATOR.
  • Scope: it says the mixins are unchanged (+33/-33). In fact all four _FastLauncherMixin helpers gained a device parameter (:1580-1617), and the diff is about +80/-76.
  • Test Plan: only the eight device_param linter errors clear. Both classes are still instantiated with only_for=("cuda", "xpu") (:2147-2158), which OnlyForRule flags and REVIEW.md Rule 4 forbids, so the file has to stay in test_linter_allowlist.json. Scenario 1 accepts an interim Rule 4 gap only when it is explained.
    Fix: say that both classes stay ACCELERATOR with only_for (and the allowlist entry) until # 204896 adds tuple labels, and consider a # TODO(\# 204896) at both instantiation calls. If only_for is later swapped for except_for="cpu": _fast_launcher_cls returns _FastCudaLauncher for every device other than xpu, so MPS and PrivateUse1 would also need to be excluded.

def test_bfloat16_scalar(self, device):

Non-blocking: test_bfloat16_scalar now takes device in an ACCELERATOR class, but it is still gated by @ unittest.skipIf(not HAS_XPU_AND_TRITON and not SM80OrLater, ...). That condition depends on what the host has, not on the device the test was given. On a host with XPU and a pre-SM80 CUDA GPU, the CUDA variant is not skipped. Rule 4 lists the device-type-aware skips instead: use @ skipCUDAIf(not SM80OrLater, "uses bfloat16 which requires SM &gt;= 80") from common_device_type. It is not imported yet; line 48 imports only instantiate_device_type_tests.

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

@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 26, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

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

Learn more about merging in the wiki.

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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 2 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable), trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable). Blocking jobs that the merge waited on for a Dr.CI or AI CI Advisor classification: 2.

Details for Dev Infra team

Raised by workflow job

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -r

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

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

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

Copy link
Copy Markdown
Collaborator

Successfully rebased stl/p-fastdev onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout stl/p-fastdev && git pull --rebase)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

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

Learn more about merging in the wiki.

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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

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

Dig deeper by viewing the failures on hud

Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

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

Learn more about merging in the wiki.

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

Advanced Debugging
Check the merge workflow status
here

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
…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.
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 module: inductor 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

None yet

Development

Successfully merging this pull request may close these issues.

5 participants