Can we do sparse x dense -> dense on GPU?

I tired to use torch.mm for a sparse matrix and a dense matrix, but got following error:

TypeError: Type torch.cuda.sparse.FloatTensor doesn't implement stateless method addmm

Is it possible to multiply a sparse matrix with a dense matrix on GPU ? Thanks!

I think you need the functions from the torch.sparse module.

Best regards

Thomas

Seems to work for me:

import torch
from torch.autograd import Variable
i = torch.LongTensor([[0, 1, 1],
                      [2, 0, 2]])
v = torch.FloatTensor([3, 4, 5])
x = torch.sparse.FloatTensor(i, v, torch.Size([2,3])).cuda()
y = x.to_dense().t()
torch.mm(x, y)

What version of pytorch are you using?

Sorry, I wasn’t being clear, my matrices are all variables.

Yikes. I’ve opened an issue for it here: https://github.com/pytorch/pytorch/issues/4887 .

Hoops, I guess I have to manually do back propagation then.