Skip to content

[Test] Extract CUDA-only tests into TestLinalgCUDA for test_linalg - #183586

Closed
RiyaP2508 wants to merge 6 commits into
gh/RiyaP2508/10/basefrom
gh/RiyaP2508/10/head
Closed

RiyaP2508 wants to merge 6 commits into
gh/RiyaP2508/10/basefrom
gh/RiyaP2508/10/head

Conversation

@RiyaP2508

@RiyaP2508 RiyaP2508 commented May 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new TestLinalgCUDA(TestCase) class. Guard TestLinalg.setUp/tearDown tf32 settings behind torch.cuda.is_available().

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via test_exclusions = {"TestLinalgCUDA": "*"}.

Test plan

  • TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg — 2926 passed
  • Syntax check passes
  • AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: @fffrog @albanD

cc @albanD

@pytorch-bot

pytorch-bot Bot commented May 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 9c47ac6 with merge base 12b535b (image):

NEW FAILURES - The following jobs have failed:

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

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and
3 helper methods into a new TestLinalgCUDA(TestCase) class. Guard
TestLinalg.setUp/tearDown tf32 behind torch.cuda.is_available().

OOT backends can skip via test_exclusions = {"TestLinalgCUDA": "*"}.

[ghstack-poisoned]
@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

Note on the PR size - this shows 9300+ LOC changed because it moves 31 test methods and 3 helpers between classes within the same file (test_linalg.py). No test logic was added, removed, or modified - it's purely structural.

I considered splitting it, but the 27 TunableOp tests share 3 helper methods (_tunableop_ctx,_set_tunableop_defaults, _compare_untuned_tuned_entries) that need to move together to avoid broken intermediate states. The 4 backend library tests are included for consistency.

For easier review, git diff --stat shows it's just 1 file changed, and collapsing the moved methods in the GitHub diff reveals only the new class definition and setUp/tearDown guard.

Would it be possible to add the skip-pr-sanity-checks label? Happy to split further if you'd prefer a different approach. Thank you!

cc @fffrog

@fffrog

fffrog commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Hi @RiyaP2508, this is a massive PR! :D To be honest, it’s a bit challenging to review such a large diff. We’d still suggest avoiding PRs of this size in the future—I’m sure it’s quite painful for @albanD to go through as well.

However, for this specific PR, I’ll go through it carefully line-by-line, so there's no need to split it up now.

@fffrog

fffrog commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Hey @RiyaP2508, sorry I couldn't finish reviewing this massive PR. It’s a bit overwhelming! :(

I thought of a better way to handle this. The only downside is that you’ll have to submit the PR manually instead of using ghstack.

The idea is to split your changes into two separate commits:

  • First commit: Only include the additions.
  • Second commit: Only include the deletions.

This way, the changes won't get mixed up. It makes it much clearer for the maintainer to see exactly what was added to TestLinalgCUDA and what was removed from TestLinalg.

What do you think?

cc @albanD

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

Hey @RiyaP2508, sorry I couldn't finish reviewing this massive PR. It’s a bit overwhelming! :(

I thought of a better way to handle this. The only downside is that you’ll have to submit the PR manually instead of using ghstack.

The idea is to split your changes into two separate commits:

  • First commit: Only include the additions.
  • Second commit: Only include the deletions.

This way, the changes won't get mixed up. It makes it much clearer for the maintainer to see exactly what was added to TestLinalgCUDA and what was removed from TestLinalg.

What do you think?

cc @albanD

Hi @fffrog, thank you so much for the suggestion and for taking the time to look through this - I completely understand how overwhelming a diff this size can be, and I really appreciate your patience!
The two-commit approach makes total sense to me (additions first, deletions second). I understand how that would make the review much cleaner and easier to follow.

Quick question before I restructure: this PR is part of a 3-PR ghstack for test_linalg:

  1. [Test] Extract CUDA-only tests into TestLinalgCUDA for test_linalg #183586 — Extract CUDA-only tests into TestLinalgCUDA (this one)
  2. [Test] Convert 8 @onlyCUDA to @onlyAccelerator for test_linalg #183587 — Convert 8 @onlyCUDA to @onlyAccelerator
  3. [Test] Replace wrong-device patterns with torch.accelerator for test_linalg #183588 — Replace wrong-device patterns with torch.accelerator

Would you prefer I:

  • Option A: Close all 3 and resubmit as a single manual PR with 4 commits (additions, deletions, onlyAccelerator changes, torch.accelerator changes), or
  • Option B: Restructure just this PR manually and rebase the other two on top after it merges?

Happy to go with whichever works best for you. I understand the importance of keeping PRs smaller and more reviewable - will definitely batch moves more carefully going forward. Thanks again for the guidance!

@fffrog

fffrog commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Would you prefer I:
Option A: Close all 3 and resubmit as a single manual PR with 4 commits (additions, deletions, onlyAccelerator changes, torch.accelerator changes), or
Option B: Restructure just this PR manually and rebase the other two on top after it merges?
Happy to go with whichever works best for you. I understand the importance of keeping PRs smaller and more reviewable - will definitely batch moves more carefully going forward. Thanks again for the guidance!

Hey @RiyaP2508, I think Option B is the better approach. We only need to refactor this current PR into two commits; the rest of the PRs can stay in their current ghstack form. The root cause is that ghstack treats two commits as two separate PRs when submitting.

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

Would you prefer I:
Option A: Close all 3 and resubmit as a single manual PR with 4 commits (additions, deletions, onlyAccelerator changes, torch.accelerator changes), or
Option B: Restructure just this PR manually and rebase the other two on top after it merges?
Happy to go with whichever works best for you. I understand the importance of keeping PRs smaller and more reviewable - will definitely batch moves more carefully going forward. Thanks again for the guidance!

Hey @RiyaP2508, I think Option B is the better approach. We only need to refactor this current PR into two commits; the rest of the PRs can stay in their current ghstack form. The root cause is that ghstack treats two commits as two separate PRs when submitting.

understood. I will soon split them. Thank you!

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #183588

…t_linalg"


## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: fffrog albanD 





[ghstack-poisoned]
RiyaP2508 added 4 commits May 30, 2026 15:54
…t_linalg"


## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: fffrog albanD 





cc albanD

[ghstack-poisoned]
…t_linalg"


## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: fffrog albanD 





cc albanD

[ghstack-poisoned]
…t_linalg"


## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: fffrog albanD 





cc albanD

[ghstack-poisoned]
…t_linalg"


## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

cc: fffrog albanD 





cc albanD

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #183588

1 similar comment
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #183588

pytorchmergebot pushed a commit that referenced this pull request Jun 2, 2026
## Summary

Convert 8 tests verified to have no CUDA-specific code in body from `@onlyCUDA` to `@onlyAccelerator`, making them runnable on XPU, HPU, and PrivateUse1 backends.

- 6 clean swaps: `test_norm_fused_type_promotion`, `test_powsum_dtype_kwarg`, `test_foreach_powsum_dtype_kwarg`, `test_triangular_solve_large`, `test_lu_solve_large_matrices`, `test_triu_tril_large_matrix_64bit`
- 2 with `.cuda()` → `.to(device)` fix: `test_matmul_45724`, `test_logaddexp_cpu_vs_accelerator_complex` (renamed)

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — all passed
- [x] Syntax check passes

Pull Request resolved: #183587
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: #183586
pytorchmergebot pushed a commit that referenced this pull request Jun 2, 2026
…linalg (#183588)

## Summary

Add `_get_other_device()` helper to `TestLinalg` and replace 16 hardcoded `torch.cuda.is_available()` + `'cuda'` wrong-device error-path blocks with device-agnostic equivalents using `torch.accelerator`. Also replace `complement_device` helper and convert 6 `device_type == 'cuda'` tolerance branches to `device_type != 'cpu'`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` - all passed
- [x] Syntax check passes

cC: @fffrog @albanD
Pull Request resolved: #183588
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: #183586, #183587
@github-project-automation github-project-automation Bot moved this from Ready for Merge to Done in PyTorch Test Refactoring Jun 2, 2026
@github-actions
github-actions Bot deleted the gh/RiyaP2508/10/head branch July 2, 2026 02:29
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#183586)

## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

Pull Request resolved: pytorch#183586
Approved by: https://github.com/Skylion007
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ch#183587)

## Summary

Convert 8 tests verified to have no CUDA-specific code in body from `@onlyCUDA` to `@onlyAccelerator`, making them runnable on XPU, HPU, and PrivateUse1 backends.

- 6 clean swaps: `test_norm_fused_type_promotion`, `test_powsum_dtype_kwarg`, `test_foreach_powsum_dtype_kwarg`, `test_triangular_solve_large`, `test_lu_solve_large_matrices`, `test_triu_tril_large_matrix_64bit`
- 2 with `.cuda()` → `.to(device)` fix: `test_matmul_45724`, `test_logaddexp_cpu_vs_accelerator_complex` (renamed)

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — all passed
- [x] Syntax check passes

Pull Request resolved: pytorch#183587
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: pytorch#183586
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…linalg (pytorch#183588)

## Summary

Add `_get_other_device()` helper to `TestLinalg` and replace 16 hardcoded `torch.cuda.is_available()` + `'cuda'` wrong-device error-path blocks with device-agnostic equivalents using `torch.accelerator`. Also replace `complement_device` helper and convert 6 `device_type == 'cuda'` tolerance branches to `device_type != 'cpu'`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` - all passed
- [x] Syntax check passes

cC: @fffrog @albanD
Pull Request resolved: pytorch#183588
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: pytorch#183586, pytorch#183587
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#183586)

## Summary

Move 31 CUDA-specific tests (27 TunableOp + 4 backend library) and 3 helper methods into a new `TestLinalgCUDA(TestCase)` class. Guard `TestLinalg.setUp`/`tearDown` tf32 settings behind `torch.cuda.is_available()`.

This is pure code movement — no test logic was changed. The high LOC count is entirely from moving methods between classes in the same file. OOT backends can skip the entire class via `test_exclusions = {"TestLinalgCUDA": "*"}`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — 2926 passed
- [x] Syntax check passes
- [x] AST parse confirms TestLinalg: 262 methods, TestLinalgCUDA: 36 methods

Pull Request resolved: pytorch#183586
Approved by: https://github.com/Skylion007
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ch#183587)

## Summary

Convert 8 tests verified to have no CUDA-specific code in body from `@onlyCUDA` to `@onlyAccelerator`, making them runnable on XPU, HPU, and PrivateUse1 backends.

- 6 clean swaps: `test_norm_fused_type_promotion`, `test_powsum_dtype_kwarg`, `test_foreach_powsum_dtype_kwarg`, `test_triangular_solve_large`, `test_lu_solve_large_matrices`, `test_triu_tril_large_matrix_64bit`
- 2 with `.cuda()` → `.to(device)` fix: `test_matmul_45724`, `test_logaddexp_cpu_vs_accelerator_complex` (renamed)

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` — all passed
- [x] Syntax check passes

Pull Request resolved: pytorch#183587
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: pytorch#183586
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…linalg (pytorch#183588)

## Summary

Add `_get_other_device()` helper to `TestLinalg` and replace 16 hardcoded `torch.cuda.is_available()` + `'cuda'` wrong-device error-path blocks with device-agnostic equivalents using `torch.accelerator`. Also replace `complement_device` helper and convert 6 `device_type == 'cuda'` tolerance branches to `device_type != 'cpu'`.

## Test plan
- [x] `TEST_CONFIG=cuda python3 test/run_test.py -i test_linalg` - all passed
- [x] Syntax check passes

cC: @fffrog @albanD
Pull Request resolved: pytorch#183588
Approved by: https://github.com/Skylion007, https://github.com/fffrog
ghstack dependencies: pytorch#183586, pytorch#183587
pytorchmergebot pushed a commit that referenced this pull request Sep 28, 2026
## Summary

`test_tf32_tunableop` and `test_tf32_offline_tunableop` were enabled for all
ROCm architectures in #183474, which removed both `@runOnRocmArch(MI300_ARCH)`
decorators along with the now-unused import. #183586 re-added them while
extracting CUDA-only tests into `TestLinalgCUDA`. `git blame` attributes both
current decorators to that refactor rather than to any deliberate
re-restriction, so this appears to be an accidental regression. This PR
restores the state #183474 landed.

While in the same area, this also widens `@runOnRocmArch(MI200_ARCH)` on
`test_fp16_backward_preserves_subnormals_rocm`, added for MI200 in #183766.
RDNA is excluded there only by omission from the allowlist, and the test
passes on RDNA.

Part of #196583.

## Validation

Repeated runs on gfx1100 (Radeon PRO W7900), gfx1151 and gfx1200, HIP
`7.16.26320`, with identical results every time.

```
test/test_linalg.py::TestLinalgCudaOnlyCUDA::test_tf32_tunableop_cuda_float32 PASSED
test/test_linalg.py::TestLinalgCudaOnlyCUDA::test_tf32_offline_tunableop_cuda_float32 PASSED
test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_False_backend_cublas_cuda PASSED
test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_False_backend_cublaslt_cuda PASSED
test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_True_backend_cublas_cuda PASSED
test/test_matmul_cuda.py::TestMatmulCudaCUDA::test_fp16_backward_preserves_subnormals_rocm_batched_True_backend_cublaslt_cuda PASSED
```

Pull Request resolved: #197361
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants