From 53813b21bed7bfa00e9db43050906e95f69c6a7e Mon Sep 17 00:00:00 2001 From: matt3o Date: Sun, 7 Apr 2024 09:49:23 +0200 Subject: [PATCH] minor bug fixes --- CrossAttentionPatch.py | 2 +- IPAdapterPlus.py | 6 +- README.md | 1 + examples/ipadapter_style_composition.json | 612 ++++++++++++++++++++++ 4 files changed, 617 insertions(+), 4 deletions(-) create mode 100644 examples/ipadapter_style_composition.json diff --git a/CrossAttentionPatch.py b/CrossAttentionPatch.py index 14aae37..e3a5ee9 100644 --- a/CrossAttentionPatch.py +++ b/CrossAttentionPatch.py @@ -84,7 +84,7 @@ class CrossAttentionPatch: weight = weight[t_idx] - if t_idx in cond_alt: + if cond_alt is not None and t_idx in cond_alt: cond = cond_alt[t_idx] del cond_alt diff --git a/IPAdapterPlus.py b/IPAdapterPlus.py index bba38ff..efb8fc8 100644 --- a/IPAdapterPlus.py +++ b/IPAdapterPlus.py @@ -161,8 +161,8 @@ def ipadapter_execute(model, neg_embed=None, unfold_batch=False, embeds_scaling='V only'): - dtype = torch.float16 if model_management.should_use_fp16() else torch.bfloat16 if model_management.should_use_bf16() else torch.float32 device = model_management.get_torch_device() + dtype = model_management.unet_dtype() is_full = "proj.3.weight" in ipadapter["image_proj"] 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"] @@ -324,8 +324,8 @@ def ipadapter_execute(model, del img_cond_embeds, img_uncond_embeds, img_comp_cond_embeds, face_cond_embeds - sigma_start = model.model.model_sampling.percent_to_sigma(start_at) - sigma_end = model.model.model_sampling.percent_to_sigma(end_at) + sigma_start = model.get_model_object("model_sampling").percent_to_sigma(start_at) + sigma_end = model.get_model_object("model_sampling").percent_to_sigma(end_at) patch_kwargs = { "ipadapter": ipa, diff --git a/README.md b/README.md index 930993d..0318dac 100644 --- a/README.md +++ b/README.md @@ -153,5 +153,6 @@ It's only thanks to generous sponsors that **the whole community** can enjoy ope - [IPAdapter](https://github.com/tencent-ailab/IP-Adapter/) - [InstantStyle](https://github.com/InstantStyle/InstantStyle) +- [B-Lora](https://github.com/yardenfren1996/B-LoRA/) - [ComfyUI](https://github.com/comfyanonymous/ComfyUI) - [laksjdjf](https://github.com/laksjdjf/) diff --git a/examples/ipadapter_style_composition.json b/examples/ipadapter_style_composition.json new file mode 100644 index 0000000..1e1791e --- /dev/null +++ b/examples/ipadapter_style_composition.json @@ -0,0 +1,612 @@ +{ + "last_node_id": 16, + "last_link_id": 25, + "nodes": [ + { + "id": 7, + "type": "CLIPTextEncode", + "pos": [ + 690, + 840 + ], + "size": { + "0": 425.27801513671875, + "1": 180.6060791015625 + }, + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 5 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 6 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "blurry, noisy, messy, lowres, jpeg, artifacts, ill, distorted, malformed" + ] + }, + { + "id": 11, + "type": "IPAdapterUnifiedLoader", + "pos": [ + 335, + 430 + ], + "size": { + "0": 315, + "1": 78 + }, + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 10 + }, + { + "name": "ipadapter", + "type": "IPADAPTER", + "link": null + } + ], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 21 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "ipadapter", + "type": "IPADAPTER", + "links": [ + 22 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "IPAdapterUnifiedLoader" + }, + "widgets_values": [ + "PLUS (high strength)" + ] + }, + { + "id": 12, + "type": "LoadImage", + "pos": [ + -102, + -46 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 25 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "black_car.jpg", + "image" + ] + }, + { + "id": 16, + "type": "LoadImage", + "pos": [ + 310, + -40 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 24 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "bw_texture_waves.jpg", + "image" + ] + }, + { + "id": 5, + "type": "EmptyLatentImage", + "pos": [ + 801, + 1097 + ], + "size": { + "0": 315, + "1": 106 + }, + "flags": {}, + "order": 2, + "mode": 0, + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 2 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 1024, + 1024, + 1 + ] + }, + { + "id": 6, + "type": "CLIPTextEncode", + "pos": [ + 690, + 610 + ], + "size": { + "0": 422.84503173828125, + "1": 164.31304931640625 + }, + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 3 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 4 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "sports car running fast on the highway\n\nhigh quality, detailed" + ] + }, + { + "id": 15, + "type": "IPAdapterStyleComposition", + "pos": [ + 772, + 219 + ], + "size": { + "0": 315, + "1": 322 + }, + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 21 + }, + { + "name": "ipadapter", + "type": "IPADAPTER", + "link": 22 + }, + { + "name": "image_style", + "type": "IMAGE", + "link": 24 + }, + { + "name": "image_composition", + "type": "IMAGE", + "link": 25 + }, + { + "name": "image_negative", + "type": "IMAGE", + "link": null + }, + { + "name": "attn_mask", + "type": "MASK", + "link": null + }, + { + "name": "clip_vision", + "type": "CLIP_VISION", + "link": null + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 23 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "IPAdapterStyleComposition" + }, + "widgets_values": [ + 1.2, + 1, + false, + "average", + 0, + 1, + "V only" + ] + }, + { + "id": 3, + "type": "KSampler", + "pos": [ + 1247, + 586 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 23 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 4 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 6 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 2 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 7 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 0, + "fixed", + 30, + 6.5, + "dpmpp_2m", + "karras", + 1 + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": [ + 1615, + 586 + ], + "size": { + "0": 140, + "1": 46 + }, + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": 8 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 9 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 9, + "type": "SaveImage", + "pos": [ + 1822, + 588 + ], + "size": [ + 691.0159878487498, + 716.6239849908982 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 9 + } + ], + "properties": {}, + "widgets_values": [ + "IPAdapter" + ] + }, + { + "id": 4, + "type": "CheckpointLoaderSimple", + "pos": [ + -72, + 657 + ], + "size": { + "0": 315, + "1": 98 + }, + "flags": {}, + "order": 3, + "mode": 0, + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 10 + ], + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 3, + 5 + ], + "slot_index": 1 + }, + { + "name": "VAE", + "type": "VAE", + "links": [ + 8 + ], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "CheckpointLoaderSimple" + }, + "widgets_values": [ + "sdxl/AlbedoBaseXL.safetensors" + ] + } + ], + "links": [ + [ + 2, + 5, + 0, + 3, + 3, + "LATENT" + ], + [ + 3, + 4, + 1, + 6, + 0, + "CLIP" + ], + [ + 4, + 6, + 0, + 3, + 1, + "CONDITIONING" + ], + [ + 5, + 4, + 1, + 7, + 0, + "CLIP" + ], + [ + 6, + 7, + 0, + 3, + 2, + "CONDITIONING" + ], + [ + 7, + 3, + 0, + 8, + 0, + "LATENT" + ], + [ + 8, + 4, + 2, + 8, + 1, + "VAE" + ], + [ + 9, + 8, + 0, + 9, + 0, + "IMAGE" + ], + [ + 10, + 4, + 0, + 11, + 0, + "MODEL" + ], + [ + 21, + 11, + 0, + 15, + 0, + "MODEL" + ], + [ + 22, + 11, + 1, + 15, + 1, + "IPADAPTER" + ], + [ + 23, + 15, + 0, + 3, + 0, + "MODEL" + ], + [ + 24, + 16, + 0, + 15, + 2, + "IMAGE" + ], + [ + 25, + 12, + 0, + 15, + 3, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 +} \ No newline at end of file