diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 09:32:22 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 09:32:22 +0000 |
commit | 6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77 (patch) | |
tree | 5c221ca22288633f8814cc1f304590bf5f26b73c /modules/devices.py | |
parent | 556c36b9607e3f4eacdddc85f8e7a78b29476ea7 (diff) | |
download | stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.tar.gz stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.tar.bz2 stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.zip |
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.py | 10 |
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") |