Skip to content

[XPU] Register _spsolve for SparseCsrXPU backend - #189372

Closed
pponikox wants to merge 1 commit into
pytorch:mainfrom
pponikox:spsolve_support_xpu
Closed

pponikox wants to merge 1 commit into
pytorch:mainfrom
pponikox:spsolve_support_xpu

Conversation

@pponikox

@pponikox pponikox commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Adds a SparseCsrXPU dispatch entry for aten::_spsolve in native_functions.yaml, mapping it to _sparse_csr_linear_solve_xpu, which is implemented in third_party/torch-xpu-ops. This enables torch.sparse.spsolve on XPU, alongside the existing SparseCsrCUDA backend.

Related XPU PR

The kernel implementation live in intel/torch-xpu-ops#4286.
Its tests are present in intel/torch-xpu-ops#5076.

Changes & Testing

See linked XPU PRs for more information

@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (4 Unrelated Failures)

As of commit a95c03c with merge base e7039c1 (image):

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

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

@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

Attention! native_functions.yaml was changed

If you are adding a new function or defaulted argument to native_functions.yaml, you cannot use it from pre-existing Python frontend code until our FC window passes (two weeks). Split your PR into two PRs, one which adds the new C++ functionality, and one that makes use of it from Python, and land them two weeks apart. See https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#forwards-compatibility-fc for more info.

@pponikox

pponikox commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: xpu"

@pytorch-bot pytorch-bot Bot added the release notes: xpu release notes category label Jul 9, 2026
torchxpubot pushed a commit to intel/torch-xpu-ops that referenced this pull request Aug 25, 2026
This patch fixes #4148 by implementing `torch.sparse.spsolve`
(`aten::_spsolve`) for the SparseCsrXPU backend. Input validation and
supported cases mirror the CUDA (cuDSS) backend: square A, 1-D b, and
left=true only (consistent with the documented torch.sparse.spsolve
API). left=False, non-1-D b, and size mismatches raise the same errors.

#### Summary

`_spsolve` solves a square linear system `A @ x = b` where `A` is a
sparse CSR matrix and `b` is a dense vector.
The CUDA backend uses NVIDIA's cuDSS direct sparse solver, which has no
equivalent on XPU. Following the existing pattern for sparse-CSR XPU ops
in the same file (triangular_solve, addmv, baddbmm, which all
materialize A.to_dense() and delegate to a dense op), the newly added
`_sparse_csr_linear_solve_xpu` performs an on-device dense solve via
`at::linalg_solve`.

**This PR requires the companion PyTorch change that registers the XPU
dispatch keys in `native_functions.yaml` which is done in:
pytorch/pytorch#189372

