Repository navigation
[Testcase Refactoring] Make test_rng device-agnostic via instantiate_device_type_tests - #198356
gavinwang269 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:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198356
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 70d9b4f with merge base 17782e7 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@pytorchbot label "module: tests/graph" |
42151a8 to
0952229
Compare
|
|
@claude review these changes |
|
Claude finished @jansel's task in 54s —— View job This mechanical move has two blockers: it fails lint, and on out-of-tree backends (the PR's motivation) PR Review: #198356SummaryThe PR moves Infrastructure
Code Quality
Testing
RecommendationRequest Changes: fix the lint failure. Then either make RNG preservation device-generic or confirm that |
0952229 to
c73f19a
Compare
…device migrations Rebased onto latest main (scaffold + migrated debuginfo from pytorch#198361 are kept). Drops the seven methods whose device versions arrive in the parallel move pieces pytorch#198354 (test_bad_decomp), pytorch#198355 (test_joint_graph), pytorch#198356 (test_rng), pytorch#198357 (test_emulate_precision_casts), pytorch#198358 (test_bad_lowering), pytorch#198359 (test_bisect_pre_grad_graph) and pytorch#198360 (test_cudagraph_bisect_max); keeps test_pre_grad, test_crossref and test_eager_backend. Marks the remaining class GENERIC, renames test_ns to bisector_ns (a class attribute named test_* would otherwise be collected by instantiate_device_type_tests), slims tearDown and removes get_lib. Must merge LAST in the series, only after every sibling move above has landed; otherwise the deleted GPU tests lose their replacements. Also fixes the lint failures on the previous revision: removes imports that are unused at this point in the series (contextmanager, import_module, _prims_common, preserve_rng_state, module-level config) and normalizes the blank-line runs left by the method removals. These imports are intentionally not kept for the siblings; each move piece brings back exactly what it uses. Signed-off-by: gavinwang269 <[email protected]>
|
@claude's review is correct on both counts — thanks @jansel for the look.
PTAL. |
|
@claude review again |
|
Claude finished @jansel's task in 1m 3s —— View job The earlier lint and RNG-scope problems are fixed. One thing is left: use PR Review: #198356SummaryThe PR moves Code Quality
RecommendationRequest Changes: fold |
|
|
||
| instantiate_device_type_tests( | ||
| TestCompilerBisectorRNG, globals(), only_for=("cuda", "xpu"), allow_xpu=True | ||
| ) |
There was a problem hiding this comment.
Is it confirmed that all test cases in the TestCompilerBisectorRNG class do not support privateuse1 or other out-of-tree devices, and the only_for extension is not powerful enough? It is recommended that the except_for blacklist be used.
There was a problem hiding this comment.
Agreed, reworked in 70d9b4f: instantiate now uses except_for="cpu" (consistent with the ACCELERATOR tag), and the device limit is made explicit instead: preserve_rng_state only saves/restores CPU, CUDA and XPU RNG state, so other accelerators are skipped by name rather than excluded from instantiation. Verified on Ascend 910B4: the NPU variant is now instantiated and skips cleanly (0.009s) instead of being silently absent.
| # accelerator devices; other out-of-tree backends are instantiated out via | ||
| # `only_for` rather than silently diverging. | ||
| @unittest.skipIf(not has_triton(), "requires Triton") | ||
| def test_rng(self, device): |
There was a problem hiding this comment.
If the class TestCompilerBisectorRNG uses the blacklist except_for, a decorator similar to skipPRIVATEUSE1(fn) can be used.
There was a problem hiding this comment.
Adopted in 70d9b4f: @skipPRIVATEUSE1 on the test, exactly along the lines you suggested.
| @unittest.skipIf(not has_triton(), "requires Triton") | ||
| def test_rng(self, device): | ||
| def foo(): | ||
| return torch.rand([10], device=device) + 1 |
There was a problem hiding this comment.
Before modification, the feature in Triton belonged to the class level, but now it is refined to the test case level. If all test cases require it, it can remain consistent with the previous approach and be placed at the class level.
There was a problem hiding this comment.
Automated review of c73f19a: nothing blocking; ready for human review.
Test-only change: test_rng moves out of TestCompilerBisector into a new device-generic class, TestCompilerBisectorRNG, which only runs on cuda and xpu because preserve_rng_state only restores CPU/CUDA/XPU RNG state. The new class follows the existing TestCompilerBisectorDevice pattern. The old test's gates are preserved (MTIA is the one exception, and the RNG comparison was unreliable there anyway), and no skip or expected-failure list refers to the old test ID. The maintainer's comments only asked for automated reviews, and the author has replied to the issues those reviews raised.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
…device_type_tests Rebased onto latest main: the Device-class scaffold already exists (merged via pytorch#198361). `test_rng` is moved out of the CPU-excluded base class into a dedicated device-instantiated class. `torch._dynamo.utils.preserve_rng_state` only saves and restores CPU, CUDA and XPU RNG state, so the eager-vs-compiled RNG comparison `test_rng` relies on is only meaningful on CUDA and XPU. The new class is instantiated with `only_for=("cuda", "xpu")` so out-of-tree backends that lack RNG save/restore are excluded at instantiation time instead of silently diverging. A follow-up could generalize `preserve_rng_state` via `torch.get_device_module(device)` to widen this coverage. Also fixes the E301/E303 lint issues flagged on the previous revision. Signed-off-by: gavinwang269 <[email protected]>
…kipPRIVATEUSE1 per review Keep the ACCELERATOR contract consistent (instantiate without only_for) and make the RNG-state coverage limit explicit instead of narrowing the device matrix via only_for: preserve_rng_state saves/restores CPU, CUDA and XPU RNG state only, so PrivateUse1 variants now skip explicitly. Hoist the Triton gate to the class level (single-test class).
c73f19a to
70d9b4f
Compare
|
@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 |
…device_type_tests (pytorch#198356) ## Summary Move `test_rng` out of the guard-skipped `TestCompilerBisector` class into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old `@unittest.skipIf(not HAS_GPU)` class guard. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the `instantiate_device_type_tests` scaffold already landed via pytorch#198361. ## Changes `test/dynamo/test_compiler_bisector.py` (+38 -20): 1. Add `TestCompilerBisectorRNG(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`) containing the moved `test_rng`; the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by instantiation, and the Triton gate sits on the class (same pattern as pytorch#198357). 2. Instantiate with `except_for="cpu"` (per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix via `only_for`). `test_rng` relies on `torch._dynamo.utils.preserve_rng_state`, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU: `do_bisect` reports `eager` instead of `inductor`). Such devices now skip explicitly via `@skipPRIVATEUSE1` rather than being silently excluded from instantiation. ## Notes - Generalizing `preserve_rng_state` via `torch.get_device_module(device)` would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate. - Test IDs change from `TestCompilerBisector.test_rng` to per-device variants (`test_rng_cuda`, `test_rng_xpu`, `test_rng_npu` [skipped], ...). I checked the `test/dynamo_skips/` and `test/dynamo_expected_failures/` entries and the slow-test lists in `main`: nothing is keyed on the old `TestCompilerBisector.test_rng` name. ## Motivation The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`. Out-of-tree accelerators registered via `PrivateUse1` are not in this list, so the test was skipped even where it can run. `instantiate_device_type_tests` gives each supported device its own variant, and `hw_classification` provides metadata for `--hw-classification` filtering. ## Test Plan | Environment | Result | |---|---| | CPU (`env-pytorch-2.16-20261029-cpu`) | `pytest --collect-only -q` -> **11 tests collected** (the moved test no longer appears un-instantiated) | | NPU (`env-pytorch-2.16-20261029-npu`, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0) | `test_rng_npu` is instantiated and **skips cleanly (0.009s)** via `@skipPRIVATEUSE1` instead of being silently absent | | CUDA / XPU execution | covered by the ciflow trunk jobs | | lint | `lintrunner` (includes in-tree TEST_LINTER): no issues | Pull Request resolved: pytorch#198356 Approved by: https://github.com/lizhihai137, https://github.com/jansel
…device_type_tests (pytorch#198356) ## Summary Move `test_rng` out of the guard-skipped `TestCompilerBisector` class into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old `@unittest.skipIf(not HAS_GPU)` class guard. Split from pytorch#191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the `instantiate_device_type_tests` scaffold already landed via pytorch#198361. ## Changes `test/dynamo/test_compiler_bisector.py` (+38 -20): 1. Add `TestCompilerBisectorRNG(TestCase)` (`hw_classification = HardwareClassification.ACCELERATOR`) containing the moved `test_rng`; the hardcoded `device=GPU_TYPE` becomes the `device` argument injected by instantiation, and the Triton gate sits on the class (same pattern as pytorch#198357). 2. Instantiate with `except_for="cpu"` (per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix via `only_for`). `test_rng` relies on `torch._dynamo.utils.preserve_rng_state`, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU: `do_bisect` reports `eager` instead of `inductor`). Such devices now skip explicitly via `@skipPRIVATEUSE1` rather than being silently excluded from instantiation. ## Notes - Generalizing `preserve_rng_state` via `torch.get_device_module(device)` would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate. - Test IDs change from `TestCompilerBisector.test_rng` to per-device variants (`test_rng_cuda`, `test_rng_xpu`, `test_rng_npu` [skipped], ...). I checked the `test/dynamo_skips/` and `test/dynamo_expected_failures/` entries and the slow-test lists in `main`: nothing is keyed on the old `TestCompilerBisector.test_rng` name. ## Motivation The `@unittest.skipIf(not HAS_GPU)` class guard uses `HAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON`. Out-of-tree accelerators registered via `PrivateUse1` are not in this list, so the test was skipped even where it can run. `instantiate_device_type_tests` gives each supported device its own variant, and `hw_classification` provides metadata for `--hw-classification` filtering. ## Test Plan | Environment | Result | |---|---| | CPU (`env-pytorch-2.16-20261029-cpu`) | `pytest --collect-only -q` -> **11 tests collected** (the moved test no longer appears un-instantiated) | | NPU (`env-pytorch-2.16-20261029-npu`, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0) | `test_rng_npu` is instantiated and **skips cleanly (0.009s)** via `@skipPRIVATEUSE1` instead of being silently absent | | CUDA / XPU execution | covered by the ciflow trunk jobs | | lint | `lintrunner` (includes in-tree TEST_LINTER): no issues | Pull Request resolved: pytorch#198356 Approved by: https://github.com/lizhihai137, https://github.com/jansel
Summary
Move
test_rngout of the guard-skippedTestCompilerBisectorclass into its own instantiated device class, so it runs on real accelerator devices instead of being skipped by the old@unittest.skipIf(not HAS_GPU)class guard.Split from #191435 (refactoring this file for out-of-tree accelerator support). This piece is a pure method move: the
instantiate_device_type_testsscaffold already landed via #198361.Changes
test/dynamo/test_compiler_bisector.py(+38 -20):TestCompilerBisectorRNG(TestCase)(hw_classification = HardwareClassification.ACCELERATOR) containing the movedtest_rng; the hardcodeddevice=GPU_TYPEbecomes thedeviceargument injected by instantiation, and the Triton gate sits on the class (same pattern as [Testcase Refactoring] Make test_emulate_precision_casts device-agnostic via instantiate_device_type_tests #198357).except_for="cpu"(per @lizhihai137's review: keeps the ACCELERATOR contract instead of narrowing the device matrix viaonly_for).test_rngrelies ontorch._dynamo.utils.preserve_rng_state, which today saves/restores only CPU, CUDA and XPU RNG state; on backends without generator save/restore the eager-vs-compiled comparison silently diverges and the bisector blames the wrong subsystem (verified on an Ascend NPU:do_bisectreportseagerinstead ofinductor). Such devices now skip explicitly via@skipPRIVATEUSE1rather than being silently excluded from instantiation.Notes
preserve_rng_stateviatorch.get_device_module(device)would widen this test's device coverage; that is a source-side change beyond this series, left as a follow-up candidate.TestCompilerBisector.test_rngto per-device variants (test_rng_cuda,test_rng_xpu,test_rng_npu[skipped], ...). I checked thetest/dynamo_skips/andtest/dynamo_expected_failures/entries and the slow-test lists inmain: nothing is keyed on the oldTestCompilerBisector.test_rngname.Motivation
The
@unittest.skipIf(not HAS_GPU)class guard usesHAS_GPU = HAS_CUDA_AND_TRITON or HAS_XPU_AND_TRITON or HAS_MTIA_AND_TRITON. Out-of-tree accelerators registered viaPrivateUse1are not in this list, so the test was skipped even where it can run.instantiate_device_type_testsgives each supported device its own variant, andhw_classificationprovides metadata for--hw-classificationfiltering.Test Plan
env-pytorch-2.16-20261029-cpu)pytest --collect-only -q-> 11 tests collected (the moved test no longer appears un-instantiated)env-pytorch-2.16-20261029-npu, Ascend 910B4 / CANN 9.2.0 GA / torch_npu 737bb43 / triton-ascend 3.6.0)test_rng_npuis instantiated and skips cleanly (0.009s) via@skipPRIVATEUSE1instead of being silently absentlintrunner(includes in-tree TEST_LINTER): no issuescc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98 @fffrog