MCPcopy Create free account
hub / github.com/cubiq/ComfyUI_IPAdapter_plus / ipadapter_execute

Function ipadapter_execute

IPAdapterPlus.py:228–539  ·  view source on GitHub ↗
(model,
                      ipadapter,
                      clipvision,
                      insightface=None,
                      image=None,
                      image_composition=None,
                      image_negative=None,
                      weight=1.0,
                      weight_composition=1.0,
                      weight_faceidv2=None,
                      weight_kolors=1.0,
                      weight_type="linear",
                      combine_embeds="concat",
                      start_at=0.0,
                      end_at=1.0,
                      attn_mask=None,
                      pos_embed=None,
                      neg_embed=None,
                      unfold_batch=False,
                      embeds_scaling='V only',
                      layer_weights=None,
                      encode_batch_size=0,
                      style_boost=None,
                      composition_boost=None,
                      enhance_tiles=1,
                      enhance_ratio=1.0,)

Source from the content-addressed store, hash-verified

226 to["patches_replace"]["attn2"][key].add(ipadapter_attention, **patch_kwargs)
227
228def ipadapter_execute(model,
229 ipadapter,
230 clipvision,
231 insightface=None,
232 image=None,
233 image_composition=None,
234 image_negative=None,
235 weight=1.0,
236 weight_composition=1.0,
237 weight_faceidv2=None,
238 weight_kolors=1.0,
239 weight_type="linear",
240 combine_embeds="concat",
241 start_at=0.0,
242 end_at=1.0,
243 attn_mask=None,
244 pos_embed=None,
245 neg_embed=None,
246 unfold_batch=False,
247 embeds_scaling='V only',
248 layer_weights=None,
249 encode_batch_size=0,
250 style_boost=None,
251 composition_boost=None,
252 enhance_tiles=1,
253 enhance_ratio=1.0,):
254 device = model_management.get_torch_device()
255 dtype = model_management.unet_dtype()
256 if dtype not in [torch.float32, torch.float16, torch.bfloat16]:
257 dtype = torch.float16 if model_management.should_use_fp16() else torch.float32
258
259 is_full = "proj.3.weight" in ipadapter["image_proj"]
260 is_portrait_unnorm = "portraitunnorm" in ipadapter
261 is_plus = (is_full or "latents" in ipadapter["image_proj"] or "perceiver_resampler.proj_in.weight" in ipadapter["image_proj"]) and not is_portrait_unnorm
262 output_cross_attention_dim = ipadapter["ip_adapter"]["1.to_k_ip.weight"].shape[1]
263 is_sdxl = output_cross_attention_dim == 2048
264 is_kwai_kolors_faceid = "perceiver_resampler.layers.0.0.to_out.weight" in ipadapter["image_proj"] and ipadapter["image_proj"]["perceiver_resampler.layers.0.0.to_out.weight"].shape[0] == 4096
265 is_faceidv2 = "faceidplusv2" in ipadapter or is_kwai_kolors_faceid
266 is_kwai_kolors = (is_sdxl and "layers.0.0.to_out.weight" in ipadapter["image_proj"] and ipadapter["image_proj"]["layers.0.0.to_out.weight"].shape[0] == 2048) or is_kwai_kolors_faceid
267 is_portrait = "proj.2.weight" in ipadapter["image_proj"] and not "proj.3.weight" in ipadapter["image_proj"] and not "0.to_q_lora.down.weight" in ipadapter["ip_adapter"] and not is_kwai_kolors_faceid
268 is_faceid = is_portrait or "0.to_q_lora.down.weight" in ipadapter["ip_adapter"] or is_portrait_unnorm or is_kwai_kolors_faceid
269
270 if is_faceid and not insightface:
271 raise Exception("insightface model is required for FaceID models")
272
273 if is_faceidv2:
274 weight_faceidv2 = weight_faceidv2 if weight_faceidv2 is not None else weight*2
275
276 if is_kwai_kolors_faceid:
277 cross_attention_dim = 4096
278 elif is_kwai_kolors:
279 cross_attention_dim = 2048
280 elif (is_plus and is_sdxl and not is_faceid) or is_portrait_unnorm:
281 cross_attention_dim = 1280
282 else:
283 cross_attention_dim = output_cross_attention_dim
284
285 if is_kwai_kolors_faceid:

Callers 4

apply_ipadapterMethod · 0.85
apply_ipadapterMethod · 0.85
apply_tiledMethod · 0.85
apply_ipadapterMethod · 0.85

Calls 9

tensor_to_imageFunction · 0.85
image_to_tensorFunction · 0.85
encode_image_maskedFunction · 0.85
tensor_to_sizeFunction · 0.85
IPAdapterClass · 0.85
set_model_patch_replaceFunction · 0.85
toMethod · 0.80
get_image_embedsMethod · 0.80

Tested by

no test coverage detected