Skip to content

Commit

Permalink
🔧 Explicit error on ipadapter invalid preprocessor/model pair (#2551)
Browse files Browse the repository at this point in the history
* 🔧 Explicit error on ipadapter invalid preprocessor/model pair

* nit
  • Loading branch information
huchenlei committed Jan 23, 2024
1 parent b23015a commit 7fb40bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions scripts/global_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
"""

0 comments on commit 7fb40bf

Please sign in to comment.