dtypes
default_dtype
¶
Context manager to temporarily change the default dtype of torch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype |
dtype
|
The dtype to temporarily set as the default. All dtypes supported by torch.set_default_dtype are valid. |
required |
Yields:
Type | Description |
---|---|
collections.abc.Generator[None]
|
None. |
Examples:
New tensors created within the context will have the new default dtype (unless explicitly overridden by the dtype
argument).
>>> torch.tensor([1.0]).dtype
torch.float32
>>> with default_dtype(torch.float64):
... torch.tensor([1.0]).dtype
torch.float64
The default dtype is restored after the context exits.