Commit
·
edc0c71
1
Parent(s):
3d00867
- .gitignore +1 -0
- modules/core.py +33 -7
.gitignore
CHANGED
|
@@ -2,6 +2,7 @@ __pycache__
|
|
| 2 |
*.ckpt
|
| 3 |
*.safetensors
|
| 4 |
*.pth
|
|
|
|
| 5 |
/repositories
|
| 6 |
/venv
|
| 7 |
/tmp
|
|
|
|
| 2 |
*.ckpt
|
| 3 |
*.safetensors
|
| 4 |
*.pth
|
| 5 |
+
!taesdxl_decoder.pth
|
| 6 |
/repositories
|
| 7 |
/venv
|
| 8 |
/tmp
|
modules/core.py
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
|
|
| 1 |
import random
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
import comfy.model_management
|
| 6 |
import comfy.sample
|
| 7 |
import comfy.utils
|
| 8 |
-
import latent_preview
|
| 9 |
|
| 10 |
from comfy.sd import load_checkpoint_guess_config
|
| 11 |
-
from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
|
| 12 |
|
| 13 |
|
| 14 |
opCLIPTextEncode = CLIPTextEncode()
|
|
@@ -45,6 +47,20 @@ def decode_vae(vae, latent_image):
|
|
| 45 |
return opVAEDecode.decode(samples=latent_image, vae=vae)[0]
|
| 46 |
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
@torch.no_grad()
|
| 49 |
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=9.0, sampler_name='euler_ancestral', scheduler='normal', denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False):
|
| 50 |
seed = seed if isinstance(seed, int) else random.randint(1, 2 ** 64)
|
|
@@ -66,21 +82,31 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=9.0, sa
|
|
| 66 |
if preview_format not in ["JPEG", "PNG"]:
|
| 67 |
preview_format = "JPEG"
|
| 68 |
|
| 69 |
-
previewer =
|
| 70 |
|
| 71 |
pbar = comfy.utils.ProgressBar(steps)
|
| 72 |
|
| 73 |
def callback(step, x0, x, total_steps):
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
|
| 80 |
denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step,
|
| 81 |
force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, seed=seed)
|
| 82 |
out = latent.copy()
|
| 83 |
out["samples"] = samples
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
return out
|
| 85 |
|
| 86 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
import random
|
| 3 |
+
import cv2
|
| 4 |
+
import einops
|
| 5 |
import torch
|
| 6 |
import numpy as np
|
| 7 |
|
| 8 |
import comfy.model_management
|
| 9 |
import comfy.sample
|
| 10 |
import comfy.utils
|
|
|
|
| 11 |
|
| 12 |
from comfy.sd import load_checkpoint_guess_config
|
| 13 |
+
from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
|
| 14 |
|
| 15 |
|
| 16 |
opCLIPTextEncode = CLIPTextEncode()
|
|
|
|
| 47 |
return opVAEDecode.decode(samples=latent_image, vae=vae)[0]
|
| 48 |
|
| 49 |
|
| 50 |
+
def get_previewer(device, latent_format):
|
| 51 |
+
from latent_preview import TAESD, TAESDPreviewerImpl
|
| 52 |
+
taesd_decoder_path = os.path.abspath(os.path.realpath(os.path.join("models", "vae_approx",
|
| 53 |
+
latent_format.taesd_decoder_name)))
|
| 54 |
+
|
| 55 |
+
if not os.path.exists(taesd_decoder_path):
|
| 56 |
+
print(f"Warning: TAESD previews enabled, but could not find {taesd_decoder_path}")
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
taesd = TAESD(None, taesd_decoder_path).to(device)
|
| 60 |
+
|
| 61 |
+
return taesd
|
| 62 |
+
|
| 63 |
+
|
| 64 |
@torch.no_grad()
|
| 65 |
def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=9.0, sampler_name='euler_ancestral', scheduler='normal', denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False):
|
| 66 |
seed = seed if isinstance(seed, int) else random.randint(1, 2 ** 64)
|
|
|
|
| 82 |
if preview_format not in ["JPEG", "PNG"]:
|
| 83 |
preview_format = "JPEG"
|
| 84 |
|
| 85 |
+
previewer = get_previewer(device, model.model.latent_format)
|
| 86 |
|
| 87 |
pbar = comfy.utils.ProgressBar(steps)
|
| 88 |
|
| 89 |
def callback(step, x0, x, total_steps):
|
| 90 |
+
if previewer and step % 3 == 0:
|
| 91 |
+
with torch.no_grad():
|
| 92 |
+
x_sample = previewer.decoder(x0).detach() * 255.0
|
| 93 |
+
x_sample = einops.rearrange(x_sample, 'b c h w -> b h w c')
|
| 94 |
+
x_sample = x_sample.cpu().numpy()[..., ::-1].copy().clip(0, 255).astype(np.uint8)
|
| 95 |
+
|
| 96 |
+
for i, s in enumerate(x_sample):
|
| 97 |
+
cv2.imshow(f'Preview {i}', s)
|
| 98 |
+
cv2.waitKey(1)
|
| 99 |
+
pbar.update_absolute(step + 1, total_steps, None)
|
| 100 |
|
| 101 |
samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
|
| 102 |
denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step,
|
| 103 |
force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, seed=seed)
|
| 104 |
out = latent.copy()
|
| 105 |
out["samples"] = samples
|
| 106 |
+
|
| 107 |
+
if previewer:
|
| 108 |
+
cv2.destroyAllWindows()
|
| 109 |
+
|
| 110 |
return out
|
| 111 |
|
| 112 |
|