From 82a33c32aa338444e3534f386a12c2e1ae014d04 Mon Sep 17 00:00:00 2001 From: Richard Zou Date: Mon, 23 Apr 2018 19:04:20 -0400 Subject: [PATCH] Update device docs (#6887) Tell users that one can substitute torch.device with a string --- docs/source/tensor_attributes.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/source/tensor_attributes.rst b/docs/source/tensor_attributes.rst index 82eaa839687..230b74d7dd3 100644 --- a/docs/source/tensor_attributes.rst +++ b/docs/source/tensor_attributes.rst @@ -71,6 +71,17 @@ Via a string and device ordinal: >>> torch.device('cpu', 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:: 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