mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Update device docs (#6887)
Tell users that one can substitute torch.device with a string
This commit is contained in:
parent
b5d2d285a8
commit
82a33c32aa
|
|
@ -71,6 +71,17 @@ Via a string and device ordinal:
|
||||||
>>> torch.device('cpu', 0)
|
>>> torch.device('cpu', 0)
|
||||||
device(type='cpu', index=0)
|
device(type='cpu', index=0)
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
The :class:`torch.device` argument in functions can generally be substituted with a string.
|
||||||
|
This allows for fast prototyping of code.
|
||||||
|
|
||||||
|
>>> # Example of a function that takes in a torch.device
|
||||||
|
>>> cuda1 = torch.device('cuda:1')
|
||||||
|
>>> torch.randn((2,3), device=cuda1)
|
||||||
|
|
||||||
|
>>> # You can substitute the torch.device with a string
|
||||||
|
>>> torch.randn((2,3), 'cuda:1')
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
For legacy reasons, a device can be constructed via a single device ordinal, which is treated
|
For legacy reasons, a device can be constructed via a single device ordinal, which is treated
|
||||||
as a cuda device. This matches :meth:`Tensor.get_device`, which returns an ordinal for cuda
|
as a cuda device. This matches :meth:`Tensor.get_device`, which returns an ordinal for cuda
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user