Skip to content

Support multiple device hardware classifications - #204896

Open
can-gaa-hou wants to merge 2 commits into
gh/can-gaa-hou/62/basefrom
gh/can-gaa-hou/62/head
Open

can-gaa-hou wants to merge 2 commits into
gh/can-gaa-hou/62/basefrom
gh/can-gaa-hou/62/head

Conversation

@can-gaa-hou

@can-gaa-hou can-gaa-hou commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Allow device-specific tuples with any-match selection and exclusion precedence.

Test Plan

conda run --no-capture-output -n pytorch python test/test_testing.py TestHardwareClassifications -v
conda run --no-capture-output -n pytorch python -m unittest tools.test.test_test_linter
conda run --no-capture-output -n pytorch lintrunner -a

Tests passed (24 + 33); lintrunner could not start: Permission denied (os error 13).

Agent details
Authored with an AI assistant.

[ghstack-poisoned]
@can-gaa-hou
can-gaa-hou requested review from a team and fffrog as code owners November 14, 2026 03:39
@pytorch-bot

pytorch-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 055f35e with merge base b09cae0 (image):
💚 Looks good so far! There are no failures yet. 💚

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

[ghstack-poisoned]
can-gaa-hou added a commit that referenced this pull request Nov 14, 2026
Allow device-specific tuples with any-match selection and exclusion precedence.

Test Plan
```
conda run --no-capture-output -n pytorch python test/test_testing.py TestHardwareClassifications -v
conda run --no-capture-output -n pytorch python -m unittest tools.test.test_test_linter
conda run --no-capture-output -n pytorch lintrunner -a
```
Tests passed (24 + 33); lintrunner could not start: Permission denied (os error 13).

Agent details
Authored with an AI assistant.

ghstack-source-id: b2c7f9e
Pull-Request: #204896
@fffrog

fffrog commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Hi @can-gaa-hou,

Thank you for proposing this.

However, I'm concerned that supporting the new pattern introduced in this PR will increase the maintenance burden for PyTorch's test suite. Instead of properly refactoring tests to be accelerator-agnostic, new vendors might simply add ad-hoc if/else checks using hw_classification.XXX to accommodate their own hardware.

@fffrog fffrog left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe more dicusstions are needed here.

@fffrog fffrog moved this from Backlog to Developing in PyTorch Test Refactoring Nov 17, 2026
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

This branch was previously deployed

1 inactive (outdated) deployment
bedrock — 85974e36 Deployed Nov 14, 2026 by pytorchbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Developing

Development

Successfully merging this pull request may close these issues.

3 participants