Skip to content

[Testcase Refactoring] Make test_smoke device-agnostic via instantiate_device_type_tests - #192434

Closed
gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:test/inductor-smoke-decouple
Closed

gavinwang269 wants to merge 1 commit into
pytorch:mainfrom
gavinwang269:test/inductor-smoke-decouple

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

test/inductor/test_smoke.py gates its accelerator tests with
@unittest.skipIf(not HAS_GPU, ...) and builds their tensors on the GPU_TYPE constant
imported from torch.testing/_internal/inductor_utils. Both are resolved once, at import,
from whichever device the process happened to initialise, so the file cannot say which
device a test is about to exercise, and every host inherits the same answer.

This change moves that decision into the framework's own mechanism. It touches two files:
the test file, and its now-unneeded exemption in
tools/linter/adapters/test_linter_allowlist.json.

Changes

  • SmokeTest is split. The generic half keeps test_compile_invalid_options, which
    touches no device and stays a plain TestCase. The accelerator half becomes
    SmokeTestDevice, declared HardwareClassification.ACCELERATOR and instantiated with
    instantiate_device_type_tests(..., globals(), except_for="cpu", allow_xpu=True), the
    form test/inductor/test_selective_lowering.py:56 and
    test/inductor/test_symm_mem_registry.py:440 already use. only_for is deliberately not
    used: test/REVIEW.md Rule 4 says "only_for must not be used" for ACCELERATOR classes,
    and it would also drop the PrivateUse1, HPU and TORCH_TEST_DEVICES bases that this PR's
    own motivation is about keeping.
  • test_compile_invalid_options keeps base behavior with a tightened assertion:
    self.assertRaisesRegex(RuntimeError, "Unrecognized mode=ha") pins the message
    torch/_inductor/__init__.py:408 raises, instead of the bare assertRaises(RuntimeError)
    inherited from base that accepted any compilation error.
  • Test bodies take device and construct their tensors there, inside the test methods;
    the GPU_TYPE import is gone, and no if device == ... branch appears. test_mlp
    registers self.addCleanup(torch._logging.set_logs) before enabling DEBUG logging, so a
    failure no longer leaks the log level into later tests in the same process.
  • The two accelerator tests are gated with @requires_triton(), as can-gaa-hou asked in
    [Testcase Refactoring] Make test_smoke device-agnostic via instantiate_device_type_tests #192434 (comment). Stated plainly:
    requires_triton is functools.partial(unittest.skipIf, not HAS_TRITON, ...)
    (inductor_utils.py:202), so like the HAS_GPU it replaces it is a process-wide boolean.
    This PR makes the instantiation per-device, not the gate.
  • The test/inductor/test_smoke.py row is deleted from
    tools/linter/adapters/test_linter_allowlist.json (Rule 7). That row was why TEST_LINTER
    stayed silent: with the row removed, the file is checked, and the check is demonstrably
    live -- see the negative control in the Test Plan.
  • The __main__ block is left byte-identical to the base commit, including the
    IS_LINUX and HAS_GPU and major <= 5 conditions. run_test.py invokes this file as a
    script, so that block decides which tests CI executes, and changing it is not this PR's to
    make.

What CI executes

Because run_test.py runs the file as python test_smoke.py (test/run_test.py:687), the
unchanged __main__ guard decides what each shard runs; the pytest invocations below are
local measurements, not a CI path. Reading the guard against the sources, before and after
this PR alike:

  • CUDA and ROCm shards: HAS_CUDA_AND_TRITON is true and the major <= 5 disjunct is false
    on any Triton-capable GPU (is_triton_capable requires HIP or compute capability 7 or
    later, torch/_dynamo/device_interface.py:433-441), so run_tests() is never called:
    the instantiated CUDA classes are generated but not executed by CI.
  • CPU-only shards: HAS_GPU is false (inductor_utils.py:82), the script path runs
    nothing from this file.
  • Out-of-tree backends: upstream CI installs none, so no PrivateUse1 class is generated
    there at all; the NPU numbers below come from a local wheel on an Ascend 910B4 host.
  • XPU is the one accelerator whose shards would execute these bodies (allow_xpu=True
    plus PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu, and the default shard suite keeps this file),
    but the xpu workflow only reacts to the ciflow/xpu label, viable/strict, its
    schedule, or manual dispatch (.github/workflows/xpu.yml:4-14). This PR does not carry
    that label (it carries ciflow/trunk and ciflow/inductor, neither of which reaches xpu.yml), so
    no XPU test job has run on any of its heads (two older heads show an XPU
    build job only). A green test_mlp_xpu / test_compile_decorator_xpu result can
    therefore only come from a run triggered after adding ciflow/xpu (and approving the
    workflows, as for the other ciflow families of this fork PR).

Known coverage changes: MTIA and fbcode/sandcastle

get_device_type_test_bases() (common_device_type.py:1023-1052) has no MTIA base, so on
an MTIA host SmokeTestDevice is not generated and test_mlp / test_compile_decorator
stop running there, whereas base did run them (HAS_GPU includes HAS_MTIA_AND_TRITON,
and GPU_TYPE resolved to mtia). That is a reading of the base sources, not a
measurement: no MTIA hardware is available here. Keeping the coverage inside this file
would break the rules it is being migrated under: hw_classification has exactly six
members (GENERIC, ACCELERATOR, CPU, CUDA, MPS, XPU;
tools/linter/adapters/test_linter.py:105-111), so Rule 2 cannot describe an MTIA class,
and Rule 4 requires ACCELERATOR classes to be instantiated, which offers no MTIA base. The
structural fix, an MTIA device test base, is a separate change. This documented drop
still needs the MTIA owners' explicit acceptance
: the question is open in the thread at
#192434 (comment) (comment
#192434 (comment)), unanswered since
2026-11-02, and nothing here assumes an answer.

The second drop is on fbcode/sandcastle hosts (an internal-build code read, not verifiable
from OSS): get_device_type_test_bases() yields only the CPU base unless IS_REMOTE_GPU
(PYTORCH_TEST_REMOTE_GPU, common_utils.py:421-424) is set, and even then the CUDA base is
dropped when ASAN, TSAN, UBSAN or TEST_WITH_MTIA is on (common_device_type.py:1028-1038).
Base ran these tests wherever HAS_GPU held, such hosts included; with except_for="cpu"
those hosts now generate no device class at all. Whether internal GPU targets set
PYTORCH_TEST_REMOTE_GPU cannot be confirmed from this repository, so the loss is filed here
as a known coverage change rather than assumed away.

Out-of-tree results

With except_for="cpu" the framework generates a PrivateUse1 class on a host that has an
out-of-tree backend registered, and on this host two of its tests fail for reasons inside
that backend:

test_compile_decorator_npu: TypeError: WrappedFunction.__init__() missing 2 required
  positional arguments: 'cudagraph_managed_input_rerecord_limit' and
  'cudagraph_managed_input_rerecord_action'
  (raised at torch_npu/npu/_graph_tree.py:2527, from parameters the wheel's own
  torch/_inductor/cudagraph_trees.py:576-577 defines)
test_mlp_npu: torch._inductor.exc.InductorError: TypeError:
  NPUPythonWrapperCodeGen._generate_extern_kernel_out_helper() got an unexpected keyword
  argument 'tunable_dyn_dims_mask'

Both are raised inside the out-of-tree backend's own wrapper codegen: its hooks predate the
inductor APIs it now runs against. Upstream CI has no out-of-tree backend, so these do not
gate this PR; they belong to the backend's own test configuration, whose documented
mechanism is PrivateUse1TestBase.set_test_configs(test_exclusions=...)
(docs/source/accelerator/testing.md:56). Adding an upstream per-device skip was rejected:
the allowed device-specific skip decorators (test/REVIEW.md:154-160) are @skipCPUIf,
@skipCUDAIf, @skipXPUIf, @skipMPSIf and the accelerator-aware @skipIf -- there is
no out-of-tree entry -- and a bare expectedFailure would swallow any exception, not just
these.

Test Plan

Two prebuilt wheel venvs, no source file overlaid onto site-packages, every run started
from /tmp (from the repository root python -m pytest puts the source tree on sys.path
and imports a torch with no built version.py, which fails for unrelated reasons).

W=<worktree>/test/inductor/test_smoke.py

# cpu wheel, out-of-tree backend autoloaded:  3 tests collected, 1 passed, 2 skipped
#   (the skips are SmokeTestDevicePRIVATEUSE1, reason "requires triton")
env -u PYTHONPATH <cpu-python> -m pytest $W -q
# cpu wheel, true CPU-only (TORCH_DEVICE_BACKEND_AUTOLOAD=0): 1 test collected, 1 passed
# npu wheel, Ascend 910B4 (no CUDA/XPU present): 2 failed, 1 passed
#   (the two failures are the out-of-tree cases described above)
lintrunner $W <worktree>/tools/linter/adapters/test_linter_allowlist.json   # ok No lint issues.

Negative control, to show the linter claim is not vacuous. With the allowlist row deleted:

<cpu-python> tools/linter/adapters/test_linter.py test/inductor/test_smoke.py   # no findings
# re-insert `only_for=("cuda", "xpu")` in the same file, same command:
# {"name":"[only_for]","severity":"error","line":69,"description":"Test class
#  'SmokeTestDevice' (ACCELERATOR): must not use only_for in
#  instantiate_device_type_tests; use except_for instead."}

Verification Report

State Host Collected Passed Failed Skipped
this PR CPU wheel, torch_npu autoloaded 3 1 0 2 (requires triton)
this PR CPU wheel, TORCH_DEVICE_BACKEND_AUTOLOAD=0 1 1 0 0 (no device class generated)
this PR NPU (Ascend 910B4, triton-ascend present) 3 1 2 0 (backend-side failures above)
Item Version
PyTorch (cpu and npu venvs) 2.16.0.dev20261029+cpu
torch_npu 2.16.0.dev20261029+git737bb43
CANN 9.2.0
Python 3.12
Hardware Ascend 910B4 (no CUDA/XPU present)

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

@pytorch-bot

pytorch-bot Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
✅ AUTOMATED REVIEW - Ready for human review:

The PR splits test/inductor/test_smoke.py into a GENERIC SmokeTest and an
ACCELERATOR SmokeTestDevice instantiated with
instantiate_device_type_tests(except_for="cpu", allow_xpu=True) and gated by @​
requires_triton(), and removes its linter allowlist row. Recommendation: Needs
Discussion. The review finds no code defect, but asks for a green ciflow/xpu run
and explicit maintainer acceptance (or a fallback) for the lost MTIA/fbcode
coverage before merge.

Findings (2):

[minor] test/inductor/test_smoke.py:69
No CI job has run the new device tests. run_test.py runs this file as a script,
so the unchanged __main__ guard decides what CI executes. On CUDA/ROCm,
HAS_CUDA_AND_TRITON implies HIP or major >= 7, so `major <= 5` is false and
run_tests() is never reached: SmokeTestDeviceCUDA is generated but never
executed. On CPU-only and PrivateUse1-only shards HAS_GPU is false. That leaves
Linux XPU as the only upstream path that runs test_mlp_xpu /
test_compile_decorator_xpu, the bodies this PR rewrote (`device` instead of
GPU_TYPE, plus the new addCleanup). xpu.yml fires only on ciflow/xpu,
viable/strict, a schedule or manual dispatch, and the XPU job in pull.yml only
builds, so the green checks say nothing about these tests. Fix: add ciflow/xpu
and get a green XPU test run before merging. (The inverted `<= 5` check predates
this PR and is left alone, as can-gaa-hou asked.)

[minor] test/inductor/test_smoke.py:70
MTIA and some internal GPU hosts lose test_mlp and test_compile_decorator
entirely. On MTIA, base ran both tests (HAS_GPU includes HAS_MTIA_AND_TRITON and
GPU_TYPE can resolve to mtia), but get_device_type_test_bases() has no MTIA base
and there is no MTIATestBase in the tree. Under IS_FBCODE/IS_SANDCASTLE without
IS_REMOTE_GPU it adds only CPUTestBase, and even with IS_REMOTE_GPU the CUDA
base is dropped under ASAN/TSAN/UBSAN or TEST_WITH_MTIA. With except_for="cpu"
those hosts get no device class, so the tests vanish rather than skip. The
description documents this but says it "still needs the MTIA owners' explicit
acceptance"; can-gaa-hou raised it and has not replied since 2026-11-02, and the
author's 2026-11-03 reply says the file "now carries SmokeTestMTIA", but that
class is no longer at HEAD. Fix: before landing, get an explicit decision from
can-gaa-hou or the MTIA owners: accept the drop, or keep a fallback until an
MTIA device test base exists.

