aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-10-04 12:32:22 +0300
committerAUTOMATIC <16777216c@gmail.com>2022-10-04 12:32:22 +0300
commit6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77 (patch)
tree5c221ca22288633f8814cc1f304590bf5f26b73c /modules/devices.py
parent556c36b9607e3f4eacdddc85f8e7a78b29476ea7 (diff)
send all three of GFPGAN's and codeformer's models to CPU memory instead of just one for #1283
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 ff82f2f6..12aab665 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -1,3 +1,5 @@
+import contextlib
+
import torch
# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
@@ -57,3 +59,11 @@ def randn_without_seed(shape):
return torch.randn(shape, device=device)
+
+def autocast():
+ from modules import shared
+
+ if dtype == torch.float32 or shared.cmd_opts.precision == "full":
+ return contextlib.nullcontext()
+
+ return torch.autocast("cuda")