lora: restore pipeline type if reload/recompile needed

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-11-13 09:56:36 -05:00
parent eebd980b2f
commit ff772003e3
4 changed files with 22 additions and 6 deletions
+1
View File
@@ -40,6 +40,7 @@ TBD
- ui: fix collapsible panels
- svd: fix stable-video-diffusion dtype mismatch
- animatediff: disable sdnq if used
- lora: restore pipeline type if reload/recompile needed
- process: improve send-to functionality
- control: safe load non-sparse controlnet
- control: fix marigold preprocessor with bfloat16
+8 -1
View File
@@ -73,6 +73,13 @@ if hasattr(torch, "float8_e8m0fnu"):
dtype_mapping[torch.float8_e8m0fnu] = Type.f8e8m0
warned = False
def warn_once(msg):
global warned
if not warned:
shared.log.warning(msg)
warned = True
class OpenVINOGraphModule(torch.nn.Module):
def __init__(self, gm, partition_id, use_python_fusion_cache, model_hash_str: str = None, file_name="", int_inputs=[]):
super().__init__()
@@ -128,7 +135,7 @@ def get_device():
device = "GPU.0"
else:
device = core.available_devices[-1]
shared.log.warning(f"OpenVINO: No compatible GPU detected! Using {device}")
warn_once(f"OpenVINO: device={device} no compatible GPU detected")
return device
+10 -3
View File
@@ -157,11 +157,14 @@ def maybe_recompile_model(names, te_multipliers):
recompile_model = True
shared.compiled_model_state.lora_model = []
if recompile_model:
current_task = sd_models.get_diffusers_task(shared.sd_model)
shared.log.debug(f'Compile: task={current_task} force model reload')
backup_cuda_compile = shared.opts.cuda_compile
backup_scheduler = getattr(sd_model, "scheduler", None)
sd_models.unload_model_weights(op='model')
shared.opts.cuda_compile = []
sd_models.reload_model_weights(op='model')
shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, current_task)
shared.opts.cuda_compile = backup_cuda_compile
if backup_scheduler is not None:
sd_model.scheduler = backup_scheduler
@@ -247,7 +250,7 @@ def network_load(names, te_multipliers=None, unet_multipliers=None, dyn_dims=Non
try:
lora_scale = te_multipliers[i] if te_multipliers else shared.opts.extra_networks_default_multiplier
lora_module = lora_modules[i] if lora_modules and len(lora_modules) > i else None
if recompile_model:
if recompile_model and shared.compiled_model_state is not None:
shared.compiled_model_state.lora_model.append(f"{name}:{lora_scale}")
lora_method = lora_overrides.get_method(shorthash)
if lora_method == 'diffusers':
@@ -307,9 +310,13 @@ def network_load(names, te_multipliers=None, unet_multipliers=None, dyn_dims=Non
if recompile_model:
shared.log.info("Network load: type=LoRA recompiling model")
backup_lora_model = shared.compiled_model_state.lora_model
if shared.compiled_model_state is not None:
backup_lora_model = shared.compiled_model_state.lora_model
else:
backup_lora_model = []
if 'Model' in shared.opts.cuda_compile:
sd_model = sd_models_compile.compile_diffusers(sd_model)
shared.compiled_model_state.lora_model = backup_lora_model
if shared.compiled_model_state is not None:
shared.compiled_model_state.lora_model = backup_lora_model
l.timer.load = time.time() - t0
+3 -2
View File
@@ -1263,6 +1263,7 @@ def clear_caches(full:bool=False):
def unload_model_weights(op='model'):
fn = f'{sys._getframe(2).f_code.co_name}:{sys._getframe(1).f_code.co_name}' # pylint: disable=protected-access
clear_caches(full=True)
if shared.compiled_model_state is not None:
shared.compiled_model_state.compiled_cache.clear()
@@ -1275,14 +1276,14 @@ def unload_model_weights(op='model'):
move_model(model_data.sd_model, 'meta')
model_data.sd_model = None
devices.torch_gc(force=True, reason='unload')
shared.log.debug(f'Unload {op}: {memory_stats()} after')
shared.log.debug(f'Unload {op}: {memory_stats()} fn={fn}')
elif (op == 'refiner') and model_data.sd_refiner:
shared.log.debug(f'Current {op}: {memory_stats()}')
disable_offload(model_data.sd_refiner)
move_model(model_data.sd_refiner, 'meta')
model_data.sd_refiner = None
devices.torch_gc(force=True, reason='unload')
shared.log.debug(f'Unload {op}: {memory_stats()}')
shared.log.debug(f'Unload {op}: {memory_stats()} fn={fn}')
def hf_auth_check(checkpoint_info, force:bool=False):