Fix diffusers_sdxl on ipex

This commit is contained in:
Disty0
2023-07-07 22:41:26 +03:00
parent 3bcca6f92b
commit 205b516487
+10 -3
View File
@@ -175,8 +175,10 @@ else:
backend = 'cpu'
if backend == 'ipex':
#Fix broken function in ipex 1.13.120+xpu
#Fix broken functions with ipex
from modules.sd_hijack_utils import CondFunc
torch.cuda.empty_cache = torch.xpu.empty_cache
#Functions with dtype errors:
CondFunc('torch.nn.modules.GroupNorm.forward',
lambda orig_func, *args, **kwargs: orig_func(args[0], args[1].to(args[0].weight.data.dtype)),
@@ -184,6 +186,7 @@ if backend == 'ipex':
CondFunc('torch.nn.modules.Linear.forward',
lambda orig_func, *args, **kwargs: orig_func(args[0], args[1].to(args[0].weight.data.dtype)),
lambda *args, **kwargs: args[2].dtype != args[1].weight.data.dtype)
#Functions that does not work with the XPU:
#UniPC:
CondFunc('torch.linalg.solve',
@@ -191,8 +194,12 @@ if backend == 'ipex':
lambda *args, **kwargs: args[1].device != torch.device("cpu"))
#SDE Samplers:
CondFunc('torch.Generator',
lambda _, device: torch.xpu.Generator(device),
lambda _, device: device != torch.device("cpu") and device != "cpu")
lambda orig_func, device: torch.xpu.Generator(device),
lambda orig_func, device: device != torch.device("cpu") and device != "cpu")
#Diffusers Float64 (ARC GPUs doesn't support double or Float64):
CondFunc('torch.from_numpy',
lambda orig_func, *args, **kwargs: orig_func(args[0].astype('float32')),
lambda *args, **kwargs: args[1].dtype == float)
#ControlNet:
CondFunc('torch.batch_norm',
lambda orig_func, *args, **kwargs: orig_func(args[0].to("cpu"),