Update device docs (#6887)

Tell users that one can substitute torch.device with a string
This commit is contained in:
Richard Zou 2018-04-23 19:04:20 -04:00 committed by Soumith Chintala
parent b5d2d285a8
commit 82a33c32aa

View File

@ -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