Can the type of a gradient only be a floating type in new versions of Pytorch?

When I return a Long gradient, Pytorch 1.5 complains with this error that it should be a floating type. https://github.com/pytorch/pytorch/blob/54c05fa34e1fbbb5096746a8ae92e27a08116de4/torch/csrc/autograd/engine.cpp#L610

However when I cast this to float gradient in Pytorch 1.2, it complains that expected Long gradient but received float.

Has behavior changed over versions?

Hi,

Gradients for Long Tensors were never really supported. And were raising errors if used at random places.
We now unified this and properly raise an error when they are created (as you cannot use them anyway) so that the user can easily pinpoint the issue.

1 Like