Nodes/pre_cfg_comfy_nodes_for_ComfyUI/Pre CFG zero attention
ComfyUI Node

Pre CFG zero attention

What if a pass ran with no attention at all? Zero-attention guidance, pre-CFG

By Extraltodeus·Created 2 years ago·Updated about a year ago· 66
Pre CFG zero attention
  • model
  • MODEL
do_onuncond
mix_scale1.5
start_at_sigma15.00
end_at_sigma0.00

Here's a thought experiment: run the model normally, but on a second pass, replace every attention output with zeros - the model has to predict without any attention mixing at all. Whatever it produces is the "no-attention" baseline, and the difference between that and the real prediction is, loosely, how much attention is steering your image. "Pre CFG zero attention" computes exactly that and lets you mix it back in, before CFG runs.

The mechanism: the node patches attention to return torch.zeros_like(q) for a targeted forward pass, gets a "zero-attention" prediction, then either uses it outright or blends it with the real prediction using mix_scale. Its default target is uncond - the negative pass. Zeroing attention on the uncond pass is the author's uncond-zero idea (he has a whole separate pack named Uncond-Zero for it): the negative prompt's influence comes through attention, and if the negative pass can't attend to anything, its unwanted bleed is cut way down. On cond it becomes a prompt-steering experiment instead - run a degraded positive pass and mix it in to change how strongly the image is compositionally driven.

What you set:

  • do_on - cond or uncond. Default uncond; start there, since uncond-zero is the proven use.
  • mix_scale - how the zero-attention prediction is blended with the real one. Default 1.5. At exactly 1 the node uses the zero-attention prediction outright and prints a message telling you the prediction "was not generated" - a hint that you should use a timestep-range node if you want that behavior on purpose.
  • start_at_sigma / end_at_sigma - sigma window, defaults spanning the whole SDXL range. Zeroing attention in the late, detail-heavy steps hits hard, so many people shorten the window.
  • model - patched MODEL in/out, right after your loader.

The cost is real: this is another "extra forward pass per step" node, like PAG and perp-neg. While the window is active you're running three passes instead of two, so expect roughly +50% sampling time. That's the price of asking the model a second question every step.

Gotchas worth knowing before you queue it up. First, when mix_scale == 1 and the target prediction was generated, the node skips and tells you (via console) to use ConditioningSetTimestepRange to avoid generating it - that's the author's supported path for the "replace outright" behavior, and it's also how he does the well-known empty-uncond speed boost in the same pack. Second, the pack-wide caveat: no negative prediction (CFG 1, distilled models) means no uncond to zero. And the author's testing was SDXL-only. On a normal SDXL workflow with a strong negative prompt, zeroing the uncond attention is a legitimately interesting lever for "my negative is too loud" problems.

Install:

cd ComfyUI/custom_nodes && git clone https://github.com/Extraltodeus/pre_cfg_comfy_nodes_for_ComfyUI

or ComfyUI Manager → search pre_cfg_comfy_nodes_for_ComfyUI → restart. No extra dependencies, no model downloads - one Python file on ComfyUI's sampler hooks.

Categorymodel_patches/Pre CFG

Inputs (5)

NameTypeDefaultDescription
modelMODEL
do_onCOMBOuncond2 options: cond, uncond
mix_scaleFLOAT1.5-2–2
start_at_sigmaFLOAT15.000–1000
end_at_sigmaFLOAT0.000–1000

Outputs (1)

NameTypeDescription
MODELMODEL