Skip to content

[MAGMA][CUDA] eig: deprecate MAGMA and dispatch to cuSOLVER unconditionally - #173510

Closed
nikitaved wants to merge 12 commits into
gh/nikitaved/26/basefrom
gh/nikitaved/26/head
Closed

nikitaved wants to merge 12 commits into
gh/nikitaved/26/basefrom
gh/nikitaved/26/head

Conversation

@nikitaved

@nikitaved nikitaved commented Jan 27, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

As per title.

Benchmark script:

import torch
import torch.utils.benchmark as benchmark

from itertools import product

results = []

batches = [(), (16,), (64,)]
sizes = [16, 128, 512,  2048]

for b, n in product(batches, sizes):
    shape = b + (n, n)
    print(f"Testing shape={shape}")
    label = "torch.eig"
    sub_label = f"{shape}"
    x = torch.rand(*shape, device="cuda")
    x = x + x.mH
    stmt = "torch.linalg.eig(x)"
    for backend in ("magma", "cusolver"):
        torch.backends.cuda.preferred_linalg_library(backend)
        # warm-up
        for _ in range(5):
            exec(stmt)

        results.append(benchmark.Timer(
            stmt=stmt,
            globals={'x': x},
            label=label,
            sub_label=sub_label,
            description=backend,
        ).blocked_autorange(min_run_time=1))

compare = benchmark.Compare(results)
compare.print()

Benchmark results (H100):

[-------------------- torch.eig -------------------]                                                                                              
                        |     magma     |   cusolver  | cusolver speedup                                                                                            
1 threads: ------------------------------------------                                                                                              
      (16, 16)          |      67215.3  |       893.3 | 75.24                                                                                             
      (128, 128)        |     390101.4  |     10526.9 | 37.05                                                                                            
      (512, 512)        |    1614706.1  |     61347.5 | 26.32                                                                                            
      (2048, 2048)      |    6447301.5  |    356181.2 | 18.10                  
      (16, 16, 16)      |     660036.1  |     13095.2 | 50.40      
      (16, 128, 128)    |    6530718.7  |    166647.0 | 39.18
      (16, 512, 512)    |   20375827.4  |    994115.1 | 20.49                                                                                              
      (16, 2048, 2048)  |   98335490.6  |   5717112.5 | 17.20                                                                                             
      (64, 16, 16)      |    2167358.2  |     51977.5 | 41.69                                                                                             
      (64, 128, 128)    |   25925259.8  |    664574.7 | 39.01                   
      (64, 512, 512)    |   84731703.1  |   3946917.0 | 21.46                                                                                             
      (64, 2048, 2048)  |  380878661.3  |  23008593.5 | 16.55                                                                                           
                                                                                                                                                   
Times are in microseconds (us).                       

cc @ptrblck @msaroufim @eqy @jerryzh168 @tinglvv @nWEIdia

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jan 27, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@pytorch-bot pytorch-bot Bot added the release notes: linalg_frontend release notes category label Jan 27, 2026
@pytorch-bot

pytorch-bot Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 Cancelled Jobs, 4 Unrelated Failures

As of commit b1070a8 with merge base aa3b33d (image):

CANCELLED JOBS - The following jobs were cancelled. Please retry:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

@nikitaved nikitaved added ciflow/trunk Trigger trunk jobs on your pull request ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 module: cuda Related to torch.cuda, and CUDA support in general labels Jan 27, 2026
[ghstack-poisoned]
@nikitaved nikitaved changed the title [MAGMA][CUDA] eig: deprecate MAGMA and dispatch to cuSOLVER uncontionally [MAGMA][CUDA] eig: deprecate MAGMA and dispatch to cuSOLVER unconditionally Jan 27, 2026
[ghstack-poisoned]
@Skylion007

Skylion007 commented Jan 30, 2026 •

Copy link
Copy Markdown
Collaborator

