Repository: pytorch
Issue: [ARM] (Neoverse-V1) torch._C._LinAlgError: linalg.svd: The algorithm failed to converge because the input matrix contained non-finite values
Labels: module: tests,triaged,module: third_party,module: linear algebra,module: arm

### 🐛 Describe the bug

There are a couple of unit test failures on arm neoverse-v1 platforms ( NOTE - these are unit tests which are currently excluded from CI )

```
torch._C._LinAlgError: linalg.svd: The algorithm failed to converge because the input matrix contained non-finite values.
Exception raised from _linalg_check_errors at /var/lib/jenkins/workspace/aten/src/ATen/native/BatchLinearAlgebra.cpp:1598 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0xe0 (0xfea5b4cbf550 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libc10.so)
frame #1: at::native::_linalg_check_errors(at::Tensor const&, c10::basic_string_view<char>, bool) + 0x954 (0xfea5b5ec2268 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #2: at::_ops::_linalg_check_errors::call(at::Tensor const&, c10::basic_string_view<char>, bool) + 0x14c (0xfea5b6c45f2c in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #3: at::native::structured__linalg_svd_out::impl(at::Tensor const&, bool, bool, std::optional<c10::basic_string_view<char> >, at::Tensor const&, at::Tensor const&, at::Tensor const&) + 0x26c (0xfea5b5ec3a7c in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0x20d5f98 (0xfea5b6e15f98 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0x20d6118 (0xfea5b6e16118 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #6: at::_ops::_linalg_svd::redispatch(c10::DispatchKeySet, at::Tensor const&, bool, bool, std::optional<c10::basic_string_view<char> >) + 0xec (0xfea5b6d27f0c in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #7: <unknown function> + 0x4b016f8 (0xfea5b98416f8 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #8: <unknown function> + 0x4b01f10 (0xfea5b9841f10 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #9: at::_ops::_linalg_svd::call(at::Tensor const&, bool, bool, std::optional<c10::basic_string_view<char> >) + 0x198 (0xfea5b6d95658 in /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so)
frame #10: at::native::linalg_svd(at::Tensor const&, bool, std::optional<c10::basic_string_view<char> >) + 0x48 (0xfea5b5ebbdb8 in 

To execute this test, run the following from the base repo dir:
    python test/test_linalg.py TestLinalgCPU.test_pca_lowrank_cpu
This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
```

I have done some debugging and the error comes from `torch.linalg.qr` returning NaN values here
https://github.com/pytorch/pytorch/blob/d49f0bf466f2484e6dbf58e5fc89c4964da8fadb/torch/_lowrank.py#L78C9-L78C33

Further debugging reveals that lapackGeqrf call here is returning NaN values.

https://github.com/pytorch/pytorch/blob/65c2086d452ae6966ce9d7fb3cb2eef2fd0d2add/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp#L363

and finally, we have found that the problem is caused by libopenblas dgeqrf_ function. We have confirmed that there are no Nan values in libopenblas <= 0.3.20. So we have raised an issue openBLAS to addrress the regression since 0.3.21.

https://github.com/OpenMathLib/OpenBLAS/issues/5006

### Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (aarch64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.30.5
Libc version: glibc-2.35

Python version: 3.10.15 | packaged by conda-forge | (main, Oct 16 2024, 01:19:28) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-1019-aws-aarch64-with-glibc2.35
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture:                         aarch64
CPU op-mode(s):                       32-bit, 64-bit
Byte Order:                           Little Endian
CPU(s):                               48
On-line CPU(s) list:                  0-47
Vendor ID:                            ARM
Model:                                1
Thread(s) per core:                   1
Core(s) per cluster:                  48
Socket(s):                            -
Cluster(s):                           1
Stepping:                             r1p1
BogoMIPS:                             2100.00
Flags:                                fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm ssbs paca pacg dcpodp svei8mm svebf16 i8mm bf16 dgh rng
L1d cache:                            3 MiB (48 instances)
L1i cache:                            3 MiB (48 instances)
L2 cache:                             48 MiB (48 instances)
L3 cache:                             32 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-47
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; CSV2, BHB
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy==1.11.2
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.22.4
[pip3] onnx==1.17.0
[pip3] onnxscript==0.1.0.dev20240817
[pip3] optree==0.13.0
[pip3] torch==2.6.0a0+git6cc0edc
[conda] numpy                     1.22.4                   pypi_0    pypi
[conda] optree                    0.13.0                   pypi_0    pypi
[conda] torch                     2.6.0a0+git6cc0edc          pypi_0    pypi

cc @seemethere @malfet @pytorch/pytorch-dev-infra @mruberry @ZainRizvi @jianyuh @nikitaved @pearu @walterddr @xwang233 @Lezcano @snadampal @milpuz01