INNER CODE UNIT · Python
sampling_function_patched
Extraltodeus/ComfyUI-AutomaticCFG · nodes.py:31
def sampling_function_patched(model, x, timestep, uncond, cond, cond_scale, model_options={}, seed=None, **kwargs):
cond_copy = cond
uncond_copy = uncond
for fn in model_options.get("sampler_patch_model_pre_cfg_function", []):
args = {"model": model, "sigma": timestep, "model_options": model_options}
model, model_options = fn(args)
if "sampler_pre_cfg_automatic_cfg_function" in model_options:
uncond, cond, cond_scale = model_options["sampler_pre_cfg_automatic_cfg_function"](
sigma=timestep, uncond=uncond, cond=cond, cond_scale=cond_scale
)
if math.isclose(cond_scale, 1.0) and model_options.get("disable_cfg1_optimization", False) == False:
uncond_ = None
else:
uncond_ = uncond