Did torch.gather change in new pytorch version?

Before I upgraded to the latest pytorch, this command worked for me:

ss = pp.gather(1, labels)

where pp is:

Variable containing:
 0.0651  0.9349
 0.6208  0.3792
 0.3024  0.6976
 0.2226  0.7774
 0.0394  0.9606
 0.4197  0.5803
 0.1205  0.8795
 0.3774  0.6226
 0.1682  0.8318
 0.2281  0.7719
 0.3845  0.6155
 0.4658  0.5342
 0.4982  0.5018
 0.2653  0.7347
 0.2694  0.7306
 0.6550  0.3450
[torch.cuda.FloatTensor of size 16x2 (GPU 0)]

and where labels

Variable containing:
 1
 1
 1
 1
 1
 1
 1
 1
 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.LongTensor of size 16 (GPU 0)]

However after I upgraded to the latest version off of master, this same line gives me the following error:

*** RuntimeError: Input tensor must have same dimensions as output tensor at /data/pytorch/torch/lib/THC/generic/THCTensorScatterGather.cu:16

I’m not sure how/why this error occurs now, and in fact it does not even make sense to me, I do not see why/what sizes need to be the same here.
Thanks

2 Likes

The answer, is that labels needs to be reshaped, into an explicit 16x1 vector, from the 16 it is at. Therefore, doing labels.view(-1,1) will make it work.

2 Likes

Hi guys,
did someone encounter the same problem after upgrading to ver 0.2?
I try to do view(-1,1) but had no luck…
got the following error message :

RuntimeError: Index tensor must have same dimensions as input tensor at /home/jdily/Desktop/project/lib/pytorch/torch/lib/THC/generic/THCTensorScatterGather.cu:111

And there is no error when running under cpu mode.

thx!

@jdily please see the release notes, especially the section called “Important Breakages and Workarounds”.

Maybe you are affected by this.

1 Like