PyTorch torch.set_default_dtype function
PyTorch torch reference manual
torch.set_default_dtype is a function in PyTorch used to set the default floating-point data type.
Function definition
torch.set_default_dtype(d)
Usage examples
Example
import
torch
Set the default dtype to float64
torch.
set_default_dtype
(
torch.
float64
)
Create a tensor, using float64 by default
x
=
torch.
tensor
(
[
1.0
,
2.0
,
3.0
]
)
(
"Default dtype:"
,
x.
dtype
)
Restore the default
torch.
set_default_dtype
(
torch.
float32
)