From 7fb40bf803d05cde9ca9db8b1c6b8ee3c5efb352 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 23 Jan 2024 00:34:47 +0000 Subject: [PATCH] :wrench: Explicit error on ipadapter invalid preprocessor/model pair (#2551) * :wrench: Explicit error on ipadapter invalid preprocessor/model pair * nit --- scripts/controlnet.py | 9 +++++++++ scripts/global_state.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/scripts/controlnet.py b/scripts/controlnet.py index 0cf9191ce..a9cb209e8 100644 --- a/scripts/controlnet.py +++ b/scripts/controlnet.py @@ -853,6 +853,15 @@ def controlnet_main_entry(self, p): for idx, unit in enumerate(self.enabled_units): Script.bound_check_params(unit) Script.check_sd_version_compatible(unit) + if ( + "ip-adapter" in unit.module and + not global_state.ip_adapter_pairing_model[unit.module](unit.model) + ): + logger.error(f"Invalid pair of IP-Adapter preprocessor({unit.module}) and model({unit.model}).\n" + "Please follow following pairing logic:\n" + + global_state.ip_adapter_pairing_logic_text) + continue + if ( 'inpaint_only' == unit.module and issubclass(type(p), StableDiffusionProcessingImg2Img) and diff --git a/scripts/global_state.py b/scripts/global_state.py index 01cea1080..21c7b8462 100644 --- a/scripts/global_state.py +++ b/scripts/global_state.py @@ -331,3 +331,22 @@ def select_control_type( default_option, default_model ) + + +ip_adapter_pairing_model = { + "ip-adapter_clip_sdxl": lambda model: "faceid" not in model and "vit" not in model, + "ip-adapter_clip_sdxl_plus_vith": lambda model: "faceid" not in model and "vit" in model, + "ip-adapter_clip_sd15": lambda model: "faceid" not in model, + "ip-adapter_face_id": lambda model: "faceid" in model and "plus" not in model, + "ip-adapter_face_id_plus": lambda model: "faceid" in model and "plus" in model, +} + +ip_adapter_pairing_logic_text = """ +{ + "ip-adapter_clip_sdxl": lambda model: "faceid" not in model and "vit" not in model, + "ip-adapter_clip_sdxl_plus_vith": lambda model: "faceid" not in model and "vit" in model, + "ip-adapter_clip_sd15": lambda model: "faceid" not in model, + "ip-adapter_face_id": lambda model: "faceid" in model and "plus" not in model, + "ip-adapter_face_id_plus": lambda model: "faceid" in model and "plus" in model, +} +"""