void _warn_once_magma_deprecation(const std::string& op_name, bool force_cusolver = true) {
if (at::globalContext().linalgPreferredBackend() == at::LinalgBackend::Magma) {
std::string warn_force_cusolver = force_cusolver
? " " + op_name + " will try dispatching to cuSOLVER instead. " +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider fmtlib::fmt would be cleaner

@Skylion007 Skylion007 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NVM, ROCM is missing this cusolver symbols for now for xgeev. Still check that table for other PRs though!

[ghstack-poisoned]
@nikitaved

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

nikitaved added a commit that referenced this pull request Feb 6, 2026
nikitaved added a commit that referenced this pull request Feb 6, 2026
…onally (if xgeev is available)

ghstack-source-id: a612a70
Pull-Request: #173510
[ghstack-poisoned]
nikitaved added a commit that referenced this pull request Feb 9, 2026
…onally (if xgeev is available)

ghstack-source-id: cc95adc
Pull-Request: #173510
[ghstack-poisoned]
nikitaved added a commit that referenced this pull request Feb 13, 2026
…onally (if xgeev is available)

ghstack-source-id: 1de5909
Pull-Request: #173510
[ghstack-poisoned]
[ghstack-poisoned]
nikitaved added a commit that referenced this pull request Feb 17, 2026
…onally (if xgeev is available)

ghstack-source-id: 249c609
Pull-Request: #173510
@nikitaved

Copy link
Copy Markdown
Collaborator Author

CUDA 12.6 is cleared.

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

radeksm pushed a commit to radeksm/pytorch that referenced this pull request Feb 20, 2026
…onally (pytorch#173510)

As per title.

Benchmark script:

```python
import torch
import torch.utils.benchmark as benchmark

from itertools import product

results = []

batches = [(), (16,), (64,)]
sizes = [16, 128, 512,  2048]

for b, n in product(batches, sizes):
    shape = b + (n, n)
    print(f"Testing shape={shape}")
    label = "torch.eig"
    sub_label = f"{shape}"
    x = torch.rand(*shape, device="cuda")
    x = x + x.mH
    stmt = "torch.linalg.eig(x)"
    for backend in ("magma", "cusolver"):
        torch.backends.cuda.preferred_linalg_library(backend)
        # warm-up
        for _ in range(5):
            exec(stmt)

        results.append(benchmark.Timer(
            stmt=stmt,
            globals={'x': x},
            label=label,
            sub_label=sub_label,
            description=backend,
        ).blocked_autorange(min_run_time=1))

compare = benchmark.Compare(results)
compare.print()
```

Benchmark results (H100):
```
[-------------------- torch.eig -------------------]
                        |     magma     |   cusolver  | cusolver speedup
1 threads: ------------------------------------------
      (16, 16)          |      67215.3  |       893.3 | 75.24
      (128, 128)        |     390101.4  |     10526.9 | 37.05
      (512, 512)        |    1614706.1  |     61347.5 | 26.32
      (2048, 2048)      |    6447301.5  |    356181.2 | 18.10
      (16, 16, 16)      |     660036.1  |     13095.2 | 50.40
      (16, 128, 128)    |    6530718.7  |    166647.0 | 39.18
      (16, 512, 512)    |   20375827.4  |    994115.1 | 20.49
      (16, 2048, 2048)  |   98335490.6  |   5717112.5 | 17.20
      (64, 16, 16)      |    2167358.2  |     51977.5 | 41.69
      (64, 128, 128)    |   25925259.8  |    664574.7 | 39.01
      (64, 512, 512)    |   84731703.1  |   3946917.0 | 21.46
      (64, 2048, 2048)  |  380878661.3  |  23008593.5 | 16.55

Times are in microseconds (us).
```

Pull Request resolved: pytorch#173510
Approved by: https://github.com/Skylion007
radeksm pushed a commit to radeksm/pytorch that referenced this pull request Feb 20, 2026
…nally (pytorch#173515)

Benchmarks:
```
[--------------- torch.cholesky --------------]
                        |   magma   |  cusolver
1 threads: ------------------------------------
      (16, 16)          |     42.8  |     34.8
      (128, 128)        |    129.7  |    108.6
      (512, 512)        |    747.0  |    376.1
      (2048, 2048)      |  22492.2  |   1954.3
      (16, 16, 16)      |     53.9  |     46.1
      (16, 128, 128)    |    197.3  |    157.7
      (16, 512, 512)    |   1471.7  |    834.9
      (16, 2048, 2048)  |  19921.6  |  10598.4
      (64, 16, 16)      |     54.3  |     46.1
      (64, 128, 128)    |    224.8  |    174.5
      (64, 512, 512)    |   1964.2  |   1261.4
      (64, 2048, 2048)  |  40397.3  |  22181.2

Times are in microseconds (us).

```

Pull Request resolved: pytorch#173515
Approved by: https://github.com/eqy
ghstack dependencies: pytorch#173510
radeksm pushed a commit to radeksm/pytorch that referenced this pull request Feb 20, 2026
…ytorch#173788)

Benchmarks on H100:
```
[--------------- torch.linalg.qr ---------------]
                        |    magma    |  cusolver
1 threads: --------------------------------------
      (16, 4)           |     3003.1  |      53.2
      (4, 16)           |     2985.2  |      77.5
      (16, 16)          |     2635.1  |      60.0
      (128, 32)         |     3004.9  |     189.0
      (32, 128)         |     3107.8  |     135.5
      (128, 128)        |     3688.3  |     611.5
      (512, 128)        |     3862.1  |     457.9
      (128, 512)        |     3645.4  |     669.3
      (512, 512)        |     4815.7  |    1852.4
      (2048, 512)       |     8958.8  |    2949.9
      (512, 2048)       |     5812.5  |    2540.7
      (2048, 2048)      |    20102.2  |   10749.8
      (16, 16, 4)       |    41537.3  |     422.7
      (16, 4, 16)       |    40861.3  |     429.3
      (16, 16, 16)      |    40989.7  |     487.0
      (16, 128, 32)     |    41950.1  |    1143.4
      (16, 32, 128)     |    42032.6  |    2403.0
      (16, 128, 128)    |    46964.5  |    8055.1
      (16, 512, 128)    |    49646.0  |    7125.4
      (16, 128, 512)    |    53973.8  |   49707.0
      (16, 512, 512)    |    75648.4  |   29472.2
      (16, 2048, 512)   |   141360.8  |   47124.6
      (16, 512, 2048)   |    88497.4  |   40474.3
      (16, 2048, 2048)  |   317109.9  |  172659.4
      (64, 16, 4)       |   184853.8  |    1537.2
      (64, 4, 16)       |   183240.0  |    1550.7
      (64, 16, 16)      |   176180.4  |    1722.3
      (64, 128, 32)     |   183096.8  |    3174.2
      (64, 32, 128)     |   171972.2  |    4400.2
      (64, 128, 128)    |   202024.5  |   10570.3
      (64, 512, 128)    |   201352.3  |   28660.5
      (64, 128, 512)    |   279550.8  |   52554.2
      (64, 512, 512)    |   359514.5  |  118561.6
      (64, 2048, 512)   |   598059.6  |  189165.5
      (64, 512, 2048)   |   353265.6  |  162186.6
      (64, 2048, 2048)  |  1334670.0  |  690921.4

Times are in microseconds (us).
```

Pull Request resolved: pytorch#173788
Approved by: https://github.com/eqy
ghstack dependencies: pytorch#173510, pytorch#173515
libohao1201 pushed a commit to libohao1201/pytorch that referenced this pull request Mar 2, 2026
…onally (pytorch#173510)

As per title.

Benchmark script:

```python
import torch
import torch.utils.benchmark as benchmark

from itertools import product

results = []

batches = [(), (16,), (64,)]
sizes = [16, 128, 512,  2048]

for b, n in product(batches, sizes):
    shape = b + (n, n)
    print(f"Testing shape={shape}")
    label = "torch.eig"
    sub_label = f"{shape}"
    x = torch.rand(*shape, device="cuda")
    x = x + x.mH
    stmt = "torch.linalg.eig(x)"
    for backend in ("magma", "cusolver"):
        torch.backends.cuda.preferred_linalg_library(backend)
        # warm-up
        for _ in range(5):
            exec(stmt)

        results.append(benchmark.Timer(
            stmt=stmt,
            globals={'x': x},
            label=label,
            sub_label=sub_label,
            description=backend,
        ).blocked_autorange(min_run_time=1))

compare = benchmark.Compare(results)
compare.print()
```

Benchmark results (H100):
```
[-------------------- torch.eig -------------------]
                        |     magma     |   cusolver  | cusolver speedup
1 threads: ------------------------------------------
      (16, 16)          |      67215.3  |       893.3 | 75.24
      (128, 128)        |     390101.4  |     10526.9 | 37.05
      (512, 512)        |    1614706.1  |     61347.5 | 26.32
      (2048, 2048)      |    6447301.5  |    356181.2 | 18.10
      (16, 16, 16)      |     660036.1  |     13095.2 | 50.40
      (16, 128, 128)    |    6530718.7  |    166647.0 | 39.18
      (16, 512, 512)    |   20375827.4  |    994115.1 | 20.49
      (16, 2048, 2048)  |   98335490.6  |   5717112.5 | 17.20
      (64, 16, 16)      |    2167358.2  |     51977.5 | 41.69
      (64, 128, 128)    |   25925259.8  |    664574.7 | 39.01
      (64, 512, 512)    |   84731703.1  |   3946917.0 | 21.46
      (64, 2048, 2048)  |  380878661.3  |  23008593.5 | 16.55

Times are in microseconds (us).
```

Pull Request resolved: pytorch#173510
Approved by: https://github.com/Skylion007
libohao1201 pushed a commit to libohao1201/pytorch that referenced this pull request Mar 2, 2026
…nally (pytorch#173515)

Benchmarks:
```
[--------------- torch.cholesky --------------]
                        |   magma   |  cusolver
1 threads: ------------------------------------
      (16, 16)          |     42.8  |     34.8
      (128, 128)        |    129.7  |    108.6
      (512, 512)        |    747.0  |    376.1
      (2048, 2048)      |  22492.2  |   1954.3
      (16, 16, 16)      |     53.9  |     46.1
      (16, 128, 128)    |    197.3  |    157.7
      (16, 512, 512)    |   1471.7  |    834.9
      (16, 2048, 2048)  |  19921.6  |  10598.4
      (64, 16, 16)      |     54.3  |     46.1
      (64, 128, 128)    |    224.8  |    174.5
      (64, 512, 512)    |   1964.2  |   1261.4
      (64, 2048, 2048)  |  40397.3  |  22181.2

Times are in microseconds (us).

```

Pull Request resolved: pytorch#173515
Approved by: https://github.com/eqy
ghstack dependencies: pytorch#173510
libohao1201 pushed a commit to libohao1201/pytorch that referenced this pull request Mar 2, 2026
…ytorch#173788)

Benchmarks on H100:
```
[--------------- torch.linalg.qr ---------------]
                        |    magma    |  cusolver
1 threads: --------------------------------------
      (16, 4)           |     3003.1  |      53.2
      (4, 16)           |     2985.2  |      77.5
      (16, 16)          |     2635.1  |      60.0
      (128, 32)         |     3004.9  |     189.0
      (32, 128)         |     3107.8  |     135.5
      (128, 128)        |     3688.3  |     611.5
      (512, 128)        |     3862.1  |     457.9
      (128, 512)        |     3645.4  |     669.3
      (512, 512)        |     4815.7  |    1852.4
      (2048, 512)       |     8958.8  |    2949.9
      (512, 2048)       |     5812.5  |    2540.7
      (2048, 2048)      |    20102.2  |   10749.8
      (16, 16, 4)       |    41537.3  |     422.7
      (16, 4, 16)       |    40861.3  |     429.3
      (16, 16, 16)      |    40989.7  |     487.0
      (16, 128, 32)     |    41950.1  |    1143.4
      (16, 32, 128)     |    42032.6  |    2403.0
      (16, 128, 128)    |    46964.5  |    8055.1
      (16, 512, 128)    |    49646.0  |    7125.4
      (16, 128, 512)    |    53973.8  |   49707.0
      (16, 512, 512)    |    75648.4  |   29472.2
      (16, 2048, 512)   |   141360.8  |   47124.6
      (16, 512, 2048)   |    88497.4  |   40474.3
      (16, 2048, 2048)  |   317109.9  |  172659.4
      (64, 16, 4)       |   184853.8  |    1537.2
      (64, 4, 16)       |   183240.0  |    1550.7
      (64, 16, 16)      |   176180.4  |    1722.3
      (64, 128, 32)     |   183096.8  |    3174.2
      (64, 32, 128)     |   171972.2  |    4400.2
      (64, 128, 128)    |   202024.5  |   10570.3
      (64, 512, 128)    |   201352.3  |   28660.5
      (64, 128, 512)    |   279550.8  |   52554.2
      (64, 512, 512)    |   359514.5  |  118561.6
      (64, 2048, 512)   |   598059.6  |  189165.5
      (64, 512, 2048)   |   353265.6  |  162186.6
      (64, 2048, 2048)  |  1334670.0  |  690921.4

Times are in microseconds (us).
```

Pull Request resolved: pytorch#173788
Approved by: https://github.com/eqy
ghstack dependencies: pytorch#173510, pytorch#173515
sandy-gags pushed a commit to sandy-gags/pytorch that referenced this pull request Mar 12, 2026
@github-actions
github-actions Bot deleted the gh/nikitaved/26/head branch March 20, 2026 02:22
EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
…onally (pytorch#173510)

As per title.

Benchmark script:

```python
import torch
import torch.utils.benchmark as benchmark

from itertools import product

results = []

batches = [(), (16,), (64,)]
sizes = [16, 128, 512,  2048]

for b, n in product(batches, sizes):
    shape = b + (n, n)
    print(f"Testing shape={shape}")
    label = "torch.eig"
    sub_label = f"{shape}"
    x = torch.rand(*shape, device="cuda")
    x = x + x.mH
    stmt = "torch.linalg.eig(x)"
    for backend in ("magma", "cusolver"):
        torch.backends.cuda.preferred_linalg_library(backend)
        # warm-up
        for _ in range(5):
            exec(stmt)

        results.append(benchmark.Timer(
            stmt=stmt,
            globals={'x': x},
            label=label,
            sub_label=sub_label,
            description=backend,
        ).blocked_autorange(min_run_time=1))

compare = benchmark.Compare(results)
compare.print()
```

Benchmark results (H100):
```
[-------------------- torch.eig -------------------]
                        |     magma     |   cusolver  | cusolver speedup
1 threads: ------------------------------------------
      (16, 16)          |      67215.3  |       893.3 | 75.24
      (128, 128)        |     390101.4  |     10526.9 | 37.05
      (512, 512)        |    1614706.1  |     61347.5 | 26.32
      (2048, 2048)      |    6447301.5  |    356181.2 | 18.10
      (16, 16, 16)      |     660036.1  |     13095.2 | 50.40
      (16, 128, 128)    |    6530718.7  |    166647.0 | 39.18
      (16, 512, 512)    |   20375827.4  |    994115.1 | 20.49
      (16, 2048, 2048)  |   98335490.6  |   5717112.5 | 17.20
      (64, 16, 16)      |    2167358.2  |     51977.5 | 41.69
      (64, 128, 128)    |   25925259.8  |    664574.7 | 39.01
      (64, 512, 512)    |   84731703.1  |   3946917.0 | 21.46
      (64, 2048, 2048)  |  380878661.3  |  23008593.5 | 16.55

Times are in microseconds (us).
```

Pull Request resolved: pytorch#173510
Approved by: https://github.com/Skylion007, https://github.com/ngimel
akashveramd pushed a commit to akashveramd/pytorch that referenced this pull request Jul 21, 2026
…pSOLVER, test_linalg_solve/triangular_solve via cuBLAS

test/test_linalg.py:
- Removed all @skipCUDAIf(TEST_WITH_ROCM and not torch.cuda.has_magma, ...) decorators
  from eig tests (PR's intended change)
- Removed @skipCUDAIfRocm from ldl_solve test; added ROCm >= 7.14 skipCUDAIf guard
- Restored test_eig_check_magma (removed upstream by pytorch#173510, not by this PR)
- Import: kept skipCUDAIfNoMagmaAndNoCusolver (still used by other 2.11 tests)

BatchLinearAlgebra.cpp:
- Added #if guard around apply_magma_eig + linalg_eig_magma
- Restored TORCH_INTERNAL_ASSERT_DEBUG_ONLY(input.is_cuda()) in linalg_eig_kernel
- Widened #if condition to include (USE_ROCM && ROCM_VERSION >= 71400)
- Replaced _warn_once_magma_deprecation with upstream verbatim implementation

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

Labels

ci-no-td Do not run TD on this PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/trunk Trigger trunk jobs on your pull request Merged module: cuda Related to torch.cuda, and CUDA support in general open source release notes: linalg_frontend release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants