From 2996e43ff71ca50f6e5b64676f998946d8041d19 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 27 Jan 2024 14:49:50 +0900 Subject: [PATCH 1/3] fix txt2img_upscale use force_enable_hr to set p.enable_hr = True allow Script.setup() have access to the correct value add a comment for p.txt2img_upscale --- modules/txt2img.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index 4efcb4c3..fc56b8a8 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -60,10 +60,10 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g assert len(gallery) > 0, 'No image to upscale' assert 0 <= gallery_index < len(gallery), f'Bad image index: {gallery_index}' - p = txt2img_create_processing(id_task, request, *args) - p.enable_hr = True + p = txt2img_create_processing(id_task, request, *args, force_enable_hr=True) p.batch_size = 1 p.n_iter = 1 + # txt2img_upscale attribute that signifies this is called by txt2img_upscale p.txt2img_upscale = True geninfo = json.loads(generation_info) From 486aeda3a75ed20e75d85d6ae6845d66d1cbe1de Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 27 Jan 2024 19:34:07 +0900 Subject: [PATCH 2/3] fix CLIP Interrogator topN regex Co-Authored-By: Martin Rizzo <60830236+martin-rizzo@users.noreply.github.com> --- modules/interrogate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/interrogate.py b/modules/interrogate.py index 35a627ca..c93e7aa8 100644 --- a/modules/interrogate.py +++ b/modules/interrogate.py @@ -17,7 +17,7 @@ clip_model_name = 'ViT-L/14' Category = namedtuple("Category", ["name", "topn", "items"]) -re_topn = re.compile(r"\.top(\d+)\.") +re_topn = re.compile(r"\.top(\d+)$") def category_types(): return [f.stem for f in Path(shared.interrogator.content_dir).glob('*.txt')] From dc46caa51c4a510043c48d0389111089f98b2fab Mon Sep 17 00:00:00 2001 From: lllyasviel Date: Sat, 27 Jan 2024 09:45:21 -0800 Subject: [PATCH 3/3] backend --- ldm_patched/contrib/external_latent.py | 24 +++++++++++++++++++ .../contrib/external_post_processing.py | 1 + ldm_patched/contrib/external_stable3d.py | 2 +- ldm_patched/modules/args_parser.py | 4 ++-- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ldm_patched/contrib/external_latent.py b/ldm_patched/contrib/external_latent.py index c6f874e1..6d753d0f 100644 --- a/ldm_patched/contrib/external_latent.py +++ b/ldm_patched/contrib/external_latent.py @@ -124,10 +124,34 @@ class LatentBatch: samples_out["batch_index"] = samples1.get("batch_index", [x for x in range(0, s1.shape[0])]) + samples2.get("batch_index", [x for x in range(0, s2.shape[0])]) return (samples_out,) +class LatentBatchSeedBehavior: + @classmethod + def INPUT_TYPES(s): + return {"required": { "samples": ("LATENT",), + "seed_behavior": (["random", "fixed"],),}} + + RETURN_TYPES = ("LATENT",) + FUNCTION = "op" + + CATEGORY = "latent/advanced" + + def op(self, samples, seed_behavior): + samples_out = samples.copy() + latent = samples["samples"] + if seed_behavior == "random": + if 'batch_index' in samples_out: + samples_out.pop('batch_index') + elif seed_behavior == "fixed": + batch_number = samples_out.get("batch_index", [0])[0] + samples_out["batch_index"] = [batch_number] * latent.shape[0] + + return (samples_out,) + NODE_CLASS_MAPPINGS = { "LatentAdd": LatentAdd, "LatentSubtract": LatentSubtract, "LatentMultiply": LatentMultiply, "LatentInterpolate": LatentInterpolate, "LatentBatch": LatentBatch, + "LatentBatchSeedBehavior": LatentBatchSeedBehavior, } diff --git a/ldm_patched/contrib/external_post_processing.py b/ldm_patched/contrib/external_post_processing.py index 432c53fb..93cb1212 100644 --- a/ldm_patched/contrib/external_post_processing.py +++ b/ldm_patched/contrib/external_post_processing.py @@ -35,6 +35,7 @@ class Blend: CATEGORY = "image/postprocessing" def blend_images(self, image1: torch.Tensor, image2: torch.Tensor, blend_factor: float, blend_mode: str): + image2 = image2.to(image1.device) if image1.shape != image2.shape: image2 = image2.permute(0, 3, 1, 2) image2 = ldm_patched.modules.utils.common_upscale(image2, image1.shape[2], image1.shape[1], upscale_method='bicubic', crop='center') diff --git a/ldm_patched/contrib/external_stable3d.py b/ldm_patched/contrib/external_stable3d.py index e56cd0fa..bae2623f 100644 --- a/ldm_patched/contrib/external_stable3d.py +++ b/ldm_patched/contrib/external_stable3d.py @@ -48,7 +48,7 @@ class StableZero123_Conditioning: encode_pixels = pixels[:,:,:,:3] t = vae.encode(encode_pixels) cam_embeds = camera_embeddings(elevation, azimuth) - cond = torch.cat([pooled, cam_embeds.repeat((pooled.shape[0], 1, 1))], dim=-1) + cond = torch.cat([pooled, cam_embeds.to(pooled.device).repeat((pooled.shape[0], 1, 1))], dim=-1) positive = [[cond, {"concat_latent_image": t}]] negative = [[torch.zeros_like(pooled), {"concat_latent_image": torch.zeros_like(t)}]] diff --git a/ldm_patched/modules/args_parser.py b/ldm_patched/modules/args_parser.py index e5b84dc1..a0d32c7a 100644 --- a/ldm_patched/modules/args_parser.py +++ b/ldm_patched/modules/args_parser.py @@ -33,8 +33,8 @@ class EnumAction(argparse.Action): parser = argparse.ArgumentParser() -parser.add_argument("--listen", type=str, default="127.0.0.1", metavar="IP", nargs="?", const="0.0.0.0") -parser.add_argument("--port", type=int, default=8188) +#parser.add_argument("--listen", type=str, default="127.0.0.1", metavar="IP", nargs="?", const="0.0.0.0") +#parser.add_argument("--port", type=int, default=8188) parser.add_argument("--disable-header-check", type=str, default=None, metavar="ORIGIN", nargs="?", const="*") parser.add_argument("--web-upload-size", type=float, default=100)