From 205b5164872aadc61b49ee409352c0a5c736aa84 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Fri, 7 Jul 2023 22:41:26 +0300 Subject: [PATCH] Fix diffusers_sdxl on ipex --- modules/devices.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/devices.py b/modules/devices.py index 67e01cd06..dbc7b94a7 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -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"),