TensorDictBase.cuda#
- TensorDictBase.cuda(device: int | str | device | None = None, **kwargs) Self#
Returns the tensordict on a CUDA device, as
to()does.A tensordict that is already on that device is returned as it is.
- Parameters:
- Raises:
RuntimeError – if
deviceis not a CUDA device.
Examples
The example needs a CUDA device, so it is not run when the documentation is tested.
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(3), batch_size=[3]) >>> td.cuda().device device(type='cuda', index=0) >>> td.cuda(1).device device(type='cuda', index=1)
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.