diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-29 17:39:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-29 17:39:06 +0000 |
commit | ce168ab5dbc8b54b7245f352a2eaa55a37019b91 (patch) | |
tree | 3549de31fff495174f6de7f53b432596d0eb6bc7 /modules | |
parent | 6484053037aaf13cd9774f150e8f45e11c8dc536 (diff) | |
parent | f9ba7e648ad5bf7dbdf2b95fa207936179bf784e (diff) | |
download | stable-diffusion-webui-gfx803-ce168ab5dbc8b54b7245f352a2eaa55a37019b91.tar.gz stable-diffusion-webui-gfx803-ce168ab5dbc8b54b7245f352a2eaa55a37019b91.tar.bz2 stable-diffusion-webui-gfx803-ce168ab5dbc8b54b7245f352a2eaa55a37019b91.zip |
Merge pull request #14791 from AUTOMATIC1111/fix-mha-manual-cast
Fix dtype error in MHA layer/change dtype checking mechanism for manual cast
Diffstat (limited to 'modules')
-rw-r--r-- | modules/devices.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/devices.py b/modules/devices.py index dfffaf24..8f49f7a4 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -4,7 +4,6 @@ from functools import lru_cache import torch from modules import errors, shared -from modules import torch_utils if sys.platform == "darwin": from modules import mac_specific @@ -141,7 +140,12 @@ def manual_cast_forward(target_dtype): args = [arg.to(target_dtype) if isinstance(arg, torch.Tensor) else arg for arg in args] kwargs = {k: v.to(target_dtype) if isinstance(v, torch.Tensor) else v for k, v in kwargs.items()} - org_dtype = torch_utils.get_param(self).dtype + org_dtype = target_dtype + for param in self.parameters(): + if param.dtype != target_dtype: + org_dtype = param.dtype + break + if org_dtype != target_dtype: self.to(target_dtype) result = self.org_forward(*args, **kwargs) @@ -170,7 +174,7 @@ def manual_cast(target_dtype): continue applied = True org_forward = module_type.forward - if module_type == torch.nn.MultiheadAttention and has_xpu(): + if module_type == torch.nn.MultiheadAttention: module_type.forward = manual_cast_forward(torch.float32) else: module_type.forward = manual_cast_forward(target_dtype) |