Skip to content

[Testcase Refactoring] Make test_static_triton_launcher device-agnostic via instantiate_device_type_tests - #192893

Closed
gavinwang269 wants to merge 5 commits into
pytorch:mainfrom
gavinwang269:test/inductor-triton-launcher-decouple
Closed

gavinwang269 wants to merge 5 commits into
pytorch:mainfrom
gavinwang269:test/inductor-triton-launcher-decouple

Conversation

@gavinwang269

@gavinwang269 gavinwang269 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactor test/inductor/test_static_triton_launcher.py to use the device-agnostic test framework (instantiate_device_type_tests + HardwareClassification) instead of hardcoded GPU_TYPE / @requires_gpu_and_triton.

Changes

  • Replace all GPU_TYPE references with torch.device(device).type (upstream standard pattern, see test_fp8.py, test_flex_attention.py)
  • Replace @requires_gpu_and_triton decorators with @unittest.skipIf(not has_triton(), "requires triton") for Triton gating and hw_classification class declarations for hardware-based test dispatch
  • Replace requires_gpu_and_triton import with has_triton and has_triton_tma_device from torch.utils._triton; add instantiate_device_type_tests from common_device_type and HardwareClassification from common_utils; remove GPU_TYPE from inductor_utils import
  • Add device parameter to all test methods in 4 accelerator/device-specific test classes
  • Replace @config.patch class decorators with setUp/tearDown context managers (class decorator form wraps class as function, breaking instantiate_device_type_tests)
  • write_cubin_to_tmp: add npubin binary key for NPU device type

Hardware Classification

Test Class hw_classification instantiate_device_type_tests
TestStaticTritonLauncherUnit GENERIC None (pure unit tests, no device dependency)
TestStaticTritonLauncher ACCELERATOR except_for="cpu", allow_xpu=True
TestStaticTritonCompileResult ACCELERATOR except_for="cpu", allow_xpu=True
TestFastCudaLauncher CUDA only_for=("cuda",) — _FastCudaLauncher is a CUDA-only C extension
TestFastCudaLauncherCompileResult CUDA only_for=("cuda", "xpu"), allow_xpu=True — fast launcher tests are CUDA/XPU only

Motivation

The @requires_gpu_and_triton decorator uses GPU_TYPE from inductor_utils, which checks GPU_TYPES (currently ["cuda", "mps", "xpu", "mtia"]). Out-of-tree accelerators registered via PrivateUse1 (e.g., Ascend NPU) are not included in this list, causing the entire test module to be skipped.

Test Plan

Verified on CPU (no GPU) and NPU (Ascend 910B4):

# CPU
python -m pytest test/inductor/test_static_triton_launcher.py --collect-only -v
# 5 tests collected (GENERIC only), 0 errors
python -m pytest test/inductor/test_static_triton_launcher.py::TestStaticTritonLauncherUnit -v
# 5 passed

# NPU
python -m pytest test/inductor/test_static_triton_launcher.py -v --tb=no
# 21 passed, 3 failed (NPU hardware/software limitations)

Verification Report

Hardware Cases Passed Failed Result
CPU (no GPU) 5 5 0 All GENERIC passed
NPU (Ascend 910B4) 24 21 3 3 failures are NPU limits (see below)

NPU Failures (hardware/software limitations)

Test Root Cause GitCode Issue
test_unsigned_integers CANN aclnnInplaceZero does not support DT_UINT64 #3973
test_any triton-ascend libdevice.isinf does not support float64 (BiSheng compiler only supports fp16/bf16/fp32) #3974
test_incompatible_code torch_npu CompileThreadPool does not propagate thread-local config to worker threads #3975

Environment

Item Version
PyTorch 2.14.0.dev20260811+cpu
torch_npu 2.14.0+gitc775ad3
triton-ascend 3.6.0+git0cfb1708
CANN 9.1.0 GA
NPU Ascend 910B4
Python 3.12.13

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01 @gujinghui @PenghuiCheng @jianyuh @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal @voznesenskym @penguinwu @EikanWang @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98

@pytorch-bot

pytorch-bot Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 62adaa0 with merge base 11cc3f2 (image):

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

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

@pytorch-bot

pytorch-bot Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@gavinwang269 gavinwang269 changed the title test host [Testcase Refactoring] Make test_static_triton_launcher device-agnostic via instantiate_device_type_tests Aug 11, 2026
@gavinwang269 gavinwang269 reopened this Aug 11, 2026
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: inductor" "topic: not user facing"

@gavinwang269
gavinwang269 force-pushed the test/inductor-triton-launcher-decouple branch from 6bc5c84 to f12c948 Compare August 11, 2026 09:56
@gavinwang269

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: tests/graph"

@pytorch-bot pytorch-bot Bot added the module: tests/graph This label covers all test cases within the Graph sheet. label Aug 11, 2026
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Aug 12, 2026
@gavinwang269
gavinwang269 marked this pull request as ready for review August 12, 2026 06:02
@jansel
jansel requested a review from zou3519 August 12, 2026 23:36
@gavinwang269
gavinwang269 force-pushed the test/inductor-triton-launcher-decouple branch 2 times, most recently from 5292a59 to bbe0446 Compare August 13, 2026 05:57

