RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'weight'

Can you run, before you enter the training loop:

net = net.float()

It will transform the model parameters to float.

And then in your training loop:

z = net(x.float())

That should proceed without error.

PS: replace .float() by .double() if you wish to have network + data in double precision format.

36 Likes