From bab6c253f44d56701bcb6a0a21574885627371bb Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Mon, 25 May 2026 23:31:33 +0100 Subject: [PATCH] feat(sd_unet): reset UNET override on cross-arch base model swap A custom UNET selected via the UNET dropdown carried over silently when the user swapped to a base model of a different arch, then crashed inside the per-arch loader because shared.opts.sd_unet was still pointing at the previous arch's file. reload_model_weights now runs sd_detect.detect_pipeline on the new checkpoint before unloading the old model, compares the detected pipeline class against the loaded model's class, and resets shared.opts.sd_unet to Default when they differ. --- modules/sd_models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/sd_models.py b/modules/sd_models.py index cc36d57ea..e4f48eb70 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -1412,6 +1412,17 @@ def reload_model_weights(sd_model=None, info=None, op='model', force=False, revi jobid = shared.state.begin('Load model') if sd_model is None: sd_model = model_data.sd_model if op == 'model' or op == 'dict' else model_data.sd_refiner + if op == 'model' and sd_model is not None and shared.opts.sd_unet not in (None, 'Default', 'None'): + old_class = type(sd_model).__name__ + try: + new_pipeline, _ = sd_detect.detect_pipeline(checkpoint_info.path, op) + except Exception: + new_pipeline = None + new_class = getattr(new_pipeline, '__name__', None) + if new_class is not None and new_class != old_class: + log.info(f'Load model: pipeline changed {old_class}->{new_class}, resetting sd_unet from "{shared.opts.sd_unet}" to Default') + shared.opts.data["sd_unet"] = 'Default' + sd_unet.loaded_unet = None if sd_model is None: # previous model load failed current_checkpoint_info = None else: