Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions modules/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import torch
from modules import errors, shared
from modules import torch_utils

if sys.platform == "darwin":
from modules import mac_specific
Expand Down Expand Up @@ -141,7 +140,12 @@ def forward_wrapper(self, *args, **kwargs):
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)
Expand Down Expand Up @@ -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)
Expand Down