Skip to content

Commit 54af3ca

Browse files
authored
[chore] allow string device to be passed to randn_tensor. (#11559)
allow string device to be passed to randn_tensor.
1 parent ba8dc7d commit 54af3ca

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/diffusers/utils/torch_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def maybe_allow_in_graph(cls):
3838
def randn_tensor(
3939
shape: Union[Tuple, List],
4040
generator: Optional[Union[List["torch.Generator"], "torch.Generator"]] = None,
41-
device: Optional["torch.device"] = None,
41+
device: Optional[Union[str, "torch.device"]] = None,
4242
dtype: Optional["torch.dtype"] = None,
4343
layout: Optional["torch.layout"] = None,
4444
):
@@ -47,6 +47,8 @@ def randn_tensor(
4747
is always created on the CPU.
4848
"""
4949
# device on which tensor is created defaults to device
50+
if isinstance(device, str):
51+
device = torch.device(device)
5052
rand_device = device
5153
batch_size = shape[0]
5254

0 commit comments

Comments
 (0)