Sorry for the bump. I’m hitting this problem again. But I’m running into this issue again. I don’t understand what’s going wrong. The dimensions appear correct.
>>> import torch
>>> cd = [[1, 0]]
>>> gd = [0.39613232016563416]
>>> i = torch.LongTensor(cd)
>>> v = torch.FloatTensor(gd)
>>> p = torch.rand(2)
>>> i

 1  0
[torch.LongTensor of size 1x2]

>>> v

 0.3961
[torch.FloatTensor of size 1]

>>> p

 0.4678
 0.0996
[torch.FloatTensor of size 2]

>>> grads = torch.sparse.FloatTensor(i.t(), v, torch.Size(list(p.size()))).to_dense()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: invalid argument 2: number of dimensions must be nDimI + nDimV at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/THS/generic/THSTensor.c:169