aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorJashoBell <JoshuaDB@gmail.com>2022-09-17 11:16:35 -0700
committerJashoBell <JoshuaDB@gmail.com>2022-09-17 11:16:35 -0700
commitd2c7ad2fec09d89d1348d6d40640259b5a02b8ad (patch)
tree90f4f6695f318aed33dea72cc340c0f5ff628ae8 /modules/devices.py
parent5a797a5612924e50d5b60d2aa1eddfae4c3e157e (diff)
parent23a0ec04c005957091ab35c26c4c31485e75d146 (diff)
Merge branch 'master' of https://github.com/AUTOMATIC1111/stable-diffusion-webui into Base
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/devices.py b/modules/devices.py
index e4430e1a..07bb2339 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -48,3 +48,13 @@ def randn(seed, shape):
torch.manual_seed(seed)
return torch.randn(shape, device=device)
+
+def randn_without_seed(shape):
+ # Pytorch currently doesn't handle setting randomness correctly when the metal backend is used.
+ if device.type == 'mps':
+ generator = torch.Generator(device=cpu)
+ noise = torch.randn(shape, generator=generator, device=cpu).to(device)
+ return noise
+
+ return torch.randn(shape, device=device)
+