aboutsummaryrefslogtreecommitdiff
path: root/modules/devices.py
diff options
context:
space:
mode:
authorKohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com>2024-01-19 00:14:03 +0800
committerKohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com>2024-01-19 00:14:03 +0800
commit0181c1f76b97162c42401f1e6286ae73d8aa6033 (patch)
tree05b2b41a8b8abca556f1674c1c39b94a5e493776 /modules/devices.py
parentcb5b335acddd126d4f6c990982816c06beb0d6ae (diff)
Fix nested manual cast
Diffstat (limited to 'modules/devices.py')
-rw-r--r--modules/devices.py6
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):