Add IPEX Optimizers and use XPU instead of CPU when using IPEX

This commit is contained in:
Disty0
2023-05-03 18:12:38 +03:00
parent e324e54cfb
commit 7577a09528
2 changed files with 8 additions and 1 deletions
+5 -1
View File
@@ -111,7 +111,11 @@ def set_cuda_params():
unet_needs_upcast = shared.opts.upcast_sampling
cpu = torch.device("cpu")
from launch import args
if args.use_ipex:
cpu = torch.device("xpu") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs.
else:
cpu = torch.device("cpu")
device = device_interrogate = device_gfpgan = device_esrgan = device_codeformer = None
dtype = torch.float16
dtype_vae = torch.float16
+3
View File
@@ -398,6 +398,9 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None, timer=None)
sd_hijack.model_hijack.hijack(sd_model)
timer.record("hijack")
sd_model.eval()
if shared.cmd_opts.use_ipex:
sd_model = torch.xpu.optimize(sd_model, dtype=devices.dtype)
shared.log.info("Applied IPEX Optimize")
shared.sd_model = sd_model
sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True) # Reload embeddings after model load as they may or may not fit the model
timer.record("embeddings")