mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-19 21:00:14 +08:00
Fix potential bugs
This commit is contained in:
parent
6484053037
commit
750dd6014a
@ -141,7 +141,12 @@ def manual_cast_forward(target_dtype):
|
|||||||
args = [arg.to(target_dtype) if isinstance(arg, torch.Tensor) else arg for arg in args]
|
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()}
|
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:
|
if org_dtype != target_dtype:
|
||||||
self.to(target_dtype)
|
self.to(target_dtype)
|
||||||
result = self.org_forward(*args, **kwargs)
|
result = self.org_forward(*args, **kwargs)
|
||||||
@ -170,7 +175,7 @@ def manual_cast(target_dtype):
|
|||||||
continue
|
continue
|
||||||
applied = True
|
applied = True
|
||||||
org_forward = module_type.forward
|
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)
|
module_type.forward = manual_cast_forward(torch.float32)
|
||||||
else:
|
else:
|
||||||
module_type.forward = manual_cast_forward(target_dtype)
|
module_type.forward = manual_cast_forward(target_dtype)
|
||||||
|
Loading…
Reference in New Issue
Block a user