Perturbed-Attention Guidance (Advanced)
Sharper images without touching your negative prompt
- model
- MODEL
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(defaultmiddle,0) - which UNet layer gets its attention perturbed. The original paper's recommendation ismiddle, 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.fullfactors in CFG and PAG together,partialonly PAG,snfuses saliency-adaptive noise fusion and ignores therescalenumber entirely. Off by default.- Optional
unet_block_listlets you override the singleunet_block/unet_block_idpair 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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| scale | FLOAT | 3.00–100 | — |
| adaptive_scale | FLOAT | 0.0000–1 | — |
| unet_block | COMBO | middle | 3 options: input, middle, output |
| unet_block_id | INT | 0 | — |
| sigma_start | FLOAT | -1.00-1–10000 | — |
| sigma_end | FLOAT | -1.00-1–10000 | — |
| rescale | FLOAT | 0.000–1 | — |
| rescale_mode | COMBO | full | 3 options: full, partial, snf |
| unet_block_listopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |