Repository: pytorch
Issue: pca_lowrank and svd_lowrank broken under automatic mixed precision.
Labels: module: cuda,triaged,module: half,module: linear algebra,module: amp (automated mixed precision)

### 🐛 Describe the bug

`torch.pca_lowrank` and `torch.svd_lowrank` does not work with automatic mixed precision, even if the inputs are 32 bit.

```python
import torch

x = torch.rand(1000, 3, device="cuda")
with torch.cuda.amp.autocast(True):
    assert x.dtype is torch.float32
    torch.pca_lowrank(x)
```

Trace:

```
Traceback (most recent call last):
  File "/home/pbsds/ntnu/ifield/tmp/pca-repro.py", line 6, in <module>
    torch.pca_lowrank(x)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/ifield-P6Ko3Gy1-py3.10/lib/python3.10/site-packages/torch/_lowrank.py", line 299, in pca_lowrank
    return _svd_lowrank(A - C, q, niter=niter, M=None)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/ifield-P6Ko3Gy1-py3.10/lib/python3.10/site-packages/torch/_lowrank.py", line 174, in _svd_lowrank
    Q = get_approximate_basis(A, q, niter=niter, M=M)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/ifield-P6Ko3Gy1-py3.10/lib/python3.10/site-packages/torch/_lowrank.py", line 70, in get_approximate_basis
    Q = torch.linalg.qr(matmul(A, R)).Q
RuntimeError: "geqrf_cuda" not implemented for 'Half'
```

Likely the `matmul` in `get_approximate_basis` in `_lowrank.py` downcasts to float16, which is not supported in `torch.linalg.qr`.



### Versions

Collecting environment information...
PyTorch version: 1.13.1+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Manjaro Linux (x86_64)
GCC version: (GCC) 11.3.0
Clang version: 15.0.7
CMake version: version 3.25.2
Libc version: glibc-2.37

Python version: 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-5.15.102-1-MANJARO-x86_64-with-glibc2.37
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3070 Laptop GPU
Nvidia driver version: 525.89.02
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   39 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          16
On-line CPU(s) list:             0-15
Vendor ID:                       GenuineIntel
Model name:                      11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
CPU family:                      6
Model:                           141
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
Stepping:                        1
CPU(s) scaling MHz:              79%
CPU max MHz:                     4600,0000
CPU min MHz:                     800,0000
BogoMIPS:                        4609,00
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       384 KiB (8 instances)
L1i cache:                       256 KiB (8 instances)
L2 cache:                        10 MiB (8 instances)
L3 cache:                        24 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-15
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Vulnerable: eIBRS with unprivileged eBPF
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] numpy==1.23.3
[pip3] pytorch-lightning==1.9.4
[pip3] pytorch3d==0.7.2
[pip3] torch==1.13.1
[pip3] torchmeta==1.8.0
[pip3] torchmetrics==0.11.4
[pip3] torchvision==0.14.1
[pip3] torchviz==0.0.2
[conda] No relevant packages

cc @ngimel @jianyuh @nikitaved @pearu @mruberry @walterddr @IvanYashchuk @xwang233 @Lezcano @mcarilli @ptrblck @leslie-fang-intel @jgong5