Reviewed commit: fa5b276

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit fa5b276 with merge base 113a303 (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 Aug 7, 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/inductor"

@pytorch-bot

pytorch-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Didn't find following labels among repository labels: module: tests/inductor

@gavinwang269 gavinwang269 changed the title Decouple test_smoke.py for device-agnostic testing [Testcase Refactoring] Make test_smoke device-agnostic via instantiate_device_type_tests Aug 7, 2026
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch 9 times, most recently from fe3adfd to 365950f Compare August 7, 2026 11:51
@jansel

jansel commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 11m 7s —— View job


Review

The refactor direction is reasonable, but as committed it does not actually accomplish the stated goal — the __main__ guard the PR description claims to have removed is still in the file, and the change silently drops Triton gating plus XPU/MTIA coverage.

Detailed review of test/inductor/test_smoke.py

1. Blocker: the __main__ guard was not removed (contradicts the PR description)

The PR body says the guard was "replaced with plain run_tests()", but the file still has it:

if __name__ == "__main__":
from torch._inductor.test_case import run_tests
if IS_LINUX and HAS_GPU:
if (not HAS_CUDA_AND_TRITON) or torch.cuda.get_device_properties(0).major <= 5:
run_tests()

if __name__ == "__main__":
    from torch._inductor.test_case import run_tests

    if IS_LINUX and HAS_GPU:
        if (not HAS_CUDA_AND_TRITON) or torch.cuda.get_device_properties(0).major <= 5:
            run_tests()

HAS_GPU is HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON (torch/testing/_internal/inductor_utils.py:82), so on a PrivateUse1 backend such as Ascend NPU it is False and run_tests() is never called under python test/inductor/test_smoke.py. That is precisely the failure mode the PR sets out to fix. On CPU-only machines the new GENERIC test_compile_invalid_options also never runs. The residual guard is also why IS_LINUX, HAS_GPU, and HAS_CUDA_AND_TRITON are still imported at line 7-8 — they should all disappear together.

Please either actually delete the guard down to run_tests(), or update the PR description to match what the code does. Note the NPU verification table (3 cases) can only have been produced via pytest, not the standard runner, so it does not exercise this path.

Fix this →

2. Triton gating is lost — CUDA-without-Triton configs now fail instead of skip

The old decorator was @unittest.skipIf(not HAS_GPU, "Triton is not available"), and HAS_GPU requires Triton. On a CUDA machine with no Triton installed, test_mlp and test_compile_decorator used to skip; now except_for="cpu" instantiates them for CUDA unconditionally and they will attempt torch.compile with no Triton backend. Add explicit gating on the device class, e.g.:

from torch.testing._internal.inductor_utils import requires_triton

@requires_triton()
class SmokeTestDevice(TestCase):
    ...

This also matters for the NPU case: nothing in the new code checks that the accelerator has a working Inductor/Triton backend. What skipped the 2 ACCELERATOR cases in your NPU run — an out-of-tree test_exclusions entry? If so, in-tree users of other PrivateUse1 backends get a hard failure rather than a skip.

3. Coverage regression: XPU and MTIA no longer run these tests

get_device_type_test_bases() (common_device_type.py:913-942) returns only CPU, CUDA, PrivateUse1, and HPU. XPUTestBase is added only when allow_xpu=True, and there is no MTIA base at all. Since the old HAS_GPU covered HAS_XPU_AND_TRITON and HAS_MTIA_AND_TRITON with GPU_TYPE resolving to xpu/mtia, this change silently stops running test_mlp/test_compile_decorator on XPU and MTIA. At minimum pass allow_xpu=True (the surrounding inductor tests do — see test_analysis.py:668, test_compiled_optimizers.py:1279) and call out the MTIA loss in the description.

instantiate_device_type_tests(SmokeTestDevice, globals(), except_for="cpu", allow_xpu=True)

Fix this →

4. Mid-file import

from torch.testing._internal.common_device_type import instantiate_device_type_tests

instantiate_device_type_tests(SmokeTestDevice, globals(), except_for="cpu")

The import at line 64 sits between the class definitions and the call. Move it into the import block at the top of the file, matching every other inductor test in this directory.

5. Lint is red and trivially fixable

Lint / lintrunner-noclang-partial fails on PYFMT for two things: import sort order (IS_LINUX, HardwareClassification → HardwareClassification, IS_LINUX) and a missing blank line before instantiate_device_type_tests(...). Per the repo guidelines, run lintrunner -a before amending.

6. Minor notes

  • Test IDs change: SmokeTest.test_mlp becomes SmokeTestDeviceCUDA.test_mlp_cuda. I found no in-repo references, but any GitHub disable-test issues keyed on the old names will silently stop applying.
  • test_mlp restores logging with a bare torch._logging.set_logs() at the end of the body; if the test raises, DEBUG logging leaks into subsequent tests. Pre-existing, but it becomes more likely to bite now that the test actually runs on more configurations. A self.addCleanup(torch._logging.set_logs) would be a one-line fix.
  • The diff stat in the description (+24/-21) doesn't match the commit (+22/-18).
| Branch: `test/inductor-smoke-decouple`

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 10, 2026
@zou3519
zou3519 requested a review from fffrog August 10, 2026 03:43
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch from 365950f to cc16faa Compare August 10, 2026 09:16
@gavinwang269

gavinwang269 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor Author

"Thanks for the review! All points addressed in the latest push:\n\n1. main guard: Removed. Replaced with plain run_tests(). The IS_LINUX, HAS_GPU, and HAS_CUDA_AND_TRITON imports have been removed.\n\n2. Triton gating: Added @unittest.skipIf(not has_triton(), \"requires triton\") to test_mlp and test_compile_decorator. This ensures tests skip gracefully on devices where Triton is not available (e.g., CUDA-without-Triton), rather than crashing on torch.compile().\n\n3. XPU coverage: Fixed. Added allow_xpu=True to instantiate_device_type_tests to preserve XPU coverage that was previously included via HAS_XPU_AND_TRITON.\n\n4. Mid-file import: Fixed. instantiate_device_type_tests import moved to the top import block.\n\n5. Lint: Fixed. lintrunner -a passes with 0 issues.\n\n6. Minor notes: The NPU verification (3 passed, including 2 ACCELERATOR tests on Ascend 910B4) was produced via pytest, which exercises the instantiate_device_type_tests path. The __main__ guard removal ensures python test/inductor/test_smoke.py also works on all platforms.\n"


instantiate_device_type_tests(
SmokeTestDevice, globals(), except_for="cpu", allow_xpu=True
)

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.

The class SmokeTest is missed in this Test case, which should be added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! Added SmokeTest to instantiate_device_type_tests in the latest push (2ddc877).

Per the pattern established in #190173, GENERIC test classes are included in instantiate_device_type_tests alongside ACCELERATOR classes so that hw_classification filtering (--hw-classification GENERIC ACCELERATOR) works uniformly across all classes in the file. This is consistent with the existing usage in test_cpu_select_algorithm.py where GENERIC classes are also passed to instantiate_device_type_tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My earlier reply pointed at 2ddc877, but that state passed two classes to instantiate_device_type_tests, which accepts one class plus the module scope, so the head keeps the call on SmokeTestDevice only (head db41907, lines 69-71). Upstream convention is that GENERIC classes stay out of device instantiation (test_debug_utils.py and test_foreach.py leave their generic classes plain), and the call also deletes the generic class from module scope, so wrapping SmokeTest would duplicate a device-free check on every accelerator base instead of adding coverage. SmokeTest itself carries hw_classification = HardwareClassification.GENERIC (head lines 30-31), which is what the runner-side classification consumes.

JiasenTian
JiasenTian previously approved these changes Aug 11, 2026

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

Add Genertic and Accelerator classification for SmokeTest

github-actions[bot]

This comment was marked as outdated.

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 4, 2026
## Summary

`test/inductor/test_smoke.py` gates its accelerator tests with
`@unittest.skipIf(not HAS_GPU, ...)` and builds their tensors on the `GPU_TYPE` constant
imported from `torch.testing/_internal/inductor_utils`. Both are resolved once, at import,
from whichever device the process happened to initialise, so the file cannot say which
device a test is about to exercise, and every host inherits the same answer.

This change moves that decision into the framework's own mechanism. It touches two files:
the test file, and its now-unneeded exemption in
`tools/linter/adapters/test_linter_allowlist.json`.

## Changes

- `SmokeTest` is split. The generic half keeps `test_compile_invalid_options`, which
  touches no device and stays a plain `TestCase`. The accelerator half becomes
  `SmokeTestDevice`, declared `HardwareClassification.ACCELERATOR` and instantiated with
  `instantiate_device_type_tests(..., globals(), except_for="cpu", allow_xpu=True)`, the
  form `test/inductor/test_selective_lowering.py:56` and
  `test/inductor/test_symm_mem_registry.py:440` already use. `only_for` is deliberately not
  used: `test/REVIEW.md` Rule 4 says "`only_for` must not be used" for ACCELERATOR classes,
  and it would also drop the PrivateUse1, HPU and `TORCH_TEST_DEVICES` bases that this PR's
  own motivation is about keeping.
- Test bodies take `device` and construct their tensors there, inside the test methods;
  the `GPU_TYPE` import is gone, and no `if device == ...` branch appears. `test_mlp`
  registers `self.addCleanup(torch._logging.set_logs)` before enabling DEBUG logging, so a
  failure no longer leaks the log level into later tests in the same process.
- The two accelerator tests are gated with `@requires_triton()`, as can-gaa-hou asked in
  pytorch#192434 (comment). Stated plainly:
  `requires_triton` is `functools.partial(unittest.skipIf, not HAS_TRITON, ...)`
  (`inductor_utils.py:202`), so like the `HAS_GPU` it replaces it is a process-wide boolean.
  This PR makes the instantiation per-device, not the gate.
- The `test/inductor/test_smoke.py` row is deleted from
  `tools/linter/adapters/test_linter_allowlist.json` (Rule 7). That row was why `TEST_LINTER`
  stayed silent: with the row removed, the file is checked, and the check is demonstrably
  live -- see the negative control in the Test Plan.
- The `__main__` block is left byte-identical to the base commit, including the
  `IS_LINUX and HAS_GPU` and `major <= 5` conditions. `run_test.py` invokes this file as a
  script, so that block decides which tests CI executes, and changing it is not this PR's to
  make.

## What CI executes

Because `run_test.py` runs the file as `python test_smoke.py` (`test/run_test.py:687`), the
unchanged `__main__` guard decides what each shard runs; the pytest invocations below are
local measurements, not a CI path. Reading the guard against the sources, before and after
this PR alike:

- CUDA and ROCm shards: `HAS_CUDA_AND_TRITON` is true and the `major <= 5` disjunct is false
  on any Triton-capable GPU (`is_triton_capable` requires HIP or compute capability 7 or
  later, `torch/_dynamo/device_interface.py:433-441`), so `run_tests()` is never called:
  the instantiated CUDA classes are generated but not executed by CI.
- CPU-only shards: `HAS_GPU` is false (`inductor_utils.py:82`), the script path runs
  nothing from this file.
- Out-of-tree backends: upstream CI installs none, so no PrivateUse1 class is generated
  there at all; the NPU numbers below come from a local wheel on an Ascend 910B4 host.
- XPU is the one accelerator whose shards would execute these bodies (`allow_xpu=True`
  plus `PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu`, and the default shard suite keeps this file),
  but the xpu workflow only reacts to the `ciflow/xpu` label, `viable/strict`, its
  schedule, or manual dispatch (`.github/workflows/xpu.yml:4-14`). This PR does not carry
  that label, so no XPU test job has run on any of its heads (two older heads show an XPU
  build job only). A green `test_mlp_xpu` / `test_compile_decorator_xpu` result can
  therefore only come from a run triggered after adding `ciflow/xpu` (and approving the
  workflows, as for the other ciflow families of this fork PR).
- fbcode/sandcastle hosts (an internal-build code read, not verifiable from OSS):
  `get_device_type_test_bases()` yields only the CPU base unless `IS_REMOTE_GPU` is set,
  and then the CUDA base only when ASAN, TSAN, UBSAN and MTIA are all off
  (`common_device_type.py:1028-1038`); with `except_for="cpu"` those hosts generate no
  device class at all.

## Known coverage change: MTIA

`get_device_type_test_bases()` (`common_device_type.py:1023-1052`) has no MTIA base, so on
an MTIA host `SmokeTestDevice` is not generated and `test_mlp` / `test_compile_decorator`
stop running there, whereas base did run them (`HAS_GPU` includes `HAS_MTIA_AND_TRITON`,
and `GPU_TYPE` resolved to `mtia`). That is a reading of the base sources, not a
measurement: no MTIA hardware is available here. Keeping the coverage inside this file
would break the rules it is being migrated under: `hw_classification` has exactly six
members (`GENERIC`, `ACCELERATOR`, `CPU`, `CUDA`, `MPS`, `XPU`;
`tools/linter/adapters/test_linter.py:105-111`), so Rule 2 cannot describe an MTIA class,
and Rule 4 requires ACCELERATOR classes to be instantiated, which offers no MTIA base. The
structural fix, an MTIA device test base, is a separate change. **This documented drop
still needs the MTIA owners' explicit acceptance**: the question is open in the thread at
pytorch#192434 (comment) (comment
pytorch#192434 (comment)), unanswered since
2026-11-02, and nothing here assumes an answer.

## Out-of-tree results

With `except_for="cpu"` the framework generates a PrivateUse1 class on a host that has an
out-of-tree backend registered, and on this host two of its tests fail for reasons inside
that backend:

```
test_compile_decorator_npu: TypeError: WrappedFunction.__init__() missing 2 required
  positional arguments: 'cudagraph_managed_input_rerecord_limit' and
  'cudagraph_managed_input_rerecord_action'
  (raised at torch_npu/npu/_graph_tree.py:2527, from parameters the wheel's own
  torch/_inductor/cudagraph_trees.py:576-577 defines)
test_mlp_npu: torch._inductor.exc.InductorError: TypeError:
  NPUPythonWrapperCodeGen._generate_extern_kernel_out_helper() got an unexpected keyword
  argument 'tunable_dyn_dims_mask'
```

Both are raised inside the out-of-tree backend's own wrapper codegen: its hooks predate the
inductor APIs it now runs against. Upstream CI has no out-of-tree backend, so these do not
gate this PR; they belong to the backend's own test configuration, whose documented
mechanism is `PrivateUse1TestBase.set_test_configs(test_exclusions=...)`
(`docs/source/accelerator/testing.md:74`). Adding an upstream per-device skip was rejected:
the allowed device-specific skip decorators (`test/REVIEW.md:154-160`) are `@skipCPUIf`,
`@skipCUDAIf`, `@skipXPUIf`, `@skipMPSIf` and the accelerator-aware `@skipIf` -- there is
no out-of-tree entry -- and a bare `expectedFailure` would swallow any exception, not just
these.

## Test Plan

Two prebuilt wheel venvs, no source file overlaid onto site-packages, every run started
from `/tmp` (from the repository root `python -m pytest` puts the source tree on `sys.path`
and imports a `torch` with no built `version.py`, which fails for unrelated reasons).

```bash
W=<worktree>/test/inductor/test_smoke.py

# cpu wheel, out-of-tree backend autoloaded:  3 tests collected, 1 passed, 2 skipped
#   (the skips are SmokeTestDevicePRIVATEUSE1, reason "requires triton")
env -u PYTHONPATH <cpu-python> -m pytest $W -q
# cpu wheel, true CPU-only (TORCH_DEVICE_BACKEND_AUTOLOAD=0): 1 test collected, 1 passed
# npu wheel, Ascend 910B4 (no CUDA/XPU present): 2 failed, 1 passed
#   (the two failures are the out-of-tree cases described above)
lintrunner $W <worktree>/tools/linter/adapters/test_linter_allowlist.json   # ok No lint issues.
```

Negative control, to show the linter claim is not vacuous. With the allowlist row deleted:

```bash
<cpu-python> tools/linter/adapters/test_linter.py test/inductor/test_smoke.py   # no findings
# re-insert `only_for=("cuda", "xpu")` in the same file, same command:
# {"name":"[only_for]","severity":"error","line":73,"description":"Test class
#  'SmokeTestDevice' (ACCELERATOR): must not use only_for in
#  instantiate_device_type_tests; use except_for instead."}
```

## Verification Report

| State | Host | Collected | Passed | Failed | Skipped |
|-------|------|-----------|--------|--------|---------|
| this PR | CPU wheel, torch_npu autoloaded | 3 | 1 | 0 | 2 (`requires triton`) |
| this PR | CPU wheel, `TORCH_DEVICE_BACKEND_AUTOLOAD=0` | 1 | 1 | 0 | 0 (no device class generated) |
| this PR | NPU (Ascend 910B4, triton-ascend present) | 3 | 1 | 2 | 0 (backend-side failures above) |

| Item | Version |
|------|---------|
| PyTorch (cpu and npu venvs) | 2.16.0.dev20261029+cpu |
| torch_npu | 2.16.0.dev20261029+git737bb43 |
| CANN | 9.2.0 |
| Python | 3.12 |
## XPU execution

The review asked for evidence that the converted device tests pass on Linux XPU. There is
no such evidence available from this PR: `gh pr checks 192434` currently lists no job whose
name contains `xpu` or `intel` (0 of 4 executed checks), even though the PR carries
`ciflow/trunk` and `ciflow/inductor`. The CUDA and XPU variants are therefore asserted here
to be *created and gated*, not executed; whether they pass belongs to a shard that has to be
run by someone able to schedule it, and no change to this file can produce that evidence.
| Hardware | Ascend 910B4 (no CUDA/XPU present) |
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch from 7339b74 to b1944bb Compare November 4, 2026 07:04
github-actions[bot]

This comment was marked as outdated.

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 4, 2026
## Summary

`test/inductor/test_smoke.py` gates its accelerator tests with
`@unittest.skipIf(not HAS_GPU, ...)` and builds their tensors on the `GPU_TYPE` constant
imported from `torch.testing/_internal/inductor_utils`. Both are resolved once, at import,
from whichever device the process happened to initialise, so the file cannot say which
device a test is about to exercise, and every host inherits the same answer.

This change moves that decision into the framework's own mechanism. It touches two files:
the test file, and its now-unneeded exemption in
`tools/linter/adapters/test_linter_allowlist.json`.

## Changes

- `SmokeTest` is split. The generic half keeps `test_compile_invalid_options`, which
  touches no device and stays a plain `TestCase`. The accelerator half becomes
  `SmokeTestDevice`, declared `HardwareClassification.ACCELERATOR` and instantiated with
  `instantiate_device_type_tests(..., globals(), except_for="cpu", allow_xpu=True)`, the
  form `test/inductor/test_selective_lowering.py:56` and
  `test/inductor/test_symm_mem_registry.py:440` already use. `only_for` is deliberately not
  used: `test/REVIEW.md` Rule 4 says "`only_for` must not be used" for ACCELERATOR classes,
  and it would also drop the PrivateUse1, HPU and `TORCH_TEST_DEVICES` bases that this PR's
  own motivation is about keeping.
- Test bodies take `device` and construct their tensors there, inside the test methods;
  the `GPU_TYPE` import is gone, and no `if device == ...` branch appears. `test_mlp`
  registers `self.addCleanup(torch._logging.set_logs)` before enabling DEBUG logging, so a
  failure no longer leaks the log level into later tests in the same process.
- The two accelerator tests are gated with `@requires_triton()`, as can-gaa-hou asked in
  pytorch#192434 (comment). Stated plainly:
  `requires_triton` is `functools.partial(unittest.skipIf, not HAS_TRITON, ...)`
  (`inductor_utils.py:202`), so like the `HAS_GPU` it replaces it is a process-wide boolean.
  This PR makes the instantiation per-device, not the gate.
- The `test/inductor/test_smoke.py` row is deleted from
  `tools/linter/adapters/test_linter_allowlist.json` (Rule 7). That row was why `TEST_LINTER`
  stayed silent: with the row removed, the file is checked, and the check is demonstrably
  live -- see the negative control in the Test Plan.
- The `__main__` block is left byte-identical to the base commit, including the
  `IS_LINUX and HAS_GPU` and `major <= 5` conditions. `run_test.py` invokes this file as a
  script, so that block decides which tests CI executes, and changing it is not this PR's to
  make.

## What CI executes

Because `run_test.py` runs the file as `python test_smoke.py` (`test/run_test.py:687`), the
unchanged `__main__` guard decides what each shard runs; the pytest invocations below are
local measurements, not a CI path. Reading the guard against the sources, before and after
this PR alike:

- CUDA and ROCm shards: `HAS_CUDA_AND_TRITON` is true and the `major <= 5` disjunct is false
  on any Triton-capable GPU (`is_triton_capable` requires HIP or compute capability 7 or
  later, `torch/_dynamo/device_interface.py:433-441`), so `run_tests()` is never called:
  the instantiated CUDA classes are generated but not executed by CI.
- CPU-only shards: `HAS_GPU` is false (`inductor_utils.py:82`), the script path runs
  nothing from this file.
- Out-of-tree backends: upstream CI installs none, so no PrivateUse1 class is generated
  there at all; the NPU numbers below come from a local wheel on an Ascend 910B4 host.
- XPU is the one accelerator whose shards would execute these bodies (`allow_xpu=True`
  plus `PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu`, and the default shard suite keeps this file),
  but the xpu workflow only reacts to the `ciflow/xpu` label, `viable/strict`, its
  schedule, or manual dispatch (`.github/workflows/xpu.yml:4-14`). This PR does not carry
  that label, so no XPU test job has run on any of its heads (two older heads show an XPU
  build job only). A green `test_mlp_xpu` / `test_compile_decorator_xpu` result can
  therefore only come from a run triggered after adding `ciflow/xpu` (and approving the
  workflows, as for the other ciflow families of this fork PR).
- fbcode/sandcastle hosts (an internal-build code read, not verifiable from OSS):
  `get_device_type_test_bases()` yields only the CPU base unless `IS_REMOTE_GPU` is set,
  and then the CUDA base only when ASAN, TSAN, UBSAN and MTIA are all off
  (`common_device_type.py:1028-1038`); with `except_for="cpu"` those hosts generate no
  device class at all.

## Known coverage change: MTIA

`get_device_type_test_bases()` (`common_device_type.py:1023-1052`) has no MTIA base, so on
an MTIA host `SmokeTestDevice` is not generated and `test_mlp` / `test_compile_decorator`
stop running there, whereas base did run them (`HAS_GPU` includes `HAS_MTIA_AND_TRITON`,
and `GPU_TYPE` resolved to `mtia`). That is a reading of the base sources, not a
measurement: no MTIA hardware is available here. Keeping the coverage inside this file
would break the rules it is being migrated under: `hw_classification` has exactly six
members (`GENERIC`, `ACCELERATOR`, `CPU`, `CUDA`, `MPS`, `XPU`;
`tools/linter/adapters/test_linter.py:105-111`), so Rule 2 cannot describe an MTIA class,
and Rule 4 requires ACCELERATOR classes to be instantiated, which offers no MTIA base. The
structural fix, an MTIA device test base, is a separate change. **This documented drop
still needs the MTIA owners' explicit acceptance**: the question is open in the thread at
pytorch#192434 (comment) (comment
pytorch#192434 (comment)), unanswered since
2026-11-02, and nothing here assumes an answer.

## Out-of-tree results

With `except_for="cpu"` the framework generates a PrivateUse1 class on a host that has an
out-of-tree backend registered, and on this host two of its tests fail for reasons inside
that backend:

```
test_compile_decorator_npu: TypeError: WrappedFunction.__init__() missing 2 required
  positional arguments: 'cudagraph_managed_input_rerecord_limit' and
  'cudagraph_managed_input_rerecord_action'
  (raised at torch_npu/npu/_graph_tree.py:2527, from parameters the wheel's own
  torch/_inductor/cudagraph_trees.py:576-577 defines)
test_mlp_npu: torch._inductor.exc.InductorError: TypeError:
  NPUPythonWrapperCodeGen._generate_extern_kernel_out_helper() got an unexpected keyword
  argument 'tunable_dyn_dims_mask'
```

Both are raised inside the out-of-tree backend's own wrapper codegen: its hooks predate the
inductor APIs it now runs against. Upstream CI has no out-of-tree backend, so these do not
gate this PR; they belong to the backend's own test configuration, whose documented
mechanism is `PrivateUse1TestBase.set_test_configs(test_exclusions=...)`
(`docs/source/accelerator/testing.md:74`). Adding an upstream per-device skip was rejected:
the allowed device-specific skip decorators (`test/REVIEW.md:154-160`) are `@skipCPUIf`,
`@skipCUDAIf`, `@skipXPUIf`, `@skipMPSIf` and the accelerator-aware `@skipIf` -- there is
no out-of-tree entry -- and a bare `expectedFailure` would swallow any exception, not just
these.

## Test Plan

Two prebuilt wheel venvs, no source file overlaid onto site-packages, every run started
from `/tmp` (from the repository root `python -m pytest` puts the source tree on `sys.path`
and imports a `torch` with no built `version.py`, which fails for unrelated reasons).

```bash
W=<worktree>/test/inductor/test_smoke.py

# cpu wheel, out-of-tree backend autoloaded:  3 tests collected, 1 passed, 2 skipped
#   (the skips are SmokeTestDevicePRIVATEUSE1, reason "requires triton")
env -u PYTHONPATH <cpu-python> -m pytest $W -q
# cpu wheel, true CPU-only (TORCH_DEVICE_BACKEND_AUTOLOAD=0): 1 test collected, 1 passed
# npu wheel, Ascend 910B4 (no CUDA/XPU present): 2 failed, 1 passed
#   (the two failures are the out-of-tree cases described above)
lintrunner $W <worktree>/tools/linter/adapters/test_linter_allowlist.json   # ok No lint issues.
```

Negative control, to show the linter claim is not vacuous. With the allowlist row deleted:

```bash
<cpu-python> tools/linter/adapters/test_linter.py test/inductor/test_smoke.py   # no findings
# re-insert `only_for=("cuda", "xpu")` in the same file, same command:
# {"name":"[only_for]","severity":"error","line":73,"description":"Test class
#  'SmokeTestDevice' (ACCELERATOR): must not use only_for in
#  instantiate_device_type_tests; use except_for instead."}
```

## Verification Report

| State | Host | Collected | Passed | Failed | Skipped |
|-------|------|-----------|--------|--------|---------|
| this PR | CPU wheel, torch_npu autoloaded | 3 | 1 | 0 | 2 (`requires triton`) |
| this PR | CPU wheel, `TORCH_DEVICE_BACKEND_AUTOLOAD=0` | 1 | 1 | 0 | 0 (no device class generated) |
| this PR | NPU (Ascend 910B4, triton-ascend present) | 3 | 1 | 2 | 0 (backend-side failures above) |

| Item | Version |
|------|---------|
| PyTorch (cpu and npu venvs) | 2.16.0.dev20261029+cpu |
| torch_npu | 2.16.0.dev20261029+git737bb43 |
| CANN | 9.2.0 |
| Python | 3.12 |
## XPU execution

The review asked for evidence that the converted device tests pass on Linux XPU. There is
no such evidence available from this PR: `gh pr checks 192434` currently lists no job whose
name contains `xpu` or `intel` (0 of 4 executed checks), even though the PR carries
`ciflow/trunk` and `ciflow/inductor`. The CUDA and XPU variants are therefore asserted here
to be *created and gated*, not executed; whether they pass belongs to a shard that has to be
run by someone able to schedule it, and no change to this file can produce that evidence.
| Hardware | Ascend 910B4 (no CUDA/XPU present) |
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch from b1944bb to 70cd75a Compare November 4, 2026 07:36
github-actions[bot]

This comment was marked as outdated.

gavinwang269 added a commit to gavinwang269/pytorch that referenced this pull request Nov 4, 2026
## Summary

`test/inductor/test_smoke.py` gates its accelerator tests with
`@unittest.skipIf(not HAS_GPU, ...)` and builds their tensors on the `GPU_TYPE` constant
imported from `torch.testing/_internal/inductor_utils`. Both are resolved once, at import,
from whichever device the process happened to initialise, so the file cannot say which
device a test is about to exercise, and every host inherits the same answer.

This change moves that decision into the framework's own mechanism. It touches two files:
the test file, and its now-unneeded exemption in
`tools/linter/adapters/test_linter_allowlist.json`.

## Changes

- `SmokeTest` is split. The generic half keeps `test_compile_invalid_options`, which
  touches no device and stays a plain `TestCase`. The accelerator half becomes
  `SmokeTestDevice`, declared `HardwareClassification.ACCELERATOR` and instantiated with
  `instantiate_device_type_tests(..., globals(), except_for="cpu", allow_xpu=True)`, the
  form `test/inductor/test_selective_lowering.py:56` and
  `test/inductor/test_symm_mem_registry.py:440` already use. `only_for` is deliberately not
  used: `test/REVIEW.md` Rule 4 says "`only_for` must not be used" for ACCELERATOR classes,
  and it would also drop the PrivateUse1, HPU and `TORCH_TEST_DEVICES` bases that this PR's
  own motivation is about keeping.
- Test bodies take `device` and construct their tensors there, inside the test methods;
  the `GPU_TYPE` import is gone, and no `if device == ...` branch appears. `test_mlp`
  registers `self.addCleanup(torch._logging.set_logs)` before enabling DEBUG logging, so a
  failure no longer leaks the log level into later tests in the same process.
- The two accelerator tests are gated with `@requires_triton()`, as can-gaa-hou asked in
  pytorch#192434 (comment). Stated plainly:
  `requires_triton` is `functools.partial(unittest.skipIf, not HAS_TRITON, ...)`
  (`inductor_utils.py:202`), so like the `HAS_GPU` it replaces it is a process-wide boolean.
  This PR makes the instantiation per-device, not the gate.
- The `test/inductor/test_smoke.py` row is deleted from
  `tools/linter/adapters/test_linter_allowlist.json` (Rule 7). That row was why `TEST_LINTER`
  stayed silent: with the row removed, the file is checked, and the check is demonstrably
  live -- see the negative control in the Test Plan.
- The `__main__` block is left byte-identical to the base commit, including the
  `IS_LINUX and HAS_GPU` and `major <= 5` conditions. `run_test.py` invokes this file as a
  script, so that block decides which tests CI executes, and changing it is not this PR's to
  make.

## What CI executes

Because `run_test.py` runs the file as `python test_smoke.py` (`test/run_test.py:687`), the
unchanged `__main__` guard decides what each shard runs; the pytest invocations below are
local measurements, not a CI path. Reading the guard against the sources, before and after
this PR alike:

- CUDA and ROCm shards: `HAS_CUDA_AND_TRITON` is true and the `major <= 5` disjunct is false
  on any Triton-capable GPU (`is_triton_capable` requires HIP or compute capability 7 or
  later, `torch/_dynamo/device_interface.py:433-441`), so `run_tests()` is never called:
  the instantiated CUDA classes are generated but not executed by CI.
- CPU-only shards: `HAS_GPU` is false (`inductor_utils.py:82`), the script path runs
  nothing from this file.
- Out-of-tree backends: upstream CI installs none, so no PrivateUse1 class is generated
  there at all; the NPU numbers below come from a local wheel on an Ascend 910B4 host.
- XPU is the one accelerator whose shards would execute these bodies (`allow_xpu=True`
  plus `PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu`, and the default shard suite keeps this file),
  but the xpu workflow only reacts to the `ciflow/xpu` label, `viable/strict`, its
  schedule, or manual dispatch (`.github/workflows/xpu.yml:4-14`). This PR does not carry
  that label, so no XPU test job has run on any of its heads (two older heads show an XPU
  build job only). A green `test_mlp_xpu` / `test_compile_decorator_xpu` result can
  therefore only come from a run triggered after adding `ciflow/xpu` (and approving the
  workflows, as for the other ciflow families of this fork PR).
- fbcode/sandcastle hosts (an internal-build code read, not verifiable from OSS):
  `get_device_type_test_bases()` yields only the CPU base unless `IS_REMOTE_GPU` is set,
  and then the CUDA base only when ASAN, TSAN, UBSAN and MTIA are all off
  (`common_device_type.py:1028-1038`); with `except_for="cpu"` those hosts generate no
  device class at all.

## Known coverage change: MTIA

`get_device_type_test_bases()` (`common_device_type.py:1023-1052`) has no MTIA base, so on
an MTIA host `SmokeTestDevice` is not generated and `test_mlp` / `test_compile_decorator`
stop running there, whereas base did run them (`HAS_GPU` includes `HAS_MTIA_AND_TRITON`,
and `GPU_TYPE` resolved to `mtia`). That is a reading of the base sources, not a
measurement: no MTIA hardware is available here. Keeping the coverage inside this file
would break the rules it is being migrated under: `hw_classification` has exactly six
members (`GENERIC`, `ACCELERATOR`, `CPU`, `CUDA`, `MPS`, `XPU`;
`tools/linter/adapters/test_linter.py:105-111`), so Rule 2 cannot describe an MTIA class,
and Rule 4 requires ACCELERATOR classes to be instantiated, which offers no MTIA base. The
structural fix, an MTIA device test base, is a separate change. **This documented drop
still needs the MTIA owners' explicit acceptance**: the question is open in the thread at
pytorch#192434 (comment) (comment
pytorch#192434 (comment)), unanswered since
2026-11-02, and nothing here assumes an answer.

## Out-of-tree results

With `except_for="cpu"` the framework generates a PrivateUse1 class on a host that has an
out-of-tree backend registered, and on this host two of its tests fail for reasons inside
that backend:

```
test_compile_decorator_npu: TypeError: WrappedFunction.__init__() missing 2 required
  positional arguments: 'cudagraph_managed_input_rerecord_limit' and
  'cudagraph_managed_input_rerecord_action'
  (raised at torch_npu/npu/_graph_tree.py:2527, from parameters the wheel's own
  torch/_inductor/cudagraph_trees.py:576-577 defines)
test_mlp_npu: torch._inductor.exc.InductorError: TypeError:
  NPUPythonWrapperCodeGen._generate_extern_kernel_out_helper() got an unexpected keyword
  argument 'tunable_dyn_dims_mask'
```

Both are raised inside the out-of-tree backend's own wrapper codegen: its hooks predate the
inductor APIs it now runs against. Upstream CI has no out-of-tree backend, so these do not
gate this PR; they belong to the backend's own test configuration, whose documented
mechanism is `PrivateUse1TestBase.set_test_configs(test_exclusions=...)`
(`docs/source/accelerator/testing.md:74`). Adding an upstream per-device skip was rejected:
the allowed device-specific skip decorators (`test/REVIEW.md:154-160`) are `@skipCPUIf`,
`@skipCUDAIf`, `@skipXPUIf`, `@skipMPSIf` and the accelerator-aware `@skipIf` -- there is
no out-of-tree entry -- and a bare `expectedFailure` would swallow any exception, not just
these.

## Test Plan

Two prebuilt wheel venvs, no source file overlaid onto site-packages, every run started
from `/tmp` (from the repository root `python -m pytest` puts the source tree on `sys.path`
and imports a `torch` with no built `version.py`, which fails for unrelated reasons).

```bash
W=<worktree>/test/inductor/test_smoke.py

# cpu wheel, out-of-tree backend autoloaded:  3 tests collected, 1 passed, 2 skipped
#   (the skips are SmokeTestDevicePRIVATEUSE1, reason "requires triton")
env -u PYTHONPATH <cpu-python> -m pytest $W -q
# cpu wheel, true CPU-only (TORCH_DEVICE_BACKEND_AUTOLOAD=0): 1 test collected, 1 passed
# npu wheel, Ascend 910B4 (no CUDA/XPU present): 2 failed, 1 passed
#   (the two failures are the out-of-tree cases described above)
lintrunner $W <worktree>/tools/linter/adapters/test_linter_allowlist.json   # ok No lint issues.
```

Negative control, to show the linter claim is not vacuous. With the allowlist row deleted:

```bash
<cpu-python> tools/linter/adapters/test_linter.py test/inductor/test_smoke.py   # no findings
# re-insert `only_for=("cuda", "xpu")` in the same file, same command:
# {"name":"[only_for]","severity":"error","line":73,"description":"Test class
#  'SmokeTestDevice' (ACCELERATOR): must not use only_for in
#  instantiate_device_type_tests; use except_for instead."}
```

## Verification Report

| State | Host | Collected | Passed | Failed | Skipped |
|-------|------|-----------|--------|--------|---------|
| this PR | CPU wheel, torch_npu autoloaded | 3 | 1 | 0 | 2 (`requires triton`) |
| this PR | CPU wheel, `TORCH_DEVICE_BACKEND_AUTOLOAD=0` | 1 | 1 | 0 | 0 (no device class generated) |
| this PR | NPU (Ascend 910B4, triton-ascend present) | 3 | 1 | 2 | 0 (backend-side failures above) |

| Item | Version |
|------|---------|
| PyTorch (cpu and npu venvs) | 2.16.0.dev20261029+cpu |
| torch_npu | 2.16.0.dev20261029+git737bb43 |
| CANN | 9.2.0 |
| Python | 3.12 |
## XPU execution

The review asked for evidence that the converted device tests pass on Linux XPU. There is
no such evidence available from this PR: `gh pr checks 192434` currently lists no job whose
name contains `xpu` or `intel` (0 of 4 executed checks), even though the PR carries
`ciflow/trunk` and `ciflow/inductor`. The CUDA and XPU variants are therefore asserted here
to be *created and gated*, not executed; whether they pass belongs to a shard that has to be
run by someone able to schedule it, and no change to this file can produce that evidence.
| Hardware | Ascend 910B4 (no CUDA/XPU present) |
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch from 70cd75a to 87652f9 Compare November 4, 2026 08:36
github-actions[bot]

This comment was marked as outdated.

## Summary

`test/inductor/test_smoke.py` gates its accelerator tests with
`@unittest.skipIf(not HAS_GPU, ...)` and builds their tensors on the `GPU_TYPE` constant
imported from `torch.testing/_internal/inductor_utils`. Both are resolved once, at import,
from whichever device the process happened to initialise, so the file cannot say which
device a test is about to exercise, and every host inherits the same answer.

This change moves that decision into the framework's own mechanism. It touches two files:
the test file, and its now-unneeded exemption in
`tools/linter/adapters/test_linter_allowlist.json`.

## Changes

- `SmokeTest` is split. The generic half keeps `test_compile_invalid_options`, which
  touches no device and stays a plain `TestCase`. The accelerator half becomes
  `SmokeTestDevice`, declared `HardwareClassification.ACCELERATOR` and instantiated with
  `instantiate_device_type_tests(..., globals(), except_for="cpu", allow_xpu=True)`, the
  form `test/inductor/test_selective_lowering.py:56` and
  `test/inductor/test_symm_mem_registry.py:440` already use. `only_for` is deliberately not
  used: `test/REVIEW.md` Rule 4 says "`only_for` must not be used" for ACCELERATOR classes,
  and it would also drop the PrivateUse1, HPU and `TORCH_TEST_DEVICES` bases that this PR's
  own motivation is about keeping.
- Test bodies take `device` and construct their tensors there, inside the test methods;
  the `GPU_TYPE` import is gone, and no `if device == ...` branch appears. `test_mlp`
  registers `self.addCleanup(torch._logging.set_logs)` before enabling DEBUG logging, so a
  failure no longer leaks the log level into later tests in the same process.
- The two accelerator tests are gated with `@requires_triton()`, as can-gaa-hou asked in
  pytorch#192434 (comment). Stated plainly:
  `requires_triton` is `functools.partial(unittest.skipIf, not HAS_TRITON, ...)`
  (`inductor_utils.py:202`), so like the `HAS_GPU` it replaces it is a process-wide boolean.
  This PR makes the instantiation per-device, not the gate.
- The `test/inductor/test_smoke.py` row is deleted from
  `tools/linter/adapters/test_linter_allowlist.json` (Rule 7). That row was why `TEST_LINTER`
  stayed silent: with the row removed, the file is checked, and the check is demonstrably
  live -- see the negative control in the Test Plan.
- The `__main__` block is left byte-identical to the base commit, including the
  `IS_LINUX and HAS_GPU` and `major <= 5` conditions. `run_test.py` invokes this file as a
  script, so that block decides which tests CI executes, and changing it is not this PR's to
  make.

## What CI executes

Because `run_test.py` runs the file as `python test_smoke.py` (`test/run_test.py:687`), the
unchanged `__main__` guard decides what each shard runs; the pytest invocations below are
local measurements, not a CI path. Reading the guard against the sources, before and after
this PR alike:

- CUDA and ROCm shards: `HAS_CUDA_AND_TRITON` is true and the `major <= 5` disjunct is false
  on any Triton-capable GPU (`is_triton_capable` requires HIP or compute capability 7 or
  later, `torch/_dynamo/device_interface.py:433-441`), so `run_tests()` is never called:
  the instantiated CUDA classes are generated but not executed by CI.
- CPU-only shards: `HAS_GPU` is false (`inductor_utils.py:82`), the script path runs
  nothing from this file.
- Out-of-tree backends: upstream CI installs none, so no PrivateUse1 class is generated
  there at all; the NPU numbers below come from a local wheel on an Ascend 910B4 host.
- XPU is the one accelerator whose shards would execute these bodies (`allow_xpu=True`
  plus `PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu`, and the default shard suite keeps this file),
  but the xpu workflow only reacts to the `ciflow/xpu` label, `viable/strict`, its
  schedule, or manual dispatch (`.github/workflows/xpu.yml:4-14`). This PR does not carry
  that label, so no XPU test job has run on any of its heads (two older heads show an XPU
  build job only). A green `test_mlp_xpu` / `test_compile_decorator_xpu` result can
  therefore only come from a run triggered after adding `ciflow/xpu` (and approving the
  workflows, as for the other ciflow families of this fork PR).
- fbcode/sandcastle hosts (an internal-build code read, not verifiable from OSS):
  `get_device_type_test_bases()` yields only the CPU base unless `IS_REMOTE_GPU` is set,
  and then the CUDA base only when ASAN, TSAN, UBSAN and MTIA are all off
  (`common_device_type.py:1028-1038`); with `except_for="cpu"` those hosts generate no
  device class at all.

## Known coverage change: MTIA

`get_device_type_test_bases()` (`common_device_type.py:1023-1052`) has no MTIA base, so on
an MTIA host `SmokeTestDevice` is not generated and `test_mlp` / `test_compile_decorator`
stop running there, whereas base did run them (`HAS_GPU` includes `HAS_MTIA_AND_TRITON`,
and `GPU_TYPE` resolved to `mtia`). That is a reading of the base sources, not a
measurement: no MTIA hardware is available here. Keeping the coverage inside this file
would break the rules it is being migrated under: `hw_classification` has exactly six
members (`GENERIC`, `ACCELERATOR`, `CPU`, `CUDA`, `MPS`, `XPU`;
`tools/linter/adapters/test_linter.py:105-111`), so Rule 2 cannot describe an MTIA class,
and Rule 4 requires ACCELERATOR classes to be instantiated, which offers no MTIA base. The
structural fix, an MTIA device test base, is a separate change. **This documented drop
still needs the MTIA owners' explicit acceptance**: the question is open in the thread at
pytorch#192434 (comment) (comment
pytorch#192434 (comment)), unanswered since
2026-11-02, and nothing here assumes an answer.

## Out-of-tree results

With `except_for="cpu"` the framework generates a PrivateUse1 class on a host that has an
out-of-tree backend registered, and on this host two of its tests fail for reasons inside
that backend:

```
test_compile_decorator_npu: TypeError: WrappedFunction.__init__() missing 2 required
  positional arguments: 'cudagraph_managed_input_rerecord_limit' and
  'cudagraph_managed_input_rerecord_action'
  (raised at torch_npu/npu/_graph_tree.py:2527, from parameters the wheel's own
  torch/_inductor/cudagraph_trees.py:576-577 defines)
test_mlp_npu: torch._inductor.exc.InductorError: TypeError:
  NPUPythonWrapperCodeGen._generate_extern_kernel_out_helper() got an unexpected keyword
  argument 'tunable_dyn_dims_mask'
```

Both are raised inside the out-of-tree backend's own wrapper codegen: its hooks predate the
inductor APIs it now runs against. Upstream CI has no out-of-tree backend, so these do not
gate this PR; they belong to the backend's own test configuration, whose documented
mechanism is `PrivateUse1TestBase.set_test_configs(test_exclusions=...)`
(`docs/source/accelerator/testing.md:74`). Adding an upstream per-device skip was rejected:
the allowed device-specific skip decorators (`test/REVIEW.md:154-160`) are `@skipCPUIf`,
`@skipCUDAIf`, `@skipXPUIf`, `@skipMPSIf` and the accelerator-aware `@skipIf` -- there is
no out-of-tree entry -- and a bare `expectedFailure` would swallow any exception, not just
these.

## Test Plan

Two prebuilt wheel venvs, no source file overlaid onto site-packages, every run started
from `/tmp` (from the repository root `python -m pytest` puts the source tree on `sys.path`
and imports a `torch` with no built `version.py`, which fails for unrelated reasons).

```bash
W=<worktree>/test/inductor/test_smoke.py

# cpu wheel, out-of-tree backend autoloaded:  3 tests collected, 1 passed, 2 skipped
#   (the skips are SmokeTestDevicePRIVATEUSE1, reason "requires triton")
env -u PYTHONPATH <cpu-python> -m pytest $W -q
# cpu wheel, true CPU-only (TORCH_DEVICE_BACKEND_AUTOLOAD=0): 1 test collected, 1 passed
# npu wheel, Ascend 910B4 (no CUDA/XPU present): 2 failed, 1 passed
#   (the two failures are the out-of-tree cases described above)
lintrunner $W <worktree>/tools/linter/adapters/test_linter_allowlist.json   # ok No lint issues.
```

Negative control, to show the linter claim is not vacuous. With the allowlist row deleted:

```bash
<cpu-python> tools/linter/adapters/test_linter.py test/inductor/test_smoke.py   # no findings
# re-insert `only_for=("cuda", "xpu")` in the same file, same command:
# {"name":"[only_for]","severity":"error","line":73,"description":"Test class
#  'SmokeTestDevice' (ACCELERATOR): must not use only_for in
#  instantiate_device_type_tests; use except_for instead."}
```

## Verification Report

| State | Host | Collected | Passed | Failed | Skipped |
|-------|------|-----------|--------|--------|---------|
| this PR | CPU wheel, torch_npu autoloaded | 3 | 1 | 0 | 2 (`requires triton`) |
| this PR | CPU wheel, `TORCH_DEVICE_BACKEND_AUTOLOAD=0` | 1 | 1 | 0 | 0 (no device class generated) |
| this PR | NPU (Ascend 910B4, triton-ascend present) | 3 | 1 | 2 | 0 (backend-side failures above) |

| Item | Version |
|------|---------|
| PyTorch (cpu and npu venvs) | 2.16.0.dev20261029+cpu |
| torch_npu | 2.16.0.dev20261029+git737bb43 |
| CANN | 9.2.0 |
| Python | 3.12 |
## XPU execution

The review asked for evidence that the converted device tests pass on Linux XPU. There is
no such evidence available from this PR: `gh pr checks 192434` currently lists no job whose
name contains `xpu` or `intel` (0 of 4 executed checks), even though the PR carries
`ciflow/trunk` and `ciflow/inductor`. The CUDA and XPU variants are therefore asserted here
to be *created and gated*, not executed; whether they pass belongs to a shard that has to be
run by someone able to schedule it, and no change to this file can produce that evidence.
| Hardware | Ascend 910B4 (no CUDA/XPU present) |
@gavinwang269
gavinwang269 force-pushed the test/inductor-smoke-decouple branch from 87652f9 to fa5b276 Compare November 4, 2026 08:56

@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 fa5b276: nothing blocking; ready for human review.

The PR splits test/inductor/test_smoke.py into a GENERIC SmokeTest and an ACCELERATOR SmokeTestDevice instantiated with instantiate_device_type_tests(except_for="cpu", allow_xpu=True) and gated by @ requires_triton(), and removes its linter allowlist row. Recommendation: Needs Discussion. The review finds no code defect, but asks for a green ciflow/xpu run and explicit maintainer acceptance (or a fallback) for the lost MTIA/fbcode coverage before merge.

⚪ 2 non-blocking findings

instantiate_device_type_tests(

No CI job has run the new device tests. run_test.py runs this file as a script, so the unchanged main guard decides what CI executes. On CUDA/ROCm, HAS_CUDA_AND_TRITON implies HIP or major >= 7, so major &lt;= 5 is false and run_tests() is never reached: SmokeTestDeviceCUDA is generated but never executed. On CPU-only and PrivateUse1-only shards HAS_GPU is false. That leaves Linux XPU as the only upstream path that runs test_mlp_xpu / test_compile_decorator_xpu, the bodies this PR rewrote (device instead of GPU_TYPE, plus the new addCleanup). xpu.yml fires only on ciflow/xpu, viable/strict, a schedule or manual dispatch, and the XPU job in pull.yml only builds, so the green checks say nothing about these tests. Fix: add ciflow/xpu and get a green XPU test run before merging. (The inverted &lt;= 5 check predates this PR and is left alone, as can-gaa-hou asked.)

An earlier comment near this line has replies: #192434 (comment)


SmokeTestDevice, globals(), except_for="cpu", allow_xpu=True

MTIA and some internal GPU hosts lose test_mlp and test_compile_decorator entirely. On MTIA, base ran both tests (HAS_GPU includes HAS_MTIA_AND_TRITON and GPU_TYPE can resolve to mtia), but get_device_type_test_bases() has no MTIA base and there is no MTIATestBase in the tree. Under IS_FBCODE/IS_SANDCASTLE without IS_REMOTE_GPU it adds only CPUTestBase, and even with IS_REMOTE_GPU the CUDA base is dropped under ASAN/TSAN/UBSAN or TEST_WITH_MTIA. With except_for="cpu" those hosts get no device class, so the tests vanish rather than skip. The description documents this but says it "still needs the MTIA owners' explicit acceptance"; can-gaa-hou raised it and has not replied since 2026-11-02, and the author's 2026-11-03 reply says the file "now carries SmokeTestMTIA", but that class is no longer at HEAD. Fix: before landing, get an explicit decision from can-gaa-hou or the MTIA owners: accept the drop, or keep a fallback until an MTIA device test base exists.

An earlier comment near this line has replies: #192434 (comment)

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

@github-actions
github-actions Bot dismissed stale reviews from themself November 4, 2026 09:13

Withdrawn: the automated review of fa5b276 found nothing blocking.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Ready for human review. On head fa5b2760e86f the automated review reports nothing blocking and no change request is open. Scope: test/inductor/test_smoke.py migrated to per-device instantiation (ACCELERATOR + instantiate_device_type_tests(except_for="cpu", allow_xpu=True)) plus removal of the file's allowlist row; the "What CI executes" section of the description walks which shards run these bodies.

Two steps remain that only maintainers can take:

  1. the documented MTIA + fbcode/sandcastle coverage drop needs explicit acceptance -- the question is open with @can-gaa-hou since 2026-11-02 (#discussion_r4440479650);
  2. @EikanWang could the ciflow/xpu label be added and the scheduled runs approved? The PR carries ciflow/trunk/ciflow/inductor, which do not reach xpu.yml, and Linux XPU is the only upstream path that executes test_mlp_xpu / test_compile_decorator_xpu.

@eellison @jansel if either of you has bandwidth: this is one of a series migrating test/inductor files to the framework's per-device instantiation, and it is ready to land once the two items above settle.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot

pytorch-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

-i flag is only allowed for users with write permissions

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: 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.

9 participants