aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorDeciare <1689220+deciare@users.noreply.github.com>2023-04-18 23:18:58 -0400
committerDeciare <1689220+deciare@users.noreply.github.comw>2023-04-18 23:27:46 -0400
commitd40e44ade479f7bba30d5317381cbc58c861775b (patch)
tree40755c59268f844ba1aa8f0dcec8cf5fdb66699a /modules/devices.py
parent22bcc7be428c94e9408f589966c2040187245d81 (diff)
Option to use CPU for random number generation.
Makes a given manual seed generate the same images across different platforms, independently of the GPU architecture in use. Fixes #9613.
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/devices.py b/modules/devices.py
index 52c3e7cd..3bc86a6a 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -92,14 +92,18 @@ def cond_cast_float(input):
def randn(seed, shape):
+ from modules.shared import opts
+
torch.manual_seed(seed)
- if device.type == 'mps':
+ if opts.use_cpu_randn or device.type == 'mps':
return torch.randn(shape, device=cpu).to(device)
return torch.randn(shape, device=device)
def randn_without_seed(shape):
- if device.type == 'mps':
+ from modules.shared import opts
+
+ if opts.use_cpu_randn or device.type == 'mps':
return torch.randn(shape, device=cpu).to(device)
return torch.randn(shape, device=device)