aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-01-25 19:12:29 +0300
committerGitHub <noreply@github.com>2023-01-25 19:12:29 +0300
commit1574e967297586d013e4cfbb6628eae595c9fba2 (patch)
tree99374009f63cf73cadc713b02db5fbba0701e516 /modules/devices.py
parent1982ef68900fe3c5eee704dfbda5416c1bb5470b (diff)
parente3b53fd295aca784253dfc8668ec87b537a72f43 (diff)
Merge pull request #6510 from brkirch/unet16-upcast-precision
Add upcast options, full precision sampling from float16 UNet and upcasting attention for inference using SD 2.1 models without --no-half
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/devices.py b/modules/devices.py
index 524ec7af..6b36622c 100644
--- a/modules/devices.py
+++ b/modules/devices.py
@@ -79,6 +79,8 @@ cpu = torch.device("cpu")
device = device_interrogate = device_gfpgan = device_esrgan = device_codeformer = None
dtype = torch.float16
dtype_vae = torch.float16
+dtype_unet = torch.float16
+unet_needs_upcast = False
def randn(seed, shape):
@@ -106,6 +108,10 @@ def autocast(disable=False):
return torch.autocast("cuda")
+def without_autocast(disable=False):
+ return torch.autocast("cuda", enabled=False) if torch.is_autocast_enabled() and not disable else contextlib.nullcontext()
+
+
class NansException(Exception):
pass
@@ -123,7 +129,7 @@ def test_for_nans(x, where):
message = "A tensor with all NaNs was produced in Unet."
if not shared.cmd_opts.no_half:
- message += " This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try using --no-half commandline argument to fix this."
+ message += " This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the \"Upcast cross attention layer to float32\" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this."
elif where == "vae":
message = "A tensor with all NaNs was produced in VAE."