Skip to content
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

Einsum? #248

Closed
justanhduc opened this issue Jul 2, 2022 · 8 comments
Closed

Einsum? #248

justanhduc opened this issue Jul 2, 2022 · 8 comments

Comments

@justanhduc
Copy link

Hey @rusty1s. Thanks for maintaining this great library. I am wondering if it is possible to support einsum for sparse matrix and tensor multiplication. Is there any difficulty? Thanks in advance!

@rusty1s
Copy link
Owner

rusty1s commented Jul 7, 2022

We do not have any plans to integrate einsum support into torch-sparse. Which operation do you try to perform? Eventually, you might be able to do so with the tools already provided in torch-sparse.

@justanhduc
Copy link
Author

My use case is that I wanna dot a sparse matrix m x n with another tensor b x n x d. With the current machinery I have to do a lot of transpose/untranspose/flatten/contiguous etc... Do you have any idea how to avoid all these?

@rusty1s
Copy link
Owner

rusty1s commented Jul 9, 2022

This should be already supported in torch-sparse:

from torch_sparse import SparseTensor
sparse_mat = SparseTensor(row=row, col=col, sparse_sizes(m, n))
dense_mat = torch.randn(b, n, d)
out = sparse_mat @ dense_mat  # b x m x d

@justanhduc
Copy link
Author

Ok I missed it. Perhaps you may want to make it more visible in the readme. Anw thanks a lot!

@yonatansverdlov
Copy link

This should be already supported in torch-sparse:

from torch_sparse import SparseTensor
sparse_mat = SparseTensor(row=row, col=col, sparse_sizes(m, n))
dense_mat = torch.randn(b, n, d)
out = sparse_mat @ dense_mat  # b x m x d

If I have a tensor ten1 of shape [b,n,dim,i] which is sparse, and tne2 tensor of shape [i,m] and I want to output ten1@ten2, how can I use what you did here?

@rusty1s
Copy link
Owner

rusty1s commented Jan 31, 2024

This wouldn't be supported since sparse matrix multiplication cannot handle 4-dimensional tensors (needs to be 2 dimensions). Your best option is to reshape ten1 into [b * n * dim, i].

@yonatansverdlov
Copy link

Why not?
Will it be supported in the future?
Do you know something that helps with sparse tensor multiplication?

@rusty1s
Copy link
Owner

rusty1s commented Feb 2, 2024

Likely not, SparseTensor is designed to have at most two sparse dimensions (while any other dimension afterwards can be dense).

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

No branches or pull requests

3 participants