diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-20 08:43:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 08:43:51 +0000 |
commit | c1713bfeac461bc28158b66ef8d956a39e296b94 (patch) | |
tree | 6cd8bea6b1464fadba076e83d213dea13f2ba8ab | |
parent | 1dbee391b4e6be991f95a92503e490c95fb00c72 (diff) | |
parent | 4a66d2fb228584bb38dc22db6a3e657561834c7a (diff) | |
download | stable-diffusion-webui-gfx803-c1713bfeac461bc28158b66ef8d956a39e296b94.tar.gz stable-diffusion-webui-gfx803-c1713bfeac461bc28158b66ef8d956a39e296b94.tar.bz2 stable-diffusion-webui-gfx803-c1713bfeac461bc28158b66ef8d956a39e296b94.zip |
Merge pull request #14689 from AUTOMATIC1111/fix-nested-manual-cast
Fix nested manual cast
-rw-r--r-- | modules/devices.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/devices.py b/modules/devices.py index 0321d12c..dfffaf24 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -164,7 +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) @@ -174,8 +178,11 @@ def manual_cast(target_dtype): try: yield None finally: - for module_type in patch_module_list: - module_type.forward = module_type.org_forward + if applied: + for module_type in patch_module_list: + if hasattr(module_type, "org_forward"): + module_type.forward = module_type.org_forward + delattr(module_type, "org_forward") def autocast(disable=False): |