IPEX fixes

This commit is contained in:
Disty0
2024-10-18 01:12:28 +03:00
parent 1a7b88ab64
commit 065155f5e6
3 changed files with 8 additions and 4 deletions
+4 -1
View File
@@ -27,12 +27,15 @@ def project(
v0: torch.Tensor, # [B, C, H, W]
v1: torch.Tensor, # [B, C, H, W]
):
device = v0.device
dtype = v0.dtype
if device.type == "xpu":
v0, v1 = v0.to("cpu"), v1.to("cpu")
v0, v1 = v0.double(), v1.double()
v1 = torch.nn.functional.normalize(v1, dim=[-1, -2, -3])
v0_parallel = (v0 * v1).sum(dim=[-1, -2, -3], keepdim=True) * v1
v0_orthogonal = v0 - v0_parallel
return v0_parallel.to(dtype), v0_orthogonal.to(dtype)
return v0_parallel.to(device, dtype=dtype), v0_orthogonal.to(device, dtype=dtype)
def normalized_guidance(
+1 -1
View File
@@ -199,7 +199,7 @@ def ipex_init(): # pylint: disable=too-many-statements
torch.cuda.ipc_collect = lambda *args, **kwargs: None
torch.cuda.utilization = lambda *args, **kwargs: 0
ipex_hijacks()
ipex_hijacks(legacy=legacy)
try:
from .diffusers import ipex_diffusers
ipex_diffusers()
+3 -2
View File
@@ -293,7 +293,9 @@ def torch_load(f, map_location=None, *args, **kwargs):
# Hijack Functions:
def ipex_hijacks():
def ipex_hijacks(legacy=True):
if legacy:
torch.nn.functional.interpolate = interpolate
torch.tensor = torch_tensor
torch.Tensor.to = Tensor_to
torch.Tensor.cuda = Tensor_cuda
@@ -319,7 +321,6 @@ def ipex_hijacks():
torch.nn.functional.layer_norm = functional_layer_norm
torch.nn.functional.linear = functional_linear
torch.nn.functional.conv2d = functional_conv2d
torch.nn.functional.interpolate = interpolate
torch.nn.functional.pad = functional_pad
torch.bmm = torch_bmm