mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-08-02 23:14:49 +08:00
Implement my alternative take on CFG++ as the euler_pp sampler.
Add euler_ancestral_pp which is the ancestral version of euler with the same modification.
This commit is contained in:
@@ -82,29 +82,6 @@ def sample_euler_cfgpp(model, x, sigmas, extra_args=None, callback=None, disable
|
||||
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
|
||||
@@ -122,7 +99,7 @@ class SamplerEulerCFGpp:
|
||||
if version == "regular":
|
||||
sampler = comfy.samplers.KSAMPLER(sample_euler_cfgpp)
|
||||
else:
|
||||
sampler = comfy.samplers.KSAMPLER(sample_euler_cfgpp_alt)
|
||||
sampler = comfy.samplers.ksampler("euler_pp")
|
||||
return (sampler, )
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
|
Reference in New Issue
Block a user