ray.rllib.utils.torch_utils.convert_to_torch_tensor#

ray.rllib.utils.torch_utils.convert_to_torch_tensor(x: numpy.array | jnp.ndarray | tf.Tensor | torch.Tensor | dict | tuple, device: str | None = None, pin_memory: bool = False)[source]#

Converts any struct to torch.Tensors.

Parameters:
  • x – Any (possibly nested) struct, the values in which will be converted and returned as a new struct with all leaves converted to torch tensors.

  • device – The device to create the tensor on.

  • pin_memory – If True, will call the pin_memory() method on the created tensors.

Returns:

A new struct with the same structure as x, but with all values converted to torch Tensor types. This does not convert possibly nested elements that are None because torch has no representation for that.

Return type:

Any