Can't Construct Sparse Tensor with cuda.Tensor


(Yinbo Chen) #1

Hi there,

I am writing autograd for sparse tensor.

Why it gets Error when I construct torch.sparse.FloatTensor(i, v, size), that i,v are cuda.Tensor? Is it necessary to transform to cpu every time?

Thanks


(Thomas V) #2

You can use torch.cuda.sparse.FloatTensor:

i = torch.LongTensor([[0, 1, 1],
                          [2, 0, 2]]).cuda()
v = torch.FloatTensor([3, 4, 5]).cuda()
torch.cuda.sparse.FloatTensor(i,v, torch.Size([2,3]))

Best regards

Thomas


(Yinbo Chen) #3

Yeah it works. Thank you!


(Chaofei Hong) #4

But doesn’t this mean I need to rewrite the code to change from cpu to gpu platform?