Skip to content
Advertisement

Pytorch getting RuntimeError: Found dtype Double but expected Float

I am trying to implement a neural net in PyTorch but it doesn’t seem to work. The problem seems to be in the training loop. I’ve spend several hours into this but can’t get it right. Please help, thanks.

I haven’t added the data preprocessing parts.

JavaScript
JavaScript
JavaScript
JavaScript

(tensor([ 5., 5., 8., 14.], dtype=torch.float64), tensor(-0.3403, dtype=torch.float64))

JavaScript
JavaScript
JavaScript
JavaScript
JavaScript

Error:

JavaScript

Advertisement

Answer

You need the data type of the data to match the data type of the model.

Either convert the model to double (recommended for simple nets with no serious performance problems such as yours)

JavaScript

or convert the data to float.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement