Robust PCA does not work on GPU with PyTorch as a backend

Hello there,
I tried a library called tensorly to use one of its functions Robust PCA. It works fine when using it on CPU it does not work on GPU with PyTorch as a backend with tensorly-0.7.0 and PyTorch 1.11.0+cu113 I also tried tensorly-0.7.0 and pytorch 1.7+cu102

Here is my CODE

pip install tensorly
print(torch.__version__)
import torch
import tensorly as tl

tl.set_backend('pytorch')
cuda = torch.device('cuda')
fake_data = torch.randn(2500, 9000, device=cuda)
low_rank_part, sparse_part = tl.decomposition.robust_pca(fake_data, reg_E=0.04, learning_rate=1.2, n_iter_max=20)

and the error


/usr/local/lib/python3.7/dist-packages/tensorly/backend/core.py:1106: UserWarning: In partial_svd: converting to NumPy. Check SVD_FUNS for available alternatives if you want to avoid this.
  warnings.warn('In partial_svd: converting to NumPy.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-7-e31773fb0320>](https://localhost:8080/#) in <module>()
      1 cuda = torch.device('cuda')
      2 fake_data = torch.randn(2500, 9000, device=cuda)
----> 3 low_rank_part, sparse_part = tl.decomposition.robust_pca(fake_data, reg_E=0.04, learning_rate=1.2, n_iter_max=20)

3 frames
<__array_function__ internals> in amax(*args, **kwargs)

[/usr/local/lib/python3.7/dist-packages/torch/_tensor.py](https://localhost:8080/#) in __array__(self, dtype)
    730             return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
    731         if dtype is None:
--> 732             return self.numpy()
    733         else:
    734             return self.numpy().astype(dtype, copy=False)

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Dependencies versions
Linux-5.4.188±x86_64-with-Ubuntu-18.04-bionic
Python 3.7.13 (default, Apr 24 2022, 01:04:09)
[GCC 7.5.0]
NumPy 1.21.6
SciPy 1.4.1
TensorLy 0.7.0
Pytorch 1.11.0+cu113

Apparently the method expects a CPUTensor, as internally .numpy() is called as given in the error message:

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

EDIT: also cross-post from here

1 Like