diff options
author | Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com> | 2024-01-20 08:31:12 +0000 |
---|---|---|
committer | Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com> | 2024-01-20 08:31:12 +0000 |
commit | 81126027f5226e7ee58e1a99194eb9ec7b8ec6e7 (patch) | |
tree | 967050b18f143954888df3c6efae6cb366a7654e | |
parent | 0181c1f76b97162c42401f1e6286ae73d8aa6033 (diff) | |
download | stable-diffusion-webui-gfx803-81126027f5226e7ee58e1a99194eb9ec7b8ec6e7.tar.gz stable-diffusion-webui-gfx803-81126027f5226e7ee58e1a99194eb9ec7b8ec6e7.tar.bz2 stable-diffusion-webui-gfx803-81126027f5226e7ee58e1a99194eb9ec7b8ec6e7.zip |
Avoid early disable
-rw-r--r-- | modules/devices.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/modules/devices.py b/modules/devices.py index 37028629..3bde1699 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -164,9 +164,11 @@ def manual_cast_forward(target_dtype): @contextlib.contextmanager def manual_cast(target_dtype): + applied = False for module_type in patch_module_list: if hasattr(module_type, "org_forward"): continue + applied = True org_forward = module_type.forward if module_type == torch.nn.MultiheadAttention and has_xpu(): module_type.forward = manual_cast_forward(torch.float32) @@ -176,6 +178,8 @@ def manual_cast(target_dtype): try: yield None finally: + if not applied: + return for module_type in patch_module_list: if hasattr(module_type, "org_forward"): module_type.forward = module_type.org_forward |