Error in a Simple gather call


I was using the below code and it worked with pytorch 0.4.1.

Suddenly, with the new Pytorch installation it is giving error. I have a large codebase and don’t want to change APIs. Any quick way to solve this? Thank you for your help.

logpt = logpt.gather(1, target)

RuntimeError: Invalid index in gather at /opt/conda/conda-bld/pytorch_1549628766161/work/aten/src/TH/generic/THTensorEvenMoreMath.cpp:457

Could you post the shape of logpt and the min and max values of target?
If the index is wrong it should also be caught in 0.4.1. I’m wondering if the creation of target changed in some way.

thanks @ptrblck for the reply. the target shape is: torch.Size([1340, 1])

and log pt shape is:
torch.Size([1340, 300])

The shapes should fit, but could you also print the min and max values of target, which seem to create the issue?

the min and max values (using torch.min(), max()) are: tensor(1) tensor(9852)

Thanks for the information. The max value should be 299 and is apparently a bit higher.
Could you check how target was calculated and see where this high value comes from?