Nodes/sd-perturbed-attention/Perturbed-Attention Guidance (Advanced)
ComfyUI Node

Perturbed-Attention Guidance (Advanced)

Sharper images without touching your negative prompt

By pamparamm·Created 2 years ago·Updated 5 months ago· 299
Perturbed-Attention Guidance (Advanced)
  • model
  • MODEL
scale3.0
adaptive_scale0.000
unet_blockmiddle
unet_block_id0
sigma_start-1.00
sigma_end-1.00
rescale0.00
rescale_modefull
unet_block_list

CFG works by comparing a "with prompt" prediction against a "without prompt" one and pushing away from the difference. Perturbed-Attention Guidance does something similar, except the thing it pushes away from isn't an empty prompt - it's your own prompt run through a UNet with its self-attention deliberately broken. That degraded prediction tends to be structurally worse (muddier backgrounds, less coherent shapes), so guiding away from it sharpens composition without you having to touch CFG or write a longer negative prompt at all.

This is the node from the paper the whole pack is named after - Ahn et al.'s "Self-Rectifying Diffusion Sampling with Perturbed-Attention Guidance." The "Advanced" version is the one with all the knobs; there's a simpler PAG node elsewhere for people who just want scale and nothing else. It's a model_patches/unet node, meaning it's a MODEL → MODEL patch: it clips in between your checkpoint loader and your KSampler and does its work per step without needing a second conditioning input.

The inputs that matter

  • scale (default 3) - same role as CFG scale: how hard you push away from the perturbed prediction. Higher tightens structure; too high oversaturates and fries the image, same failure mode as cranking CFG.
  • adaptive_scale (default 0, PAG-only) - a dampening factor for late denoising steps. 0 means PAG runs at full strength the whole time; 1 turns it off entirely in the late steps. This exists specifically to buy back some speed, since computing the perturbed pass every step isn't free.
  • unet_block / unet_block_id (default middle, 0) - which UNet layer gets its attention perturbed. The original paper's recommendation is middle, which is also the default, so leave this alone unless you're experimenting.
  • sigma_start / sigma_end (both -1 by default) - restrict PAG to a noise-level window instead of running it the entire denoise. -1/-1 means always-on.
  • rescale / rescale_mode (0 / full) - an anti-oversaturation valve modeled on the RescaleCFG trick. full factors in CFG and PAG together, partial only PAG, snf uses saliency-adaptive noise fusion and ignores the rescale number entirely. Off by default.
  • Optional unet_block_list lets you override the single unet_block/unet_block_id pair and target multiple layers at once with a compact syntax (e.g. m0,u0.4 - middle block 0 plus output block 0's sub-index 4). SD1.5 and SDXL have different layer counts, and the README spells out the exact ranges if you want to go layer-hunting.

Output is a single MODEL - wire it straight into your KSampler.

How to install it

Either search "Perturbed-Attention Guidance" in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/pamparamm/sd-perturbed-attention

then restart. There's also a comfy-cli path (comfy node registry-install sd-perturbed-attention) if that's your workflow. No models to download, no extra Python dependencies - it's pure attention-graph surgery on a model you already have loaded.

Worth knowing: this pack's author, pamparamm, also maintains ComfyUI-ppm (the CFG++ samplers, the Guidance Limiter node, AttentionCouplePPM) - same lineage of paper-accurate, low-drama guidance nodes. If you've used one, the conventions here (sigma windows, rescale modes) will feel familiar.

Common issues & troubleshooting

It's noticeably slower. That's expected - PAG runs an extra perturbed forward pass through part of the UNet every step, and one widely-read PAG writeup on r/StableDiffusion reported roughly a 60% iteration-speed hit. adaptive_scale above 0 claws some of that back by tapering PAG off in the late steps, where its effect matters less anyway. Narrowing sigma_start/sigma_end to just the early-to-mid steps does the same thing more aggressively.

Images look fried at higher scale. Same fix as burned CFG: turn on rescale (start around 0.5–0.7) or try rescale_mode: snf. A commonly cited starting combo from the PAG-writeup era is CFG 4 + PAG scale 3, which happens to land back at the "classic" CFG 7 - a reasonable anchor if you're not sure where to start.

"I don't see a difference." This is a real, split opinion in the community - some people call PAG a game-changer for cleaning up messy backgrounds, group scenes, and architectural detail; others genuinely can't tell PAG output from non-PAG output on their subjects. It's a real, subtle effect, not a placebo, but it's most visible on complex, multi-object scenes rather than a single clean portrait - so don't judge it on a headshot.

unet_block_list syntax errors. The block-range syntax (d0-d3, u0.4-9, etc.) is unforgiving about typos. If it's rejecting your string, fall back to the plain unet_block/unet_block_id pair while you get the syntax right.

Categorymodel_patches/unet

Inputs (10)

NameTypeDefaultDescription
modelMODEL
scaleFLOAT3.00–100
adaptive_scaleFLOAT0.0000–1
unet_blockCOMBOmiddle3 options: input, middle, output
unet_block_idINT0
sigma_startFLOAT-1.00-1–10000
sigma_endFLOAT-1.00-1–10000
rescaleFLOAT0.000–1
rescale_modeCOMBOfull3 options: full, partial, snf
unet_block_listoptSTRING

Outputs (1)

NameTypeDescription
MODELMODEL