Nodes/CFG Megapack/PAG: Perturbed-Attention Guidance (Ahn et al. 2024)
ComfyUI Node

PAG: Perturbed-Attention Guidance (Ahn et al. 2024)

The extra model pass that fixes hands, fingers and mush

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
PAG: Perturbed-Attention Guidance (Ahn et al. 2024)
  • model
  • MODEL
◄scale3.0►
◄blocksmiddle (PAG / SEG default)►

Perturbed-Attention Guidance was the SDXL-era answer to the question every CFG node in this pack is quietly answering: what if you guided away from something other than the empty prompt? PAG (Ahn et al., ECCV 2024) guides away from a deliberately degraded version of your own prompt - and it's still one of the best-value extra passes on a UNet model.

How it works

At each step, PAG runs the model an extra time on your positive prompt, with the selected self-attention blocks replaced by the identity. In plain terms, every token attends only to itself; the structural information that attention normally spreads across the image is gone, and the result is a flat, structureless prediction.

Then it guides away from that: on top of whatever CFG is doing, + s · (c − pag). You're pushing away from the version of the image that has lost its structure, which sharpens structure - that's the paper's whole argument, and it's why PAG is famous for hands and faces.

The cost is honest and non-negotiable: one extra full model evaluation per guided step. Plain CFG already doubles your compute with its unconditional pass; PAG adds a third, so expect around half again the render time of plain CFG, before any other node you've chained.

The inputs

  • scale - the strength s, default 3. The useful band is 1.5 to 5, and the pack's tooltip has the practical advice built in: use 1.5 when CFG is also on, because the two effects add up and stacking a strong PAG on a high cfg is how people end up with over-sharpened, crunchy images.
  • blocks - which self-attention blocks get perturbed. Default is middle (PAG / SEG default), which is what both papers ship. The other presets reach further into the network: middle + first output, deep output (output 0-2), deep input (input 7-8), or every SDXL attention block. On SD1.5 the middle block exists too; this is UNet vocabulary.

Output: a single MODEL.

Where it fits

PAG writes the pack's weak branch stage - the stage that decides what to guide away from - which means it composes with everything else. A combine node still decides how the two predictions are mixed; PAG just adds a third prediction to the party. The pack's recipe for getting more out of a model you already like is exactly this: run SEG or PAG at 1.5–3 on top of a modest cfg of 4 to 7, and let the perturbation pass carry the sharpening instead of the scale.

It's also the node that ages the fastest. PAG was a genuine community topic through 2024 and 2025 - the phrase shows up around 140 times in the corpus this knowledge base is built from, with the discussion thinning out sharply through 2026 as the model generation moved to flow-matching and guidance-distilled checkpoints where plain CFG doesn't even run. It's not obsolete on SDXL finetunes; it's just no longer the thing people are adding to their Flux workflows.

Install

ComfyUI Manager: search CFG Megapack, install, restart. comfy-cli: comfy node install comfy-cfg-megapack. By hand:

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

Restart ComfyUI. No requirements.txt, no extra dependencies, no model downloads - torch and the Python standard library on ComfyUI's current node API. Tested on ComfyUI 0.38.0 with torch 2.11, on GPU and CPU-only. CFG_MEGAPACK_VRAM_FRACTION=0.6 before launch caps the pack's GPU memory share if the card is shared.

Traps

  • It doesn't work on Anima or other Cosmos-Predict2 transformers, and it tells you so. PAG needs the attention output replaced, and those blocks don't allow it - the node stops with a message pointing you at SEG or the attention skip method, both of which work there. That's the whole of this pack's block-preset vocabulary on transformer models: it takes patches on its attention inputs only.
  • Chaining a second PAG from another pack doubles the extra pass rather than reinforcing it. Pick one.
  • Don't pay for PAG and then throw the detail away. It's most useful where it can act on structure - moderate steps, cfg 4 to 7, and not stacked under four other CFG-fixing nodes that flatten it back out.
  • ComfyUI has one CFG-function slot. PAG's node patches the model differently from the combine rules, so it composes with them - but another pack's RescaleCFG, Mahiro or RenormCFG chained after your chain still takes that slot and wins.
CategoryCFG Megapack/papers/weak branch (a degraded pass of the model itself)

Inputs (3)

NameTypeDefaultDescription
modelMODEL—
scaleFLOAT3.00–20Strength s (1.5-5; 1.5 when CFG is also on).
blocksCOMBOmiddle (PAG / SEG default)Which self-attention blocks are perturbed (SDXL names; the middle block exists on SD1.5 too). On Anima and other Cosmos-Predict2 transformers: middle = the two middle blocks, deep input = the first third, deep output = the last third.

Outputs (1)

NameTypeDescription
MODELMODEL—