Skip to content

[rocm] Fix current torch.linalg.lstsq limitation in InverseMelScale module #3939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amd-sriram
Copy link

This PR fixes the following error:
RuntimeError: torch.linalg.lstsq: only overdetermined systems (input.size(-2) >= input.size(-1)) are allowed on CUDA. Please rebuild with cuSOLVER

Checking the pytorch code https://github.com/ROCm/pytorch/blob/main/aten/src/ATen/native/cuda/linalg/BatchLinearAlgebra.cpp, it calls magma. According to magma documentation, least squares method - magma_sgels_gpu supports only overdetermined systems https://icl.utk.edu/projectsfiles/magma/doxygen/group__magma__gels.html

The proposed temporary solution uses https://docs.pytorch.org/docs/stable/generated/torch.linalg.pinv.html as a replacement for linear least squares. This change can be reverted once torch.linalg.lstsq uses hipSolver for underconstrained systems.

Tested on rocm with
pytest test/torchaudio_unittest/transforms/transforms_cuda_test.py -k test_inverse_melscale

RuntimeError: torch.linalg.lstsq: only overdetermined systems (input.size(-2) >= input.size(-1)) are allowed on CUDA. Please rebuild with cuSOLVER

Checking the pytorch code aten/src/ATen/native/cuda/linalg/BatchLinearAlgebra.cpp, it calls magma. According to magma documentation, least squares method - magma_sgels_gpu does supports only overdetermined systems
https://icl.utk.edu/projectsfiles/magma/doxygen/group__magma__gels.html

The proposed temporary solution uses https://docs.pytorch.org/docs/stable/generated/torch.linalg.pinv.html as a replacement for linear least squares. This change can be reverted once torch.linalg.lstsq uses hipSolver for underconstrained systems.

Tested on rocm with pytest test/torchaudio_unittest/transforms/transforms_cuda_test.py -k test_inverse_melscale
Copy link

pytorch-bot bot commented Jun 13, 2025

🔗 Helpful Links

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants