mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-01 21:07:20 +08:00
Perpneg guider with updated pre and post-cfg (#8698)
This commit is contained in:
parent
396454fa41
commit
5b4eb021cb
@ -69,8 +69,17 @@ class Guider_PerpNeg(comfy.samplers.CFGGuider):
|
|||||||
negative_cond = self.conds.get("negative", None)
|
negative_cond = self.conds.get("negative", None)
|
||||||
empty_cond = self.conds.get("empty_negative_prompt", None)
|
empty_cond = self.conds.get("empty_negative_prompt", None)
|
||||||
|
|
||||||
(noise_pred_pos, noise_pred_neg, noise_pred_empty) = \
|
conds = [positive_cond, negative_cond, empty_cond]
|
||||||
comfy.samplers.calc_cond_batch(self.inner_model, [positive_cond, negative_cond, empty_cond], x, timestep, model_options)
|
|
||||||
|
out = comfy.samplers.calc_cond_batch(self.inner_model, conds, x, timestep, model_options)
|
||||||
|
|
||||||
|
# Apply pre_cfg_functions since sampling_function() is skipped
|
||||||
|
for fn in model_options.get("sampler_pre_cfg_function", []):
|
||||||
|
args = {"conds":conds, "conds_out": out, "cond_scale": self.cfg, "timestep": timestep,
|
||||||
|
"input": x, "sigma": timestep, "model": self.inner_model, "model_options": model_options}
|
||||||
|
out = fn(args)
|
||||||
|
|
||||||
|
noise_pred_pos, noise_pred_neg, noise_pred_empty = out
|
||||||
cfg_result = perp_neg(x, noise_pred_pos, noise_pred_neg, noise_pred_empty, self.neg_scale, self.cfg)
|
cfg_result = perp_neg(x, noise_pred_pos, noise_pred_neg, noise_pred_empty, self.neg_scale, self.cfg)
|
||||||
|
|
||||||
# normally this would be done in cfg_function, but we skipped
|
# normally this would be done in cfg_function, but we skipped
|
||||||
@ -82,6 +91,7 @@ class Guider_PerpNeg(comfy.samplers.CFGGuider):
|
|||||||
"denoised": cfg_result,
|
"denoised": cfg_result,
|
||||||
"cond": positive_cond,
|
"cond": positive_cond,
|
||||||
"uncond": negative_cond,
|
"uncond": negative_cond,
|
||||||
|
"cond_scale": self.cfg,
|
||||||
"model": self.inner_model,
|
"model": self.inner_model,
|
||||||
"uncond_denoised": noise_pred_neg,
|
"uncond_denoised": noise_pred_neg,
|
||||||
"cond_denoised": noise_pred_pos,
|
"cond_denoised": noise_pred_pos,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user