@rogerchen838 rogerchen838 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the current head against RFC #191471. The static Triton launcher tests are device-type instantiated and safely exclude unsupported devices; no blocking issue was found. The latest lint/build checks are passing, while the broader test matrix is still in progress.

@rogerchen838 rogerchen838 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the current head against RFC #191471. The static Triton launcher tests are device-type instantiated and safely exclude unsupported devices; no blocking issue was found. The latest lint/build checks are passing, while the broader test matrix is still in progress.

@liangel-02
liangel-02 requested a review from fffrog August 13, 2026 19:06
@liangel-02 liangel-02 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 13, 2026
@gavinwang269
gavinwang269 force-pushed the test/inductor-triton-launcher-decouple branch from bbe0446 to f560b6f Compare August 17, 2026 03:25

@rogerchen838 rogerchen838 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The current head has a CI-backed formatting failure, so I cannot keep the earlier approval until it is fixed.

fast(1, 1, 1, stream, new_arg0, 5)
self.assertEqual(
new_arg0, torch.tensor([5], dtype=torch.int32, device=GPU_TYPE)
new_arg0, torch.tensor([5], dtype=torch.int32, device=device)

This comment was marked as low quality.

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 catching this! Fixed. Ran lintrunner -a — the assertion has been collapsed to a single line and the trailing newline is now present. Also rebased onto latest main.

@gavinwang269
gavinwang269 force-pushed the test/inductor-triton-launcher-decouple branch from f560b6f to 04a3026 Compare August 19, 2026 01:38
@zou3519
zou3519 removed their request for review August 19, 2026 22:34
@gavinwang269
gavinwang269 force-pushed the test/inductor-triton-launcher-decouple branch 2 times, most recently from a64e594 to a13e705 Compare August 20, 2026 02:52

@rogerchen838 rogerchen838 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I verified this against each PR’s current head and confirmed that the imported capability API is not present in common_device_type.py; this blocks test collection.

from torch.testing._internal.inductor_utils import GPU_TYPE, HAS_XPU_AND_TRITON
from torch.testing._internal.triton_utils import requires_gpu_and_triton
from torch.testing._internal.common_device_type import (
Capability,

This comment was marked as low quality.

@gavinwang269 gavinwang269 Aug 24, 2026 •

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 detailed analysis! This has been fixed in commit 9709a7e (the latest head).

To clarify what changed:

Verified: grep -r "Capability" test/inductor/test_static_triton_launcher.py returns 0 matches. Could you please re-review the latest head (9709a7e)?

@gavinwang269 gavinwang269 Sep 29, 2026 •

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.

@rogerchen838 thanks for the careful review. On the collection-blocking concern at the current heads: the Capability / requires_capabilities imports are already gone. At 9709a7e7 (the head your last review referenced) and at the current head 62adaa0a, test/inductor/test_static_triton_launcher.py:33 imports only instantiate_device_type_tests from common_device_type, and the Triton gating uses the existing @unittest.skipIf(not has_triton(), "requires Triton") (e.g. lines 327/360 at 9709a7e7). Could you double-check and dismiss the request-changes if that matches what you see? Note: I'm also superseding this PR with a per-class split (#198436 ~ #198440), so the discussion may continue there.

@rogerchen838 rogerchen838 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I checked the current head and the target import. This is collection-blocking because the imported symbols must exist before any test can run.

AI-assisted analysis: this PR imports Capability and requires_capabilities from torch.testing._internal.common_device_type, but neither API exists at this PR head. Please remove this dependency or first rebase onto the change that introduces those APIs.

@gavinwang269

Copy link
Copy Markdown
Contributor Author

@rogerchen838 Following up on your latest review — the Capability and requires_capabilities imports were removed in the latest commit (9709a7e). The only import from common_device_type.py is now instantiate_device_type_tests, and Triton gating uses @unittest.skipIf(not has_triton(), "requires triton") with has_triton from torch.utils._triton. grep "Capability" test/inductor/test_static_triton_launcher.py returns 0 matches. Could you please re-review the latest head?

@gavinwang269

Copy link
Copy Markdown
Contributor Author

Hi @rogerchen838, sorry for the slow follow-up on this. The branch has been rebased onto the latest main (the merge previously showed as dirty). To summarize the current state of your review points:

  1. The Capability / requires_capabilities imports that blocked collection were removed in 9709a7e and are absent from the current head — the only import from common_device_type is instantiate_device_type_tests, which exists on main.
  2. The formatting failure from the first round was fixed in 04a3026.
  3. The rebase kept the two new scalar tests that landed upstream (test_float_scalars, test_bfloat16_scalar) untouched, and dropped the upstream import they no longer needed.

The unit-test portion passes locally (9/9 on CPU, one expected ROCm-only skip). CI is running on the new head. Could you take another look when convenient? Thanks!

gavinwang269 and others added 5 commits September 11, 2026 09:18
…ic via instantiate_device_type_tests

- Replace all GPU_TYPE references with torch.device(device).type in test methods
  (upstream standard pattern, see test_fp8.py, test_flex_attention.py)
- Keep self.device_type in setUp/tearDown only (no device param available,
  upstream precedent: test_flex_decoding.py)
- Replace @requires_gpu_and_triton with hw_classification declarations
- TestStaticTritonLauncherUnit: GENERIC (pure unit tests)
- TestFastCudaLauncher: only_for=("cuda",) — CUDA-only C extension
- TestFastCudaLauncherCompileResult: only_for=("cuda", "xpu")
- Add npubin binary key for NPU in write_cubin_to_tmp
- Replace @config.patch class decorators with setUp/tearDown context managers
- Rebased onto latest upstream/main to incorporate new _global_scratch_kernel
  and test_device_tma_gemm_falls_back_from_fast_launcher additions
…t methods

TestStaticTritonLauncher and TestStaticTritonCompileResult use
instantiate_device_type_tests with except_for="cpu", allow_xpu=True.
All 19 test methods with device parameter use triton.jit/torch.compile
and require Capability.lib.triton to be registered.

Restored @skipIfRocm on TestFastCudaLauncher and TestFastCudaLauncherCompileResult
(ROCm presents as CUDA, only_for does not exclude it).
Restored @skipIfXpu on test_too_high_shared_mem (TestStaticTritonLauncher
uses allow_xpu=True, XPU runs and would fail on CUDA OOM test).
TestFastCudaLauncherCompileResult was labeled HardwareClassification.CUDA but
was instantiated with only_for=("cuda", "xpu"), and mixed two CUDA-only tests
(test_basic_compile, test_device_tma_gemm_falls_back_from_fast_launcher) with a
device-generic fallback smoke test (test_disable_fast_launcher). The mismatch
forced redundant @skipIfXpu guards and an unreachable XPU assertion branch in
test_basic_compile.

Split the class so hw_classification matches the instantiation scope: shared
setUp/tearDown/tracker move into _FastLauncherCompileMixin (not a TestCase); the
device-generic test_disable_fast_launcher moves into a new
TestFastLauncherFallbackCompileResult (ACCELERATOR, cuda+xpu); the two CUDA-only
tests stay in TestFastCudaLauncherCompileResult (only_for=cuda). This lets both
@skipIfXpu decorators and the dead XPU branch in test_basic_compile be removed.

Test Plan:
- AST parse and instantiate_device_type_tests attribution verified via ast
  introspection (mixin has no TestCase base; ACCELERATOR class holds only
  test_disable_fast_launcher; CUDA class holds the two CUDA-only tests with no
  @skipIfXpu).
- pytest --collect-only: baseline and post-change both collect identically; the
  _FastCudaLauncher wheel symbol is absent on this CPU host so the device-generic
  classes generate no variants, unchanged from baseline.
- ruff check / ruff format --check and lintrunner -a: no issues.
@gavinwang269

Copy link
Copy Markdown
Contributor Author

Revisit of the classification mismatch: instead of dropping the XPU instantiation (which would remove test_disable_fast_launcher's device-generic fallback coverage), split the class by capability: CUDA-only tests stay in TestFastCudaLauncherCompileResult (only_for=("cuda",), now honestly tagged CUDA, dead @skipIfXpu guards and unreachable XPU branch removed), and the device-generic fallback test moved to TestFastLauncherFallbackCompileResult (ACCELERATOR, cuda+xpu). Effective executed set is unchanged (CUDA 3 + XPU 1).

@gavinwang269

gavinwang269 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing in favor of a per-class split — this single-file diff (+259 -168, 427 lines in one file) was hard to review in one go. The same changes are split into five PRs, one class per PR, each kept small:

  1. [Testcase Refactoring] Declare TestStaticTritonLauncherUnit as a GENERIC hardware-classification class #198436 — Declare TestStaticTritonLauncherUnit as a GENERIC hardware-classification class
  2. [Testcase Refactoring] Make TestStaticTritonLauncher device-agnostic via instantiate_device_type_tests #198437 — Make TestStaticTritonLauncher device-agnostic via instantiate_device_type_tests
  3. [Testcase Refactoring] Make TestStaticTritonCompileResult device-agnostic via instantiate_device_type_tests #198438 — Make TestStaticTritonCompileResult device-agnostic via instantiate_device_type_tests
  4. [Testcase Refactoring] Keep XPU coverage and classify TestFastLauncher hw classes #198439 — Instantiate TestFastCudaLauncher for CUDA with hw_classification CUDA
  5. [Testcase Refactoring] Split TestFastLauncherCompileResult into mixin, accelerator and CUDA-only classes #198440 — Split TestFastCudaLauncherCompileResult into mixin, fallback and CUDA-only classes

All review feedback on this PR (lint fix, and dropping the not-yet-landed Capability API in favor of has_triton() gating) is already carried into the split pieces; @rogerchen838's last request-changes references imports that no longer exist at this head (see my reply to the inline thread). Review attention can move to the five smaller PRs.

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

Labels

ciflow/inductor module: dynamo module: inductor module: tests/graph This label covers all test cases within the Graph sheet. open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants