Nodes/CFG Megapack/CFG Weak Branch: Perturbed Self-Attention
ComfyUI Node

CFG Weak Branch: Perturbed Self-Attention

Build your own PAG, SEG, temperature or skip in one node

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
CFG Weak Branch: Perturbed Self-Attention
  • model
  • MODEL
◄methodpag (identity attention)►
◄scale3.00►
◄modeadd on top of CFG►
◄blocksmiddle (PAG / SEG default)►
◄blur_sigma10.0►
◄temperature2.00►

Everything in the weak-branch family works the same way: run the model a second time in a worse configuration and steer away from that prediction. PAG gets there by turning self-attention into identity, SEG by blurring the attention queries, STG by skipping attention entirely, and someone somewhere thought "what if attention just ran hotter". This node is all four in one, with a mode switch on top.

If you want exactly one of them with the paper's settings, the individual PAG, SEG and STG nodes in the same pack are tidier. This is the one you reach for when you want to tune.

The mechanism

One extra forward pass per step, on your positive prompt, with the selected self-attention blocks degraded according to method:

  • pag - identity attention, each token sees only itself (Ahn et al. 2024).
  • seg - the queries blurred over the image (Hong 2024).
  • temperature - the attention logits divided by temperature, flattening the distribution.
  • skip - the self-attention sublayer removed (STG, Hyung et al. 2025).

Then mode decides what to do with that prediction:

  • add on top of CFG - result = mix + scale * (conditional - perturbed). Your CFG still runs; the weak branch is an extra push.
  • replace the unconditional - the perturbed prediction takes u's place in the mix, at the mix scale. The text-unconditional pass is then skipped, so guidance comes from the weak branch alone. It's a genuine cost saving (back to roughly plain CFG's forward-pass count) at the price of steering with a blunted model instead of the empty prompt.

Cost in the default add mode: one extra model pass per step, roughly a 50% hit on SDXL render time. Replace mode gives that back.

Inputs and output

Six inputs beyond the model.

  • method - pag / seg / temperature / skip. "Anima: seg and skip only."
  • scale - default 3.0, "add mode: how hard to push away from the perturbed prediction (PAG paper: 3). Unused in replace mode." In replace mode this field does nothing.
  • mode - add on top of CFG (default) or replace the unconditional.
  • blocks - which blocks get perturbed: middle (PAG / SEG default), middle + first output, deep output (output 0-2), deep input (input 7-8), all SDXL attention blocks. On Anima and other Cosmos-Predict2 transformers, middle means its two middle blocks, deep input the first third, deep output the last third.
  • temperature - temperature only: attention logits divided by this (above 1 = flatter).
  • blur_sigma - SEG only: Gaussian blur of the queries in latent pixels (100 = every query becomes the mean).

Output: MODEL.

Practical guidance

The default scale of 3 is PAG's and it is aggressive. On a CFG-sensitive checkpoint - Pony, Illustrious, Anima - people consistently report PAG frying images even at low values, so start at 1.5.

For SEG, the default blur_sigma of 10 is mild; 20–40 is where the effect becomes obvious. For temperature, 2 is already a substantial flattening.

On Anima, pag and temperature simply don't run: those transformer blocks only accept patches on the attention inputs, and a query temperature would be undone by the blocks' own query normalization. The node stops with a message that points at seg and skip. That's not a bug you can work around; it's the architecture.

Install

Manager → search CFG Megapack → install, restart ComfyUI. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/AbstractEyes/comfy-cfg-megapack

No dependencies, no model files, no key - but a current ComfyUI is mandatory, since the pack is built on comfy_api.latest (README: tested on 0.38.0). On an older install, the pack won't import and nothing will show up in the node search.

Where people get burned

Two weak branches in the graph. The weak-branch stage holds a single rule; a later weak-branch node replaces an earlier one. Chaining this after PAG means PAG is gone. Same in reverse. CFG Plan Readout shows what's live.

scale in replace mode. Ignored by design. If you switched modes and the output barely changed, that's why - strength is now the mix scale, i.e. the sampler's cfg.

blur_sigma and temperature doing nothing. Each only applies to its own method. Half of this node's inputs are inert on any given run; that's the cost of collapsing four papers into one menu.

PAG on Anima. Unsupported, with an error. Use seg or skip. The pack's troubleshooting section says it plainly, and the node tells you when you try.

Slot conflict, for the record. If another pack's RescaleCFG, Mahiro or RenormCFG node is chained after this one, it owns ComfyUI's single CFG-function slot and your weak branch does nothing at all. That failure looks exactly like "the weak branch is too subtle", which is why it wastes so much time.

CategoryCFG Megapack/2 weak branch

Inputs (7)

NameTypeDefaultDescription
modelMODEL—
methodCOMBOpag (identity attention)pag: identity attention. seg: blurred queries. temperature: flatter attention. skip: the self-attention sublayer removed. Anima: seg and skip only.
scaleFLOAT3.000–100add mode: how hard to push away from the perturbed prediction (PAG paper: 3). Unused in replace mode.
modeCOMBOadd on top of CFGadd: result = mix + scale * (conditional - perturbed). replace: the perturbed prediction takes the unconditional's place in the mix, at the mix scale (the text-unconditional pass is then skipped).
blocksCOMBOmiddle (PAG / SEG default)Which self-attention blocks are perturbed (SDXL names; the middle block also exists on SD1.5). On Anima / Cosmos DiTs: middle = the two middle blocks, deep input = the first third, deep output = the last third, all = every block.
blur_sigmaFLOAT10.00.1–100SEG only: Gaussian blur of the queries in latent pixels. 100 = infinite (every query becomes the mean).
temperatureFLOAT2.000.05–20Temperature only: attention logits are divided by this (above 1 = flatter).

Outputs (1)

NameTypeDescription
MODELMODEL—