RuntimeError: Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #2 ‘weight’

The default type for weights and biases are torch.FloatTensor. So, you’ll need to cast either your model to torch.DoubleTensor or cast your inputs to torch.FloatTensor. For casting your inputs you can do

X = X.float()

or cast your complete model to DoubleTensor as

model = model.double()

You can also set the default type for all tensors using

pytorch.set_default_tensor_type('torch.DoubleTensor')

It is better to convert your inputs to float rather than converting your model to double, because mathematical computations on double datatype is considerably slower on GPU.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)