Repository navigation
Conversation
🔗 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 ( 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. |
Attention! native_functions.yaml was changedIf 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. |
|
@pytorchbot label "release notes: xpu" |
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
left a comment
There was a problem hiding this comment.
Please remove the reminder about "DO NOT MERGE" from PR description since intel/torch-xpu-ops#4286 has been merged.
Description updated. |
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.
|
@pytorchbot rebase |
|
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. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Rebase failed due to Command |
c5c4ab5 to
a95c03c
Compare
|
@guangyey could you take a look at this PR? |
|
|
|
@pytorchbot merge |
Merge failedReason: Approvers from one of the following sets are needed:
|
|
@Skylion007 it seems that the merge failed due to missing approval. |
|
@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 |
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
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 ===================================================== ```
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.
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 ===================================================== ```
Adds a
SparseCsrXPUdispatch entry foraten::_spsolveinnative_functions.yaml, mapping it to_sparse_csr_linear_solve_xpu, which is implemented in third_party/torch-xpu-ops. This enablestorch.sparse.spsolveon 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