diff options
author | Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com> | 2024-01-18 16:14:03 +0000 |
---|---|---|
committer | Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com> | 2024-01-18 16:14:03 +0000 |
commit | 0181c1f76b97162c42401f1e6286ae73d8aa6033 (patch) | |
tree | 05b2b41a8b8abca556f1674c1c39b94a5e493776 | |
parent | cb5b335acddd126d4f6c990982816c06beb0d6ae (diff) | |
download | stable-diffusion-webui-gfx803-0181c1f76b97162c42401f1e6286ae73d8aa6033.tar.gz stable-diffusion-webui-gfx803-0181c1f76b97162c42401f1e6286ae73d8aa6033.tar.bz2 stable-diffusion-webui-gfx803-0181c1f76b97162c42401f1e6286ae73d8aa6033.zip |
Fix nested manual cast
-rw-r--r-- | modules/devices.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/devices.py b/modules/devices.py index 0321d12c..37028629 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -165,6 +165,8 @@ def manual_cast_forward(target_dtype): @contextlib.contextmanager def manual_cast(target_dtype): for module_type in patch_module_list: + if hasattr(module_type, "org_forward"): + continue org_forward = module_type.forward if module_type == torch.nn.MultiheadAttention and has_xpu(): module_type.forward = manual_cast_forward(torch.float32) @@ -175,7 +177,9 @@ def manual_cast(target_dtype): yield None finally: for module_type in patch_module_list: - module_type.forward = module_type.org_forward + if hasattr(module_type, "org_forward"): + module_type.forward = module_type.org_forward + delattr(module_type, "org_forward") def autocast(disable=False): |