aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-10-15 10:47:26 +0300
committerGitHub <noreply@github.com>2022-10-15 10:47:26 +0300
commitf42e0aae6de6b9a7f8da4eaf13594a13502b4fa9 (patch)
tree472025101577ff5cbd45a3bcb524e6e4accb75ec /modules/devices.py
parent0e77ee24b0b651d6a564245243850e4fb9831e31 (diff)
parentd13ce89e203d76ab2b54a3406a93a5e4304f529e (diff)
Merge branch 'master' into master
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/devices.py b/modules/devices.py
index 07bb2339..eb422583 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -1,8 +1,10 @@
+import contextlib
+
import torch
-# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
from modules import errors
+# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
has_mps = getattr(torch, 'has_mps', False)
cpu = torch.device("cpu")
@@ -32,10 +34,9 @@ def enable_tf32():
errors.run(enable_tf32, "Enabling TF32")
-
-device = get_optimal_device()
-device_codeformer = cpu if has_mps else device
-
+device = device_interrogate = device_gfpgan = device_bsrgan = device_esrgan = device_scunet = device_codeformer = get_optimal_device()
+dtype = torch.float16
+dtype_vae = torch.float16
def randn(seed, shape):
# Pytorch currently doesn't handle setting randomness correctly when the metal backend is used.
@@ -58,3 +59,14 @@ def randn_without_seed(shape):
return torch.randn(shape, device=device)
+
+def autocast(disable=False):
+ from modules import shared
+
+ if disable:
+ return contextlib.nullcontext()
+
+ if dtype == torch.float32 or shared.cmd_opts.precision == "full":
+ return contextlib.nullcontext()
+
+ return torch.autocast("cuda")