|
|
|
@ -56,6 +56,80 @@ class SamplerLCMUpscale:
|
|
|
|
|
sampler = comfy.samplers.KSAMPLER(sample_lcm_upscale, extra_options={"total_upscale": scale_ratio, "upscale_steps": scale_steps, "upscale_method": upscale_method})
|
|
|
|
|
return (sampler, )
|
|
|
|
|
|
|
|
|
|
from comfy.k_diffusion.sampling import to_d
|
|
|
|
|
import comfy.model_patcher
|
|
|
|
|
|
|
|
|
|
@torch.no_grad()
|
|
|
|
|
def sample_euler_cfgpp(model, x, sigmas, extra_args=None, callback=None, disable=None):
|
|
|
|
|
extra_args = {} if extra_args is None else extra_args
|
|
|
|
|
|
|
|
|
|
temp = [0]
|
|
|
|
|
def post_cfg_function(args):
|
|
|
|
|
temp[0] = args["uncond_denoised"]
|
|
|
|
|
return args["denoised"]
|
|
|
|
|
|
|
|
|
|
model_options = extra_args.get("model_options", {}).copy()
|
|
|
|
|
extra_args["model_options"] = comfy.model_patcher.set_model_options_post_cfg_function(model_options, post_cfg_function, disable_cfg1_optimization=True)
|
|
|
|
|
|
|
|
|
|
s_in = x.new_ones([x.shape[0]])
|
|
|
|
|
for i in trange(len(sigmas) - 1, disable=disable):
|
|
|
|
|
sigma_hat = sigmas[i]
|
|
|
|
|
denoised = model(x, sigma_hat * s_in, **extra_args)
|
|
|
|
|
d = to_d(x, sigma_hat, temp[0])
|
|
|
|
|
if callback is not None:
|
|
|
|
|
callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigma_hat, 'denoised': denoised})
|
|
|
|
|
dt = sigmas[i + 1] - sigma_hat
|
|
|
|
|
x = denoised + sigmas[i + 1] * d
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
@torch.no_grad()
|
|
|
|
|
def sample_euler_cfgpp_alt(model, x, sigmas, extra_args=None, callback=None, disable=None):
|
|
|
|
|
extra_args = {} if extra_args is None else extra_args
|
|
|
|
|
|
|
|
|
|
temp = [0]
|
|
|
|
|
def post_cfg_function(args):
|
|
|
|
|
temp[0] = args["uncond_denoised"]
|
|
|
|
|
return args["denoised"]
|
|
|
|
|
|
|
|
|
|
model_options = extra_args.get("model_options", {}).copy()
|
|
|
|
|
extra_args["model_options"] = comfy.model_patcher.set_model_options_post_cfg_function(model_options, post_cfg_function, disable_cfg1_optimization=True)
|
|
|
|
|
|
|
|
|
|
s_in = x.new_ones([x.shape[0]])
|
|
|
|
|
for i in trange(len(sigmas) - 1, disable=disable):
|
|
|
|
|
sigma_hat = sigmas[i]
|
|
|
|
|
denoised = model(x, sigma_hat * s_in, **extra_args)
|
|
|
|
|
d = to_d(x - denoised + temp[0], sigma_hat, denoised)
|
|
|
|
|
if callback is not None:
|
|
|
|
|
callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigma_hat, 'denoised': denoised})
|
|
|
|
|
dt = sigmas[i + 1] - sigma_hat
|
|
|
|
|
# Euler method
|
|
|
|
|
x = x + d * dt
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
class SamplerEulerCFGpp:
|
|
|
|
|
@classmethod
|
|
|
|
|
def INPUT_TYPES(s):
|
|
|
|
|
return {"required":
|
|
|
|
|
{"version": (["regular", "alternative"],),}
|
|
|
|
|
}
|
|
|
|
|
RETURN_TYPES = ("SAMPLER",)
|
|
|
|
|
# CATEGORY = "sampling/custom_sampling/samplers"
|
|
|
|
|
CATEGORY = "_for_testing"
|
|
|
|
|
|
|
|
|
|
FUNCTION = "get_sampler"
|
|
|
|
|
|
|
|
|
|
def get_sampler(self, version):
|
|
|
|
|
if version == "regular":
|
|
|
|
|
sampler = comfy.samplers.KSAMPLER(sample_euler_cfgpp)
|
|
|
|
|
else:
|
|
|
|
|
sampler = comfy.samplers.KSAMPLER(sample_euler_cfgpp_alt)
|
|
|
|
|
return (sampler, )
|
|
|
|
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
|
|
|
"SamplerLCMUpscale": SamplerLCMUpscale,
|
|
|
|
|
"SamplerEulerCFGpp": SamplerEulerCFGpp,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
|
|
|
"SamplerEulerCFGpp": "SamplerEulerCFG++",
|
|
|
|
|
}
|
|
|
|
|