#### Testing
Due to the fact that any new tests for `_spsolve` would fail on XPU
build until registration PR
(pytorch/pytorch#189372) is merged, a decision
was made to move ALL new tests to a separate PR
(#5076) which will be merged
at the end (after this and registration PR). They were previously
checked and confirmed passing for XPU and skipping for CPU.
Thanks to that there should be no blockers nor build failures related to
adding `_spsolve` implementation.

@CuiYifeng CuiYifeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove the reminder about "DO NOT MERGE" from PR description since intel/torch-xpu-ops#4286 has been merged.

Comment thread third_party/xpu.txt Resolved
@pponikox

Copy link
Copy Markdown
Contributor Author

Please remove the reminder about "DO NOT MERGE" from PR description since intel/torch-xpu-ops#4286 has been merged.

Description updated.

@pponikox
pponikox requested a review from CuiYifeng August 26, 2026 14:55

@BBBela BBBela left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! 😉
But I would wait until the torch-xpu-ops pin update commit dfb0c18 is on viable/strict branch, then rebase onto viable/strict and then launch CI - to avoid main branch flakiness in CI.

zxd1997066 pushed a commit to intel/torch-xpu-ops that referenced this pull request Aug 28, 2026
This patch fixes #4148 by implementing `torch.sparse.spsolve`
(`aten::_spsolve`) for the SparseCsrXPU backend. Input validation and
supported cases mirror the CUDA (cuDSS) backend: square A, 1-D b, and
left=true only (consistent with the documented torch.sparse.spsolve
API). left=False, non-1-D b, and size mismatches raise the same errors.

#### Summary

`_spsolve` solves a square linear system `A @ x = b` where `A` is a
sparse CSR matrix and `b` is a dense vector.
The CUDA backend uses NVIDIA's cuDSS direct sparse solver, which has no
equivalent on XPU. Following the existing pattern for sparse-CSR XPU ops
in the same file (triangular_solve, addmv, baddbmm, which all
materialize A.to_dense() and delegate to a dense op), the newly added
`_sparse_csr_linear_solve_xpu` performs an on-device dense solve via
`at::linalg_solve`.

**This PR requires the companion PyTorch change that registers the XPU
dispatch keys in `native_functions.yaml` which is done in:
pytorch/pytorch#189372

#### Testing
Due to the fact that any new tests for `_spsolve` would fail on XPU
build until registration PR
(pytorch/pytorch#189372) is merged, a decision
was made to move ALL new tests to a separate PR
(#5076) which will be merged
at the end (after this and registration PR). They were previously
checked and confirmed passing for XPU and skipping for CPU.
Thanks to that there should be no blockers nor build failures related to
adding `_spsolve` implementation.
@pponikox

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorch-bot

pytorch-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

You don't have permissions to rebase this PR since you are a first time contributor. If you think this is a mistake, please contact PyTorch Dev Infra.

@BBBela

BBBela commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase --onto refs/remotes/origin/viable/strict 610343e5acab74781f4ac043633d32465f8a86e5 pull/189372/head returned non-zero exit code 1

Rebasing (1/5)
Rebasing (2/5)
Auto-merging third_party/xpu.txt
CONFLICT (content): Merge conflict in third_party/xpu.txt
error: could not apply 073835e8293... updated XPU commit SHA to point a version with implemented _spsolve for XPU backend
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 073835e8293... # updated XPU commit SHA to point a version with implemented _spsolve for XPU backend

Raised by https://github.com/pytorch/pytorch/actions/runs/33368135518

@pponikox
pponikox force-pushed the spsolve_support_xpu branch from c5c4ab5 to a95c03c Compare August 31, 2026 07:53
@pponikox

Copy link
Copy Markdown
Contributor Author

@guangyey could you take a look at this PR?
It registers the op which was implemented on the XPU side in intel/torch-xpu-ops#4286.

@chuanqi129 chuanqi129 added the ciflow/xpu Run XPU CI tasks label Aug 31, 2026
@pbielak
pbielak requested a review from guangyey August 31, 2026 09:42
@guangyey
guangyey marked this pull request as ready for review September 1, 2026 01:30
@guangyey guangyey added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 1, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@Skylion007

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • MPS (malfet, kurtamohler, jhavukainen)
  • Metamates (aditvenk, AmesingFlank, amirafzali, angelayi, anshul-si, ...)
  • Greenlight Review Bot (pytorchgreenlight)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@pponikox

pponikox commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@Skylion007 it seems that the merge failed due to missing approval.
Could you please approve the PR and then run the merge command?

@Skylion007

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
Adds a `SparseCsrXPU` dispatch entry for `aten::_spsolve` in `native_functions.yaml`, mapping it to `_sparse_csr_linear_solve_xpu`, which is implemented in third_party/torch-xpu-ops. This enables `torch.sparse.spsolve` on XPU, alongside the existing SparseCsrCUDA backend.

#### Related XPU PR

The kernel implementation live in intel/torch-xpu-ops#4286.
Its tests are present in intel/torch-xpu-ops#5076.

#### Changes & Testing

See linked XPU PRs for more information
Pull Request resolved: pytorch#189372
Approved by: https://github.com/BBBela, https://github.com/CuiYifeng, https://github.com/guangyey, https://github.com/Skylion007
torchxpubot pushed a commit to intel/torch-xpu-ops that referenced this pull request Sep 8, 2026
This patch fixes #4148 and is a continuation of
#4286.

**IMPORTANT:**
This PR should be merged **AFTER**:
* #4286 = implementation for
XPU backend
* pytorch/pytorch#189372 = registration for
SparseCsrXPU backend

It adds unit tests for newly implemented and registered _spsolve op:
* `test_spsolve_xpu`: identity, 1×1, dense-ish, larger, diagonal, and
tridiagonal sparsity patterns; residual check A @ x == b; correctness
vs. dense torch.linalg.solve on XPU and CPU; empty (0×0) system.
* `test_spsolve_xpu_errors`: left=False, non-1-D b, system-size
mismatch, singular matrix (LinAlgError).

```
python -m pytest third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py -k "spsolve_xpu and xpu_" -v
================================================================= test session starts ==================================================================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 -- /home/gta/venv2/bin/python
cachedir: .pytest_cache
hypothesis profile 'default'
rootdir: /home/gta/pytorch
configfile: pytest.ini
plugins: hypothesis-6.155.7
collected 9572 items / 9564 deselected / 8 selected                                                                                                    

third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_cpu_float32 SKIPPED (Only runs on xpu)             [ 12%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_cpu_float64 SKIPPED (Only runs on xpu)             [ 25%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_errors_cpu_float32 SKIPPED (Only runs on xpu)      [ 37%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_errors_cpu_float64 SKIPPED (Only runs on xpu)      [ 50%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_errors_xpu_float32 PASSED                          [ 62%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_errors_xpu_float64 PASSED                          [ 75%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_xpu_float32 PASSED                                 [ 87%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_xpu_float64 PASSED                                 [100%]

==================================================== 4 passed, 4 skipped, 9564 deselected in 4.59s =====================================================
```
minmingzhu pushed a commit to minmingzhu/torch-xpu-ops that referenced this pull request Sep 15, 2026
This patch fixes intel#4148 by implementing `torch.sparse.spsolve`
(`aten::_spsolve`) for the SparseCsrXPU backend. Input validation and
supported cases mirror the CUDA (cuDSS) backend: square A, 1-D b, and
left=true only (consistent with the documented torch.sparse.spsolve
API). left=False, non-1-D b, and size mismatches raise the same errors.

#### Summary

`_spsolve` solves a square linear system `A @ x = b` where `A` is a
sparse CSR matrix and `b` is a dense vector.
The CUDA backend uses NVIDIA's cuDSS direct sparse solver, which has no
equivalent on XPU. Following the existing pattern for sparse-CSR XPU ops
in the same file (triangular_solve, addmv, baddbmm, which all
materialize A.to_dense() and delegate to a dense op), the newly added
`_sparse_csr_linear_solve_xpu` performs an on-device dense solve via
`at::linalg_solve`.

**This PR requires the companion PyTorch change that registers the XPU
dispatch keys in `native_functions.yaml` which is done in:
pytorch/pytorch#189372

#### Testing
Due to the fact that any new tests for `_spsolve` would fail on XPU
build until registration PR
(pytorch/pytorch#189372) is merged, a decision
was made to move ALL new tests to a separate PR
(intel#5076) which will be merged
at the end (after this and registration PR). They were previously
checked and confirmed passing for XPU and skipping for CPU.
Thanks to that there should be no blockers nor build failures related to
adding `_spsolve` implementation.
orrangetabby17 pushed a commit to intel/torch-xpu-ops that referenced this pull request Oct 8, 2026
This patch fixes #4148 and is a continuation of
#4286.

**IMPORTANT:**
This PR should be merged **AFTER**:
* #4286 = implementation for
XPU backend
* pytorch/pytorch#189372 = registration for
SparseCsrXPU backend

It adds unit tests for newly implemented and registered _spsolve op:
* `test_spsolve_xpu`: identity, 1×1, dense-ish, larger, diagonal, and
tridiagonal sparsity patterns; residual check A @ x == b; correctness
vs. dense torch.linalg.solve on XPU and CPU; empty (0×0) system.
* `test_spsolve_xpu_errors`: left=False, non-1-D b, system-size
mismatch, singular matrix (LinAlgError).

```
python -m pytest third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py -k "spsolve_xpu and xpu_" -v
================================================================= test session starts ==================================================================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 -- /home/gta/venv2/bin/python
cachedir: .pytest_cache
hypothesis profile 'default'
rootdir: /home/gta/pytorch
configfile: pytest.ini
plugins: hypothesis-6.155.7
collected 9572 items / 9564 deselected / 8 selected                                                                                                    

third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_cpu_float32 SKIPPED (Only runs on xpu)             [ 12%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_cpu_float64 SKIPPED (Only runs on xpu)             [ 25%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_errors_cpu_float32 SKIPPED (Only runs on xpu)      [ 37%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRCPU::test_spsolve_xpu_errors_cpu_float64 SKIPPED (Only runs on xpu)      [ 50%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_errors_xpu_float32 PASSED                          [ 62%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_errors_xpu_float64 PASSED                          [ 75%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_xpu_float32 PASSED                                 [ 87%]
third_party/torch-xpu-ops/test/xpu/test_sparse_csr_xpu.py::TestSparseCSRXPU::test_spsolve_xpu_xpu_float64 PASSED                                 [100%]

==================================================== 4 passed, 4 skipped, 9564 deselected in 4.59s =====================================================
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged open source release notes: xpu release notes category

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

8 participants