diff --git a/hordelib/horde.py b/hordelib/horde.py index 76ef9d90..c2f18972 100644 --- a/hordelib/horde.py +++ b/hordelib/horde.py @@ -1041,6 +1041,8 @@ def _final_pipeline_adjustments(self, payload, pipeline_data) -> tuple[dict, lis self.generator.reconnect_input(pipeline_data, "layer_diffuse_apply.model", "model_loader") self.generator.reconnect_input(pipeline_data, "output_image.images", "layer_diffuse_decode_rgba") self.generator.reconnect_input(pipeline_data, "layer_diffuse_decode_rgba.images", "vae_decode") + if payload.get("hires_fix") is True: + self.generator.reconnect_input(pipeline_data, "upscale_sampler.model", "layer_diffuse_apply") if model_details.get("baseline") == "stable diffusion 1": pipeline_params["layer_diffuse_apply.config"] = "SD15, Attention Injection, attn_sharing" pipeline_params["layer_diffuse_decode_rgba.sd_version"] = "SD15" diff --git a/hordelib/pipeline_designs/pipeline_stable_diffusion.json b/hordelib/pipeline_designs/pipeline_stable_diffusion.json index d68daa96..6052bc37 100644 --- a/hordelib/pipeline_designs/pipeline_stable_diffusion.json +++ b/hordelib/pipeline_designs/pipeline_stable_diffusion.json @@ -1,6 +1,6 @@ { - "last_node_id": 15, - "last_link_id": 23, + "last_node_id": 17, + "last_link_id": 36, "nodes": [ { "id": 7, @@ -14,7 +14,7 @@ "1": 90.3333740234375 }, "flags": {}, - "order": 6, + "order": 8, "mode": 0, "inputs": [ { @@ -54,7 +54,7 @@ "1": 83.00006103515625 }, "flags": {}, - "order": 5, + "order": 7, "mode": 0, "inputs": [ { @@ -93,7 +93,7 @@ "1": 58 }, "flags": {}, - "order": 3, + "order": 5, "mode": 0, "inputs": [ { @@ -133,13 +133,13 @@ "1": 400 }, "flags": {}, - "order": 10, + "order": 12, "mode": 0, "inputs": [ { "name": "images", "type": "IMAGE", - "link": 21 + "link": 36 } ], "title": "output_image", @@ -148,6 +148,84 @@ "ComfyUI" ] }, + { + "id": 15, + "type": "RepeatImageBatch", + "pos": [ + 257, + 1026 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 22 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 23 + ], + "shape": 3, + "slot_index": 0 + } + ], + "title": "repeat_image_batch", + "properties": { + "Node name for S&R": "RepeatImageBatch" + }, + "widgets_values": [ + 1 + ] + }, + { + "id": 11, + "type": "LoadImage", + "pos": [ + -91, + 768 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 22 + ], + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null + } + ], + "title": "image_loader", + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "example.png", + "image" + ] + }, { "id": 12, "type": "VAEEncode", @@ -160,7 +238,7 @@ "1": 46 }, "flags": {}, - "order": 7, + "order": 6, "mode": 0, "inputs": [ { @@ -188,114 +266,180 @@ } }, { - "id": 5, - "type": "EmptyLatentImage", + "id": 3, + "type": "KSampler", "pos": [ - 575, - 565 + 1019, + 107 ], "size": { "0": 315, - "1": 106 + "1": 262 }, "flags": {}, - "order": 1, + "order": 9, "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 35 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 4 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 6 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 34 + } + ], "outputs": [ { "name": "LATENT", "type": "LATENT", "links": [ - 18 + 20, + 24 ], "slot_index": 0 } ], - "title": "empty_latent_image", + "title": "sampler", "properties": { - "Node name for S&R": "EmptyLatentImage" + "Node name for S&R": "KSampler" }, "widgets_values": [ - 512, - 512, - 1 + 283224582220517, + "randomize", + 20, + 8, + "euler", + "normal", + 0.8 ] }, { - "id": 11, - "type": "LoadImage", + "id": 16, + "type": "LayeredDiffusionApply", "pos": [ - -91, - 768 - ], - "size": [ - 315, - 314 + 597, + 254 ], + "size": { + "0": 315, + "1": 82 + }, "flags": {}, - "order": 2, + "order": 4, "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 26 + } + ], "outputs": [ { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 22 - ], + "name": "MODEL", + "type": "MODEL", + "links": [], + "shape": 3, "slot_index": 0 - }, - { - "name": "MASK", - "type": "MASK", - "links": null } ], - "title": "image_loader", + "title": "layer_diffuse_apply", "properties": { - "Node name for S&R": "LoadImage" + "Node name for S&R": "LayeredDiffusionApply" }, "widgets_values": [ - "example.png", - "image" + "SD15, Attention Injection, attn_sharing", + 1 ] }, { - "id": 15, - "type": "RepeatImageBatch", + "id": 17, + "type": "LayeredDiffusionDecodeRGBA", "pos": [ - 257, - 1026 + 1621, + 234 ], "size": { "0": 315, - "1": 58 + "1": 102 }, "flags": {}, - "order": 4, + "order": 11, "mode": 0, "inputs": [ { - "name": "image", + "name": "samples", + "type": "LATENT", + "link": 24 + }, + { + "name": "images", "type": "IMAGE", - "link": 22 + "link": 27 } ], "outputs": [ { "name": "IMAGE", "type": "IMAGE", + "links": [], + "shape": 3, + "slot_index": 0 + } + ], + "title": "layer_diffuse_decode_rgba", + "properties": { + "Node name for S&R": "LayeredDiffusionDecodeRGBA" + }, + "widgets_values": [ + "SD15", + 16 + ] + }, + { + "id": 5, + "type": "EmptyLatentImage", + "pos": [ + 575, + 565 + ], + "size": { + "0": 315, + "1": 106 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", "links": [ - 23 + 34 ], - "shape": 3, "slot_index": 0 } ], - "title": "repeat_image_batch", + "title": "empty_latent_image", "properties": { - "Node name for S&R": "RepeatImageBatch" + "Node name for S&R": "EmptyLatentImage" }, "widgets_values": [ + 512, + 512, 1 ] }, @@ -311,14 +455,15 @@ "1": 98 }, "flags": {}, - "order": 0, + "order": 2, "mode": 0, "outputs": [ { "name": "MODEL", "type": "MODEL", "links": [ - 1 + 26, + 35 ], "slot_index": 0 }, @@ -348,66 +493,6 @@ "Deliberate.ckpt" ] }, - { - "id": 3, - "type": "KSampler", - "pos": [ - 1019, - 107 - ], - "size": { - "0": 315, - "1": 262 - }, - "flags": {}, - "order": 8, - "mode": 0, - "inputs": [ - { - "name": "model", - "type": "MODEL", - "link": 1 - }, - { - "name": "positive", - "type": "CONDITIONING", - "link": 4 - }, - { - "name": "negative", - "type": "CONDITIONING", - "link": 6 - }, - { - "name": "latent_image", - "type": "LATENT", - "link": 18 - } - ], - "outputs": [ - { - "name": "LATENT", - "type": "LATENT", - "links": [ - 20 - ], - "slot_index": 0 - } - ], - "title": "sampler", - "properties": { - "Node name for S&R": "KSampler" - }, - "widgets_values": [ - 62706718437716, - "randomize", - 20, - 8, - "euler", - "normal", - 1 - ] - }, { "id": 14, "type": "VAEDecode", @@ -420,7 +505,7 @@ "1": 46 }, "flags": {}, - "order": 9, + "order": 10, "mode": 0, "inputs": [ { @@ -439,7 +524,8 @@ "name": "IMAGE", "type": "IMAGE", "links": [ - 21 + 27, + 36 ], "slot_index": 0 } @@ -451,14 +537,6 @@ } ], "links": [ - [ - 1, - 4, - 0, - 3, - 0, - "MODEL" - ], [ 4, 6, @@ -507,14 +585,6 @@ 1, "VAE" ], - [ - 18, - 5, - 0, - 3, - 3, - "LATENT" - ], [ 19, 4, @@ -531,14 +601,6 @@ 0, "LATENT" ], - [ - 21, - 14, - 0, - 9, - 0, - "IMAGE" - ], [ 22, 11, @@ -554,10 +616,66 @@ 12, 0, "IMAGE" + ], + [ + 24, + 3, + 0, + 17, + 0, + "LATENT" + ], + [ + 26, + 4, + 0, + 16, + 0, + "MODEL" + ], + [ + 27, + 14, + 0, + 17, + 1, + "IMAGE" + ], + [ + 34, + 5, + 0, + 3, + 3, + "LATENT" + ], + [ + 35, + 4, + 0, + 3, + 0, + "MODEL" + ], + [ + 36, + 14, + 0, + 9, + 0, + "IMAGE" ] ], "groups": [], "config": {}, - "extra": {}, + "extra": { + "ds": { + "scale": 0.8264462809917354, + "offset": [ + -271.8083588837497, + 68.64949882587337 + ] + } + }, "version": 0.4 } diff --git a/hordelib/pipeline_designs/pipeline_stable_diffusion_hires_fix.json b/hordelib/pipeline_designs/pipeline_stable_diffusion_hires_fix.json index df6843b0..de9a550a 100644 --- a/hordelib/pipeline_designs/pipeline_stable_diffusion_hires_fix.json +++ b/hordelib/pipeline_designs/pipeline_stable_diffusion_hires_fix.json @@ -1,6 +1,6 @@ { - "last_node_id": 22, - "last_link_id": 36, + "last_node_id": 24, + "last_link_id": 45, "nodes": [ { "id": 12, @@ -14,13 +14,13 @@ "1": 468.13226318359375 }, "flags": {}, - "order": 12, + "order": 14, "mode": 0, "inputs": [ { "name": "images", "type": "IMAGE", - "link": 34 + "link": 43 } ], "title": "output_image", @@ -41,7 +41,7 @@ "1": 58 }, "flags": {}, - "order": 3, + "order": 5, "mode": 0, "inputs": [ { @@ -82,7 +82,7 @@ "1": 180.6060791015625 }, "flags": {}, - "order": 6, + "order": 8, "mode": 0, "inputs": [ { @@ -122,7 +122,7 @@ "1": 164.31304931640625 }, "flags": {}, - "order": 5, + "order": 7, "mode": 0, "inputs": [ { @@ -162,7 +162,7 @@ "1": 130 }, "flags": {}, - "order": 9, + "order": 10, "mode": 0, "inputs": [ { @@ -237,13 +237,13 @@ "1": 262 }, "flags": {}, - "order": 8, + "order": 9, "mode": 0, "inputs": [ { "name": "model", "type": "MODEL", - "link": 18 + "link": 44 }, { "name": "positive", @@ -276,7 +276,7 @@ "Node name for S&R": "KSampler" }, "widgets_values": [ - 458841867575267, + 709052412707182, "randomize", 12, 8, @@ -297,7 +297,7 @@ "1": 46 }, "flags": {}, - "order": 7, + "order": 6, "mode": 0, "inputs": [ { @@ -325,53 +325,81 @@ } }, { - "id": 16, - "type": "CheckpointLoaderSimple", + "id": 18, + "type": "LoadImage", "pos": [ - -420, - 334 + 261, + 934 ], "size": { "0": 315, - "1": 98 + "1": 314 }, "flags": {}, "order": 1, "mode": 0, "outputs": [ { - "name": "MODEL", - "type": "MODEL", + "name": "IMAGE", + "type": "IMAGE", "links": [ - 18, - 23 + 35 ], "slot_index": 0 }, { - "name": "CLIP", - "type": "CLIP", - "links": [ - 24 - ], - "slot_index": 1 - }, + "name": "MASK", + "type": "MASK", + "links": null + } + ], + "title": "image_loader", + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "example.png", + "image" + ] + }, + { + "id": 22, + "type": "RepeatImageBatch", + "pos": [ + 624, + 934 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ { - "name": "VAE", - "type": "VAE", + "name": "image", + "type": "IMAGE", + "link": 35 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", "links": [ - 28, - 32 + 36 ], - "slot_index": 2 + "shape": 3, + "slot_index": 0 } ], - "title": "model_loader", + "title": "repeat_image_batch", "properties": { - "Node name for S&R": "CheckpointLoaderSimple" + "Node name for S&R": "RepeatImageBatch" }, "widgets_values": [ - "Deliberate.ckpt" + 1 ] }, { @@ -386,13 +414,13 @@ "1": 262 }, "flags": {}, - "order": 10, + "order": 11, "mode": 0, "inputs": [ { "name": "model", "type": "MODEL", - "link": 23, + "link": 45, "slot_index": 0 }, { @@ -419,7 +447,8 @@ "name": "LATENT", "type": "LATENT", "links": [ - 33 + 33, + 42 ], "slot_index": 0 } @@ -429,7 +458,7 @@ "Node name for S&R": "KSampler" }, "widgets_values": [ - 65484213431324, + 932988885298999, "randomize", 14, 8, @@ -438,6 +467,50 @@ 0.5 ] }, + { + "id": 24, + "type": "LayeredDiffusionDecodeRGBA", + "pos": [ + 2135, + -102 + ], + "size": { + "0": 315, + "1": 102 + }, + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 42 + }, + { + "name": "images", + "type": "IMAGE", + "link": 40 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [], + "shape": 3, + "slot_index": 0 + } + ], + "title": "layer_diffuse_decode_rgba", + "properties": { + "Node name for S&R": "LayeredDiffusionDecodeRGBA" + }, + "widgets_values": [ + "SD15", + 16 + ] + }, { "id": 21, "type": "VAEDecode", @@ -450,7 +523,7 @@ "1": 46 }, "flags": {}, - "order": 11, + "order": 12, "mode": 0, "inputs": [ { @@ -469,7 +542,8 @@ "name": "IMAGE", "type": "IMAGE", "links": [ - 34 + 40, + 43 ], "slot_index": 0 } @@ -480,80 +554,92 @@ } }, { - "id": 18, - "type": "LoadImage", + "id": 16, + "type": "CheckpointLoaderSimple", "pos": [ - 261, - 934 - ], - "size": [ - 315, - 314 + -420, + 334 ], + "size": { + "0": 315, + "1": 98 + }, "flags": {}, "order": 2, "mode": 0, "outputs": [ { - "name": "IMAGE", - "type": "IMAGE", + "name": "MODEL", + "type": "MODEL", "links": [ - 35 + 37, + 44, + 45 ], "slot_index": 0 }, { - "name": "MASK", - "type": "MASK", - "links": null + "name": "CLIP", + "type": "CLIP", + "links": [ + 24 + ], + "slot_index": 1 + }, + { + "name": "VAE", + "type": "VAE", + "links": [ + 28, + 32 + ], + "slot_index": 2 } ], - "title": "image_loader", + "title": "model_loader", "properties": { - "Node name for S&R": "LoadImage" + "Node name for S&R": "CheckpointLoaderSimple" }, "widgets_values": [ - "example.png", - "image" + "Deliberate.ckpt" ] }, { - "id": 22, - "type": "RepeatImageBatch", + "id": 23, + "type": "LayeredDiffusionApply", "pos": [ - 624, - 934 + 443, + -13 ], "size": { "0": 315, - "1": 58 + "1": 82 }, "flags": {}, "order": 4, "mode": 0, "inputs": [ { - "name": "image", - "type": "IMAGE", - "link": 35 + "name": "model", + "type": "MODEL", + "link": 37 } ], "outputs": [ { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 36 - ], + "name": "MODEL", + "type": "MODEL", + "links": [], "shape": 3, "slot_index": 0 } ], - "title": "repeat_image_batch", + "title": "layer_diffuse_apply", "properties": { - "Node name for S&R": "RepeatImageBatch" + "Node name for S&R": "LayeredDiffusionApply" }, "widgets_values": [ + "SD15, Attention Injection, attn_sharing", 1 ] } @@ -607,22 +693,6 @@ 3, "LATENT" ], - [ - 18, - 16, - 0, - 3, - 0, - "MODEL" - ], - [ - 23, - 16, - 0, - 11, - 0, - "MODEL" - ], [ 24, 16, @@ -679,14 +749,6 @@ 0, "LATENT" ], - [ - 34, - 21, - 0, - 12, - 0, - "IMAGE" - ], [ 35, 18, @@ -702,6 +764,54 @@ 19, 0, "IMAGE" + ], + [ + 37, + 16, + 0, + 23, + 0, + "MODEL" + ], + [ + 40, + 21, + 0, + 24, + 1, + "IMAGE" + ], + [ + 42, + 11, + 0, + 24, + 0, + "LATENT" + ], + [ + 43, + 21, + 0, + 12, + 0, + "IMAGE" + ], + [ + 44, + 16, + 0, + 3, + 0, + "MODEL" + ], + [ + 45, + 16, + 0, + 11, + 0, + "MODEL" ] ], "groups": [ @@ -751,6 +861,14 @@ } ], "config": {}, - "extra": {}, + "extra": { + "ds": { + "scale": 0.683013455365071, + "offset": [ + -1143.7145712697502, + 509.85654565587373 + ] + } + }, "version": 0.4 } diff --git a/hordelib/pipelines/pipeline_stable_diffusion_hires_fix.json b/hordelib/pipelines/pipeline_stable_diffusion_hires_fix.json index fed95de1..8d0e1c04 100644 --- a/hordelib/pipelines/pipeline_stable_diffusion_hires_fix.json +++ b/hordelib/pipelines/pipeline_stable_diffusion_hires_fix.json @@ -1,7 +1,7 @@ { "3": { "inputs": { - "seed": 458841867575267, + "seed": 709052412707182, "steps": 12, "cfg": 8, "sampler_name": "dpmpp_sde", @@ -84,7 +84,7 @@ }, "11": { "inputs": { - "seed": 65484213431324, + "seed": 932988885298999, "steps": 14, "cfg": 8, "sampler_name": "dpmpp_2m", @@ -201,5 +201,37 @@ "_meta": { "title": "repeat_image_batch" } + }, + "23": { + "inputs": { + "config": "SD15, Attention Injection, attn_sharing", + "weight": 1, + "model": [ + "16", + 0 + ] + }, + "class_type": "LayeredDiffusionApply", + "_meta": { + "title": "layer_diffuse_apply" + } + }, + "24": { + "inputs": { + "sd_version": "SD15", + "sub_batch_size": 16, + "samples": [ + "11", + 0 + ], + "images": [ + "21", + 0 + ] + }, + "class_type": "LayeredDiffusionDecodeRGBA", + "_meta": { + "title": "layer_diffuse_decode_rgba" + } } } diff --git a/tests/test_horde_inference_layerdiffusion.py b/tests/test_horde_inference_layerdiffusion.py index c4deec27..8e95814a 100644 --- a/tests/test_horde_inference_layerdiffusion.py +++ b/tests/test_horde_inference_layerdiffusion.py @@ -4,6 +4,8 @@ from hordelib.horde import HordeLib +from .testing_shared_functions import check_single_inference_image_similarity + class TestHordeInferenceTransparent: def test_layerdiffuse_sd15( @@ -90,3 +92,40 @@ def test_layerdiffuse_sdxl( image_result.image.save(f"images/{img_filename}", quality=100) img_pairs_to_check.append((f"images_expected/{img_filename}", image_result.image)) + + def test_layerdiffusion_hires_fix( + self, + hordelib_instance: HordeLib, + stable_diffusion_model_name_for_testing: str, + ): + data = { + "sampler_name": "k_dpmpp_2m", + "cfg_scale": 7.5, + "denoising_strength": 1.0, + "seed": 123456789, + "height": 768, + "width": 768, + "karras": False, + "tiling": False, + "hires_fix": True, + "transparent": True, + "clip_skip": 1, + "control_type": None, + "image_is_control": False, + "return_control_map": False, + "prompt": "an ancient llamia monster", + "ddim_steps": 25, + "n_iter": 1, + "model": stable_diffusion_model_name_for_testing, + } + pil_image = hordelib_instance.basic_inference_single_image(data).image + assert pil_image is not None + assert isinstance(pil_image, Image.Image) + + img_filename = "layer_diffusion_hires_fix.png" + pil_image.save(f"images/{img_filename}", quality=100) + + assert check_single_inference_image_similarity( + f"images_expected/{img_filename}", + pil_image, + )