From f437bfa4f568c3749b346e3f4f4de29e65a64fac Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Thu, 15 May 2025 11:46:44 +0530 Subject: [PATCH] allow string device to be passed to randn_tensor. --- src/diffusers/utils/torch_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/diffusers/utils/torch_utils.py b/src/diffusers/utils/torch_utils.py index 19c076a4a6c7..62e8be129264 100644 --- a/src/diffusers/utils/torch_utils.py +++ b/src/diffusers/utils/torch_utils.py @@ -38,7 +38,7 @@ def maybe_allow_in_graph(cls): def randn_tensor( shape: Union[Tuple, List], generator: Optional[Union[List["torch.Generator"], "torch.Generator"]] = None, - device: Optional["torch.device"] = None, + device: Optional[Union[str, "torch.device"]] = None, dtype: Optional["torch.dtype"] = None, layout: Optional["torch.layout"] = None, ): @@ -47,6 +47,8 @@ def randn_tensor( is always created on the CPU. """ # device on which tensor is created defaults to device + if isinstance(device, str): + device = torch.device(device) rand_device = device batch_size = shape[0]