tensorly icon indicating copy to clipboard operation
tensorly copied to clipboard

Support TT decomposition using CUDA backend

Open JeremieMelo opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe.

When performing decomposition, e.g., tensor_train using pytorch backend, it by default uses scipy.linalg.svd, which is very slow especially when the input tensor is on CUDA.

Describe the solution you'd like

Consider using torch.linalg.svd for fast decomposition for CUDA Tensors

Describe alternatives you've considered

Additional context

JeremieMelo avatar Jun 09 '22 19:06 JeremieMelo

Hi @JeremieMelo, So this is kind of tricky. Tensorly is using scipy.sparse.linalg.eigsh and some post-processing to compute a "small" SVD, that is a SVD where only a few singular values/singular vectors are required. We could use a full SVD and truncate it but @JeanKossaifi wanted to avoid this option for speed/memory reasons. The problem is that as far as I know, only scipy.sparse has an implementation of eigsh (which itself calls LAPACK if I remember correctly). And scipy needs numpy arrays, thus the factors are recast as numpy arrays in partial_svd which is called in e.g. Tucker decomposition or Tensor Train decomposition.

However in your case, using full SVD and then truncating it could be faster, since you could use the backend's SVD and not recast the factors as numpy arrays, avoiding to break GPU support. You can tinker with this by modifying the partial_svd function in tensorly.backend.core.py.

cohenjer avatar Jun 13 '22 15:06 cohenjer

@JeremieMelo @cohenjer we already have full GPU support - just pass for instance svd= 'truncated_svd' instead of 'numppy_svd'. You can check available functions by printing tensorly.SVD_FUNS. In particular you can also use, for PyTorch, symeig_svd and randomized_svd, it's in the doc and docstring: https://github.com/tensorly/tensorly/blob/8ecfd6e1dfbdfdde1cc6a3160863cd42b10cfb78/tensorly/decomposition/_cp.py#L215

As @cohenjer mentioned numpy_svd uses an efficient sparse SVD that is CPU only. We could consider changing the default if pytorch's SVD is more efficient than it used to be.

JeanKossaifi avatar Jun 13 '22 18:06 JeanKossaifi

Hey @JeanKossaifi I think there is still an issue with Tensor Train decomposition. In tensorly.decomposition._tt.py, partial_svd is used not svd, and there is no option to change default SVD like you are suggesting. I thought this was intended, but right now I do think we have no GPU support for the TT decomposition?

JeremieMelo's comment was not about CP or Tucker (which are fine) but about only tensor train :)

cohenjer avatar Jun 14 '22 06:06 cohenjer

I am reopening the issue since TT decomposition does not have GPU support. I update the Issue title to better match the content.

cohenjer avatar Jul 04 '22 09:07 cohenjer

Indeed, this is an oversight, we should always support other SVDs. Thanks for reopening @cohenjer.

JeanKossaifi avatar Jul 15 '22 18:07 JeanKossaifi

Fixed in #453.

JeanKossaifi avatar Oct 31 '22 00:10 JeanKossaifi