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.
This commit is contained in:
CalamitousFelicitousness
2026-05-25 23:31:33 +01:00
parent cda4822ca0
commit bab6c253f4
+11
View File
@@ -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: