Make OpenVINO use SD_LORA_DIFFUSERS flag

This commit is contained in:
Disty0
2023-12-03 00:14:57 +03:00
parent bebfc908a8
commit 8ba80bbc41
3 changed files with 6 additions and 6 deletions
+3 -2
View File
@@ -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
+2 -4
View File
@@ -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)
+1
View File
@@ -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: