numpy_to_torch#

muse.utils.numpy_to_torch(numpy_array, cuda_device=None)#

Convert a numpy.ndarray to a torch.Tensor.

Floating-point precision is capped at float32: float64 input is downcast to float32, while narrower dtypes (float16, integers) are left as-is.

Parameters:
  • numpy_array (ndarray) – The array to convert.

  • cuda_device (int | None) – If provided, transfer the tensor to the specified CUDA device.

Returns:

The converted Torch tensor.

Return type:

torch.Tensor