diff --git a/comfy/samplers.py b/comfy/samplers.py index fa4640842..0b9525d38 100755 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -355,8 +355,10 @@ def cfg_function(model, cond_pred, uncond_pred, cond_scale, x, timestep, model_o args = {"cond": x - cond_pred, "uncond": x - uncond_pred, "cond_scale": cond_scale, "timestep": timestep, "input": x, "sigma": timestep, "cond_denoised": cond_pred, "uncond_denoised": uncond_pred, "model": model, "model_options": model_options, "input_cond": cond, "input_uncond": uncond} cfg_result = x - model_options["sampler_cfg_function"](args) - else: + elif uncond_pred.any(): cfg_result = uncond_pred + (cond_pred - uncond_pred) * cond_scale + else: + cfg_result = cond_pred for fn in model_options.get("sampler_post_cfg_function", []): args = {"denoised": cfg_result, "cond": cond, "uncond": uncond, "cond_scale": cond_scale, "model": model, "uncond_denoised": uncond_pred, "cond_denoised": cond_pred,