Repository navigation
[Testcase Refactoring] Split the Triton-gated CUDA launcher unit test into a CUDA-classified class - #203548
[Testcase Refactoring] Split the Triton-gated CUDA launcher unit test into a CUDA-classified class#203548gavinwang269 wants to merge 2 commits into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (4): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203548
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 7f38462 with merge base d0c5544 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
93f13c2 to
ac3bdfa
Compare
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant.
ac3bdfa to
8d82825
Compare
|
@pytorchbot label "module: tests/graph" |
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant.
8d82825 to
324f959
Compare
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant.
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant.
|
@jansel could you approve and run the workflows on Of the PRs we have on
+77/−54, single file, test-side only — no production module is touched, and the same three-file split is what the CUDA-only classes look like on main already (e.g. |
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant. Rebase notes (onto main after pytorch#199309): main's two new oversized shared memory tests (test_oversized_shared_mem, test_too_high_oversized_shared_mem) are kept and converted to this PR's per-device form: injected device argument, per-test Triton gate, and a CUDA-only SkipTest guard since the shared helper _oversized_shared_mem_limits() reads torch.cuda device properties. The from pathlib import Path import is restored because test_make_launcher_reuses_loaded_kernel_after_cache_context still calls Path(); without it the PR head raises NameError (undefined-name check on the pre-rebase head confirms this predates the rebase).
…via instantiate_device_type_tests Independent slice (launcher migration only; the three unit-class splits moved out of this PR to their own dependency-free PRs pytorch#203548 pytorch#203550 pytorch#203551): class-level @requires_gpu_and_triton replaced by per-test Triton gates and instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True); 12 of 14 tests gain the injected device argument; write_cubin_to_tmp picks the binary key per device (npubin alongside zebin/cubin/hsaco); the JITFunction getitem save becomes unconditional (module scope) and the patch install moves into setUp/tearDown of every instantiated device variant. Rebase notes (onto main after pytorch#199309): main's two new oversized shared memory tests (test_oversized_shared_mem, test_too_high_oversized_shared_mem) are kept and converted to this PR's per-device form: injected device argument, per-test Triton gate, and a CUDA-only SkipTest guard since the shared helper _oversized_shared_mem_limits() reads torch.cuda device properties. The from pathlib import Path import is restored because test_make_launcher_reuses_loaded_kernel_after_cache_context still calls Path(); without it the PR head raises NameError (undefined-name check on the pre-rebase head confirms this predates the rebase). Rebase notes (onto main after pytorch#198440): pytorch#198440 refactored the unrelated TestFastLauncherCompileResult class and moved the file's instantiate_device_type_tests calls into a single trailing group; this PR's TestStaticTritonLauncher instantiation now joins that group. The import-block and tail hunks merged accordingly; nothing inside the decoupled class changed.
There was a problem hiding this comment.
Automated review of da883b5: nothing blocking; ready for human review.
The PR moves test_tensor_memory_autotuner_retries_without_pipelining out of TestStaticTritonLauncherUnit into a new TestStaticTritonLauncherUnitCuda class, classified HardwareClassification.CUDA and not device-type-instantiated. Recommendation: Approve. Every point raised is non-blocking, though the reviewer would most like the cross-class delegation dropped and the docstring corrected before merge.
⚪ 4 non-blocking findings
Helper sharing: one delegate is unused and the other is fragile (non-blocking). _global_scratch_kernel = staticmethod(TestStaticTritonLauncherUnit._global_scratch_kernel) is never used: the only test calls self._can_statically_launch, which doesn't call _global_scratch_kernel. _can_statically_launch is read off TestStaticTritonLauncherUnit when the class body runs at import. Its only other users are the cubin-metadata tests, which sibling # 203551 is said to move. Since the slices are meant to merge in "any merge order", if # 203551 moves the helper off the unit class, the module fails to import with AttributeError and every test in the file is lost. This is plausible, not confirmed. The file already shares helpers through mixins (StaticLauncherTestMixin, _FastLauncherMixin, _FastLauncherCompileMixin). Suggested fix: put _can_statically_launch (and _global_scratch_kernel only once a test needs it) on a small mixin both unit classes inherit. Placing the class directly after TestStaticTritonLauncherUnit would also keep StaticLauncherTestMixin next to its first consumer, TestStaticTritonLauncher.
The new class docstring (649-659) is inaccurate (non-blocking). It names CUDAAutotuner, which doesn't exist in the tree; the test builds a CachingAutotuner (the PR body repeats the wrong name). It says "not instantiated", but the class has @ instantiate_parametrized_tests; what it skips is instantiate_device_type_tests. It says TestStaticTritonLauncherUnit is left with "only device-independent tests" and "can be declared GENERIC", but at HEAD that class still has four @ skipIfRocm tests, a ROCm-only test and no hw_classification. The docstring describes where the series ends up, not this commit. Other class docstrings here are one or two lines about what the class tests; move the refactoring history to the PR description.
The stated reason for the CUDA classification doesn't separate this test from ones that stay behind (non-blocking). test/REVIEW.md Rule 1 calls a class accelerator-specific when its tests "will fail" on other accelerators. This test is fully mocked (C_impl is a Mock, DeviceGuard patched, device_props a SimpleNamespace) and needs no device. The docstring's reason ("exercise CUDA-internal behavior through mocks") applies equally to test_tensor_memory_limit and test_tensor_memory_missing_metadata, which mock the same path but stay in the class meant to become GENERIC. The real differences are the HAS_TRITON gate and @ skipIfRocm (a build check). A GENERIC version would drop out of the standard CUDA jobs, and CPU CI images don't install Triton. That coverage argument is a reasonable basis for CUDA. Please state it in the docstring and PR description instead, so later slices apply the same criterion.
The unit class's hw_classification has no named owner (non-blocking). TestStaticTritonLauncherUnit still has no hw_classification (Rule 2), which Scenario 1 allows mid-series. None of the listed siblings (# 203550, # 203551, # 198437) says it declares GENERIC, and "any merge order" leaves it unclear which one does. Please name the slice. Also, the test plan's "in-tree test linter + lintrunner clean" doesn't cover this file: it is on tools/linter/adapters/test_linter_allowlist.json:458, and test_linter.py:779-781 skips allowlisted files silently.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
|
Hi @fffrog - this slice is ready for a final pass: all CI green (193 checks), review threads resolved, lizhihai137 approved on Nov 20. It is one of the static-launcher unit-test splits (+76/-54, single test file) from the family you reviewed in #198438. Your approve would put it over the Testing-set line so it can merge. Thanks! |
|
Hi @jansel - you approved the predecessors of this chain (198438/198439/198440) before we re-split it into 203548/203550/203551 per review feedback. Same file (test/inductor/test_static_triton_launcher.py), same device-agnostic structure, moderate diff each. lizhihai137 re-approved all three on Nov 20, but his approval does not satisfy the merge gate; one approve from you or another Testing/Core member would land the set. 198437 is the remaining sibling and can wait for this set to settle. |
|
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 8 jobs have failed, first few of them are: trunk / win-vs2022-cpu-py3 / test (default, 5, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 4, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 1, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 2, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 8, 12, windows.4xlarge.nonephemeral) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour 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 |
…ssified unit class The three global-scratch unit tests in TestStaticTritonLauncherUnit are RoCm-incompatible (@skipIfRocm or hip-only) and keep the otherwise device-independent unit class from being declared GENERIC. pytorch#203548 already established TestStaticTritonLauncherUnitCuda for exactly this purpose and pre-delegated the _global_scratch_kernel helper, so the tests move there verbatim instead of introducing a second class. Test Plan: python -m pytest test/inductor/test_static_triton_launcher.py -q
…ssified unit class The three global-scratch unit tests in TestStaticTritonLauncherUnit are RoCm-incompatible (@skipIfRocm or hip-only) and keep the otherwise device-independent unit class from being declared GENERIC. pytorch#203548 already established TestStaticTritonLauncherUnitCuda for exactly this purpose and pre-delegated the _global_scratch_kernel helper, so the tests move there verbatim instead of introducing a second class. Test Plan: python -m pytest test/inductor/test_static_triton_launcher.py -q
…via instantiate_device_type_tests (#198437) ## Current state (2026-12-02) - Head `879a6d25a2f3`, rebased onto main on Dec 1. One file changed: `test/inductor/test_static_triton_launcher.py`. - All 213 checks on the head are completed with nothing failing (208 success, 4 skipped, 1 neutral), and none waiting for approval. - All 16 review threads are resolved. Each carries a reply, and the two that still cited a pre-rebase head were re-verified against this head today with line numbers. - Labels: `topic: not user facing`, `ready for review`, `module: tests/graph`, `ciflow/inductor`, `ciflow/xpu`. - Waiting on one approving review from a member of the merge-rules approver lists. The two content approvals so far (lizhihai137 on Nov 2, KarhouTam on Dec 1) are from contributors outside those lists, so the merge bot still reports the PR as needing additional approval. ## Summary Launcher-migration slice of the static-launcher file (the original #192893 monolith has been re-cut into dependency-free, review-sized PRs per #198436's review request; this PR is +363/-324 in one file; the unit-class splits are in #203548 (Triton-gated autotuner), #203550 (RoCm scratch trio), #203551 (cubin metadata pair), each with its own correctly-scoped class; merge in any order). ## Changes (one file: test/inductor/test_static_triton_launcher.py) `TestStaticTritonLauncher` on main is a `@requires_gpu_and_triton` class with 24 test methods bound to `GPU_TYPE`. It is made device-agnostic via `instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True)` with `hw_classification = HardwareClassification.ACCELERATOR`. All 24 tests are kept; where each one lives: - 13 general launcher tests stay in `TestStaticTritonLauncher` (ACCELERATOR). All 13 now take the injected `device` and pass it to `self._make_launcher(compiled_kernel, device)`, so the binary key (`cubin`/`zebin`/`npubin`/`hsaco`), the launcher class and the load interface resolve from the device under test instead of `GPU_TYPE`. `test_bfloat16_scalar` swaps its process-wide `@skipIfRocm` / `@unittest.skipIf(not HAS_XPU_AND_TRITON and not SM80OrLater, ...)` guards for the device-aware `@skipCUDAIfRocm` / `@skipCUDAIf(not SM80OrLater, ...)` from `common_device_type`. - The removed class-level `@requires_gpu_and_triton` is replaced by a `setUp` gate that is per-device rather than process-wide: `has_triton_for_device(self.device_type)` so a backend without Triton skips even when another backend has it, and `is_registered_static_launch_device(self.device_type)` (only cuda, hip and xpu register a static launcher) so Triton-capable but launcher-less backends skip instead of raising. - The 8 `test_xpu_*` tests move to a new `TestStaticTritonLauncherXpuOnly` (`hw_classification = XPU`, keeps the class-level `@requires_gpu_and_triton` and its per-test `@unittest.skipUnless(HAS_XPU_AND_TRITON, ...)` decorators), instantiated `only_for="xpu", allow_xpu=True`, mirroring `TestFastLauncherXpuOnly` from #198439. - The two oversized-shared-memory tests (`test_oversized_shared_mem`, `test_too_high_oversized_shared_mem`, both on main via #199309; their helper reads `torch.cuda.get_device_properties`) move to a new `TestStaticTritonLauncherCudaOversized` (`hw_classification = CUDA`), instantiated `only_for=("cuda",)` with a `setUp` skip for `self.device_type != "cuda"` (plus a runtime `has_triton_for_device` skip), the way `TestCudaStaticTritonCompileResult` is scoped. Their `@skipIfRocm` is kept; `@skipIfXpu` and the body-level `SkipTest` guards are dropped because the class is CUDA-only. - `test_launcher_keeps_module_owner_alive_until_release` moves into `TestStaticTritonLauncherUnit`, the host-side unit class, so the module-owner lifetime check runs once without a working Triton device. - The `instantiate_device_type_tests` calls for the three launcher classes sit in the file's single trailing group, the shape #198440 established. No helper or other class is touched: `StaticLauncherTestMixin` already takes optional `device` arguments on main (landed via #198439/#198440), and `TestFastLauncher` plus the compile-result classes keep their current scoping. ## Notes - No dependency on the sibling split PRs; the overlapping import lines collapse to one copy at rebase. - MTIA: the ACCELERATOR class is instantiated for accelerator device types with `except_for="cpu"`; no MTIA base is registered, so no MTIA variants are generated. This is a coverage note for #198436's open question, not a regression on currently-tested devices. ## Verification - [x] CPU wheel env (torch 2.16.0.dev20261029+cpu): `TestStaticTritonLauncherUnit` failure set identical to the pre-change head (28 tests; the two failures are preexisting wheel-vs-trunk artifacts already present before this PR's edits, 3 skips) ``` python test/inductor/test_static_triton_launcher.py TestStaticTritonLauncherUnit ``` - [x] `ast.parse` clean; ruff 0.14.4 with the repo config: `check` and `format --check` clean on the file; in-tree `test_linter` run with this file's allowlist entry temporarily removed: no findings in this PR's three launcher classes (the remaining file-level findings belong to the unit-class and fast-launcher regions tracked in #198436 and the fast-launcher follow-up) - [ ] `ciflow/xpu` label requested so this PR's CI actually exercises the XPU instantiations (the 13 ACCELERATOR tests on xpu and the 8-test XPU-only class); CUDA CI covers the cuda instantiations and the new CUDA-only class - No XPU, CUDA or NPU device is available in this environment, so the device-generic skips above are static-reasoning plus CI, not test-run evidence. ## Linked issue or supporting maintainer Part of #185590 (test case refactoring initiative), hardware-decoupling slice. Pull Request resolved: #198437 Approved by: https://github.com/lizhihai137, https://github.com/KarhouTam, https://github.com/jansel
…ified class (#203550) ## Summary Slice 2 of 4 of the static-launcher re-cut (independent; any order; original monolith #198437). Moves three scratch-space tests out of `TestStaticTritonLauncherUnit` into the existing CUDA-classified class `TestStaticTritonLauncherUnitCuda`, established by #203548: `test_global_scratch_allocation`, `test_fast_launcher_rejects_global_scratch` (both `@skipIfRocm`) and `test_rocm_rejects_global_scratch` (ROCm-only). No new class: the three bodies move verbatim, and the scratch-kernel factory is delegated by reference, never copied. The class docstring, inherited stale from main, is corrected in this PR: it claimed the class cannot run on RoCm and named a `CUDAAutotuner` that does not exist; it now describes the class as covering the CUDA/ROCm paths of `CachingAutotuner` and `StaticallyLaunchedCudaKernel`, noting that `CachingAutotuner` itself is device-generic. (+50/-55, one file; relocation of the three test bodies plus the docstring fix) ## What classifies `TestStaticTritonLauncherUnit` This slice does not declare `hw_classification` on the source class. The unit class still holds the last two device-gated tests, `test_static_launch_takes_cubin_from_metadata_group` and `test_static_launch_rejects_ambiguous_metadata_group` (`@skipIfRocm`); slice 3 (#203551) moves those into `TestStaticTritonLauncherUnitMetadataGroup` (GENERIC). Once that lands no device-gated test remains in the unit class, and its GENERIC declaration is the final slice of this re-cut, which is not opened yet. REVIEW.md Scenario 1 permits the multi-PR split; this section is the split explanation the rule asks for. ## Test Plan - [x] cpu wheel venv (previous head): failure set identical to base; the two commits added after it each change only the class docstring (AST-verified), no behavioral diff - [x] ROCm run: green. Run 46792320695 (<https://github.com/pytorch/pytorch/actions/runs/46792320695>), triggered by head `f72c3ea88139`: build plus all 8 `default` shards pass on `linux-noble-rocm-py3.11-mi300`; `test_rocm_rejects_global_scratch` ran on shard 1/8 and passed, per the shard's junit report (56 tests, 0 skipped, 0 failed). The current head `daeb4dafbdf3` only rewords the class docstring, no behavioral change. The `ciflow/rocm-mi300` label made `test_rocm_rejects_global_scratch` actually execute. It runs because `rocm-mi300.yml` runs the `default` config, which discovers this file (it is in neither the job's `tests-to-exclude` nor the `ROCM_BLOCKLIST` in `test/run_test.py`), and ROCm jobs exclude `GENERIC` classes only, so the CUDA-classified class runs. The earlier review round suggested `ciflow/inductor-rocm-mi300` instead; that workflow runs the `inductor` config, whose `test_inductor_shard` in `.ci/pytorch/test.sh` never includes `test_static_triton_launcher`. - [ ] in-tree test linter: not a meaningful check for this file yet. It is listed in `tools/linter/adapters/test_linter_allowlist.json`, and `check_file` in `tools/linter/adapters/test_linter.py` returns early for allowlisted paths, so the regular lintrunner path verifies nothing here. The file leaves the allowlist when the family-wide classification completes. ## Linked issue or supporting maintainer Part of #185590 (test case refactoring initiative) - hardware-decoupling slice. Pull Request resolved: #203550 Approved by: https://github.com/lizhihai137, https://github.com/jansel
Summary
Slice 1 of 4 of the static-launcher re-cut (original monolith #198437 at 505 lines; all slices independent, any merge order) per #198436's review request.
Moves the Triton-gated autotuner unit test (
test_tensor_memory_autotuner_retries_without_pipelining) out ofTestStaticTritonLauncherUnitinto a new CUDA-classified, non-instantiated classTestStaticTritonLauncherUnitCuda. The body exercisesCUDAAutotuner/StaticallyLaunchedCudaKernelinternals through mocks and is RoCm-skipped -- CUDA-family-specific, so device-variant instantiation (XPU/PrivateUse1 copies) would add noise, not coverage. The shared helpers (_global_scratch_kernel,_can_statically_launch) stay on the unit class and are delegated by reference (staticmethod-wrapped so signatures hold); nothing is copied.(+74/-52, one file)
Test Plan
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo
Rebase note (2026-11-06): replayed onto current main after #200916 touched the same file; slice content unchanged (+77/-54).
Linked issue or supporting maintainer
Part of #185590 (test case refactoring initiative) - hardware-decoupling slice.