I want all the floating numbers in my PyTorch code double type by default, how can I do that?
I want all the floating numbers in my PyTorch code double type by default, how can I do that?
You are looking for torch.set_default_tensor_type:
torch.set_default_tensor_type(torch.DoubleTensor)
Aletrnatively, you can use torch.set_default_dtype:
torch.set_default_dtype(torch.float64)
You should use for that torch.set_default_dtype.
It is true that using torch.set_default_tensor_type will also have a similar effect, but torch.set_default_tensor_type not only sets the default data type, but also sets the default values for the device where the tensor is allocated, and the layout of the tensor.