From 1a4af0bc29002b667ae982bd54c489b0cb1753fd Mon Sep 17 00:00:00 2001 From: laksjdjf Date: Wed, 8 Nov 2023 19:48:24 +0900 Subject: [PATCH] f --- lcm_sampler.py | 3 +- lcm_ssd1b_anime.json | 653 +++++++++++++++++++++++++++++++++++++++++++ taesd_decoder.py | 12 +- 3 files changed, 661 insertions(+), 7 deletions(-) create mode 100644 lcm_ssd1b_anime.json diff --git a/lcm_sampler.py b/lcm_sampler.py index 8ab2d35..f637f81 100644 --- a/lcm_sampler.py +++ b/lcm_sampler.py @@ -1,5 +1,6 @@ from comfy.samplers import * from comfy.k_diffusion.sampling import generic_step_sampler +import math def ksampler_lcm(sampler_name, eta, extra_options={}, inpaint_options={}): class KSAMPLER(Sampler): @@ -39,7 +40,7 @@ def LCMSampler_outer(eta): mu = (x - (1 - alpha_cumprod).sqrt() * noise) / alpha_cumprod.sqrt() if sigma_prev > 0: # this is not mathematically correct, but eta=1 means lcm_sampler and eta=0 means ddim(euler). - noise_interp = (1 - eta) * noise + eta * noise_sampler(sigma, sigma_prev) + noise_interp = math.sqrt(1 - eta) * noise + math.sqrt(eta) * noise_sampler(sigma, sigma_prev) mu = alpha_cumprod_prev.sqrt() * mu + (1 - alpha_cumprod_prev).sqrt() * noise_interp return mu return LCMSampler_step diff --git a/lcm_ssd1b_anime.json b/lcm_ssd1b_anime.json new file mode 100644 index 0000000..5cfdbdd --- /dev/null +++ b/lcm_ssd1b_anime.json @@ -0,0 +1,653 @@ +{ + "last_node_id": 137, + "last_link_id": 365, + "nodes": [ + { + "id": 4, + "type": "CheckpointLoaderSimple", + "pos": [ + 125, + 85 + ], + "size": { + "0": 315, + "1": 98 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 313, + 349 + ], + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 353, + 354, + 355 + ], + "slot_index": 1 + }, + { + "name": "VAE", + "type": "VAE", + "links": [], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "CheckpointLoaderSimple" + }, + "widgets_values": [ + "ssd-1b-anime-v2.safetensors" + ] + }, + { + "id": 37, + "type": "CLIPTextEncode", + "pos": [ + 498, + 93 + ], + "size": { + "0": 297.1368103027344, + "1": 122.81802368164062 + }, + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 353 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 188 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "masterpiece, best quality, nsfw, 1girl, solo, (blush:1.5), parted lip, black hair, blue eyes, white shirt, short sleeves, midriff, navel, shorts, room,sunset" + ] + }, + { + "id": 132, + "type": "CLIPTextEncode", + "pos": [ + 499, + 300 + ], + "size": { + "0": 297.1368103027344, + "1": 122.81802368164062 + }, + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 354 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 346 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "Negative prompts do not apply." + ] + }, + { + "id": 123, + "type": "LoraLoader", + "pos": [ + 132, + 237 + ], + "size": { + "0": 315, + "1": 126 + }, + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 349 + }, + { + "name": "clip", + "type": "CLIP", + "link": 355 + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 356 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 357 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoraLoader" + }, + "widgets_values": [ + "ssd-1b-anime-cfgdistill.safetensors", + 1, + 1 + ] + }, + { + "id": 134, + "type": "TAESDLoader", + "pos": [ + 120, + 609 + ], + "size": { + "0": 315, + "1": 82 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "VAE", + "type": "VAE", + "links": [ + 350 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "TAESDLoader" + }, + "widgets_values": [ + "taesdxl_decoder.pth", + 16 + ] + }, + { + "id": 78, + "type": "SamplerCustom", + "pos": [ + 842, + 264 + ], + "size": { + "0": 355.20001220703125, + "1": 442 + }, + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 348 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 188 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 346 + }, + { + "name": "sampler", + "type": "SAMPLER", + "link": 359 + }, + { + "name": "sigmas", + "type": "SIGMAS", + "link": 279 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 245 + } + ], + "outputs": [ + { + "name": "output", + "type": "LATENT", + "links": [], + "shape": 3, + "slot_index": 0 + }, + { + "name": "denoised_output", + "type": "LATENT", + "links": [ + 365 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "SamplerCustom" + }, + "widgets_values": [ + true, + 4545, + "fixed", + 1 + ] + }, + { + "id": 5, + "type": "EmptyLatentImage", + "pos": [ + 836, + 84 + ], + "size": { + "0": 316.51568603515625, + "1": 106 + }, + "flags": {}, + "order": 2, + "mode": 0, + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 245 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 832, + 1216, + 1 + ] + }, + { + "id": 135, + "type": "VAEDecode", + "pos": [ + 1201, + 86 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 365 + }, + { + "name": "vae", + "type": "VAE", + "link": 350 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 352 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 61, + "type": "SaveImage", + "pos": [ + 1232, + 191 + ], + "size": { + "0": 906.6248168945312, + "1": 1172.5723876953125 + }, + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 352 + } + ], + "properties": {}, + "widgets_values": [ + "ComfyUI" + ] + }, + { + "id": 120, + "type": "BasicScheduler", + "pos": [ + 492, + 607 + ], + "size": { + "0": 315, + "1": 82 + }, + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 313 + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 279 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "BasicScheduler" + }, + "widgets_values": [ + "normal", + 4 + ] + }, + { + "id": 133, + "type": "SamplerLCM", + "pos": [ + 497, + 490 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 3, + "mode": 0, + "outputs": [ + { + "name": "SAMPLER", + "type": "SAMPLER", + "links": [ + 359 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "SamplerLCM" + }, + "widgets_values": [ + 1 + ] + }, + { + "id": 92, + "type": "LoraLoader", + "pos": [ + 125, + 425 + ], + "size": { + "0": 315, + "1": 126 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 356 + }, + { + "name": "clip", + "type": "CLIP", + "link": 357 + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 348 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoraLoader" + }, + "widgets_values": [ + "ssd-1b-anime-lcm.safetensors", + 1, + 1 + ] + } + ], + "links": [ + [ + 188, + 37, + 0, + 78, + 1, + "CONDITIONING" + ], + [ + 245, + 5, + 0, + 78, + 5, + "LATENT" + ], + [ + 279, + 120, + 0, + 78, + 4, + "SIGMAS" + ], + [ + 313, + 4, + 0, + 120, + 0, + "MODEL" + ], + [ + 346, + 132, + 0, + 78, + 2, + "CONDITIONING" + ], + [ + 348, + 92, + 0, + 78, + 0, + "MODEL" + ], + [ + 349, + 4, + 0, + 123, + 0, + "MODEL" + ], + [ + 350, + 134, + 0, + 135, + 1, + "VAE" + ], + [ + 352, + 135, + 0, + 61, + 0, + "IMAGE" + ], + [ + 353, + 4, + 1, + 37, + 0, + "CLIP" + ], + [ + 354, + 4, + 1, + 132, + 0, + "CLIP" + ], + [ + 355, + 4, + 1, + 123, + 1, + "CLIP" + ], + [ + 356, + 123, + 0, + 92, + 0, + "MODEL" + ], + [ + 357, + 123, + 1, + 92, + 1, + "CLIP" + ], + [ + 359, + 133, + 0, + 78, + 3, + "SAMPLER" + ], + [ + 365, + 78, + 1, + 135, + 0, + "LATENT" + ] + ], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 + } \ No newline at end of file diff --git a/taesd_decoder.py b/taesd_decoder.py index d0fa4fa..54eac06 100644 --- a/taesd_decoder.py +++ b/taesd_decoder.py @@ -15,16 +15,16 @@ class TAESDDecoder: @torch.no_grad() def decode(self, latent): - B = latent['samples'].shape[0] + B = latent.shape[0] + latent = latent.to(model_management.get_torch_device()) * self.scale x_sample = [] for i in range(0, B, self.max_batch_size): - x_sample.append(self.taesd.decoder((latent['samples'][i:i + self.max_batch_size].to(model_management.get_torch_device()) * self.scale)).detach()) + x_sample.append(self.taesd.decoder(latent[i:i + self.max_batch_size]).detach()) x_sample = torch.cat(x_sample, dim=0) x_sample = x_sample.sub(0.5).mul(2) x_sample = torch.clamp((x_sample + 1.0) / 2.0, min=0.0, max=1.0) - x_sample = x_sample.permute(0, 2, 3, 1) - - return (x_sample, ) + x_sample = x_sample.permute(0, 2, 3, 1).cpu() + return x_sample class TAESDLoader: @@ -46,7 +46,7 @@ class TAESDLoader: RETURN_TYPES = ("VAE",) FUNCTION = "load" OUTPUT_IS_LIST = (False,) - CATEGORY = "loader" + CATEGORY = "loaders" def __init__(self): self.taesd = None