From 8ba80bbc41c052964812830815f3fb443236fa3e Mon Sep 17 00:00:00 2001 From: Disty0 Date: Sun, 3 Dec 2023 00:14:57 +0300 Subject: [PATCH] Make OpenVINO use SD_LORA_DIFFUSERS flag --- extensions-builtin/Lora/lora_patches.py | 5 +++-- extensions-builtin/Lora/networks.py | 6 ++---- installer.py | 1 + 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions-builtin/Lora/lora_patches.py b/extensions-builtin/Lora/lora_patches.py index 12986e8f9..680ed4d0d 100644 --- a/extensions-builtin/Lora/lora_patches.py +++ b/extensions-builtin/Lora/lora_patches.py @@ -1,3 +1,4 @@ +import os import torch import networks from modules import patches, shared @@ -18,7 +19,7 @@ class LoraPatches: self.MultiheadAttention_load_state_dict = None def apply(self): - if self.active or (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): # OpenVINO only works with Diffusers LoRa loading + if self.active or os.environ.get('SD_LORA_DIFFUSERS', None): # OpenVINO only works with Diffusers LoRa loading return self.Linear_forward = patches.patch(__name__, torch.nn.Linear, 'forward', networks.network_Linear_forward) self.Linear_load_state_dict = patches.patch(__name__, torch.nn.Linear, '_load_from_state_dict', networks.network_Linear_load_state_dict) @@ -36,7 +37,7 @@ class LoraPatches: self.active = True def undo(self): - if not self.active or (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): # OpenVINO only works with Diffusers LoRa loading + if not self.active or os.environ.get('SD_LORA_DIFFUSERS', None): # OpenVINO only works with Diffusers LoRa loading return self.Linear_forward = patches.undo(__name__, torch.nn.Linear, 'forward') # pylint: disable=E1128 self.Linear_load_state_dict = patches.undo(__name__, torch.nn.Linear, '_load_from_state_dict') # pylint: disable=E1128 diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 015d2cece..afd9d0796 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -166,12 +166,10 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No try: if recompile_model: shared.compiled_model_state.lora_model.append(f"{name}:{te_multipliers[i] if te_multipliers else 1.0}") - if shared.backend == shared.Backend.DIFFUSERS and (os.environ.get('SD_LORA_DIFFUSERS', None) + if shared.backend == shared.Backend.DIFFUSERS and (os.environ.get('SD_LORA_DIFFUSERS', None) # OpenVINO only works with Diffusers LoRa loading. or getattr(network_on_disk, 'shorthash', '').lower() == 'aaebf6360f7d' # sd15-lcm or getattr(network_on_disk, 'shorthash', '').lower() == '3d18b05e4f56' # sdxl-lcm - or getattr(network_on_disk, 'shorthash', '').lower() == '813ea5fb1c67' # turbo sdxl-turbo - or (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx")): - # OpenVINO only works with Diffusers LoRa loading. + or getattr(network_on_disk, 'shorthash', '').lower() == '813ea5fb1c67'): # turbo sdxl-turbo net = load_diffusers(name, network_on_disk, lora_scale=te_multipliers[i] if te_multipliers else 1.0) else: net = load_network(name, network_on_disk) diff --git a/installer.py b/installer.py index 7529f6cea..d7f069af9 100644 --- a/installer.py +++ b/installer.py @@ -518,6 +518,7 @@ def check_torch(): install('openvino==2023.2.0', 'openvino') install('onnxruntime-openvino', 'onnxruntime-openvino', ignore=True) # TODO openvino: numpy version conflicts with tensorflow and doesn't support Python 3.11 os.environ.setdefault('PYTORCH_TRACING_MODE', 'TORCHFX') + os.environ.setdefault('SD_LORA_DIFFUSERS', '1') os.environ.setdefault('NEOReadDebugKeys', '1') os.environ.setdefault('ClDeviceGlobalMemSizeAvailablePercent', '100') if args.profile: