Pre CFG PAG
Perturbed Attention Guidance as a plain model patch — sharper details, no new sampler
- model
- MODEL
Perturbed Attention Guidance (PAG) is one of those techniques that sounds academic and does something very practical: it makes the image sharper and more "crisp" without touching your prompt, and it reduces those smeary, under-defined regions that plague SDXL at low steps. "Pre CFG PAG" is PAG squeezed into a model patch so you don't need a special sampler to use it.
Here's the mechanism, minus the jargon. Attention computes an output from queries, keys, and values - mixing information across the image. PAG's idea is to run the model a second time with attention deliberately broken, so the prediction is worse, then amplify the difference between the good and bad predictions and add it back. Concretely, the node patches self-attention to return the value vectors v directly instead of the attended result - a "perturbed" prediction that has lost the spatial mixing attention normally does. The gap between the real prediction and that degraded one is mostly the detail attention was contributing, so real + (real - perturbed) * scale beefs it up. Scale 0.5 (the default) is a gentle lift; go higher and detail gets pushed harder, past 2-ish and you'll start seeing oversharpening artifacts.
What you actually set:
scale- how much of the perturbed-guidance term to add. Default 0.5, range −2 to 10. Small values are safe; this is a "season to taste" slider.start_at_sigma/end_at_sigma- raw sigma window. Defaults (15 down to 0) span the whole SDXL sampling, so the effect is on every step by default.model- the patched MODEL in, MODEL out, wired right after your loader.
The one thing to know before you fall in love: PAG costs a second forward pass per step. CFG already runs the model twice (cond + uncond); this adds a third while it's active. On an 8GB card that's the difference between "snappy" and "go make tea." That's the standard trade of every PAG implementation, not a bug in this node. The payoff is you get that structure/sharpness gain on top of your existing sampler and scheduler - no swapping to a PAG sampler, no retuning your whole workflow.
The author is Extraltodeus, a long-time ComfyUI node author (he also wrote the automatic-CFG and uncond-zero packs, and his "gradient scaling" node is in this same repo), and he's upfront that he only tested on SDXL. This node will load fine on other architectures, but SDXL-family is its proven home - which suits it, since SDXL's "soft, plastic" look at low steps is exactly the failure PAG fixes.
Installing is the whole-pack story, which is refreshingly light:
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 requirements.txt, no model downloads. One caveat shared with the rest of the pack: at CFG 1 (or on guidance-distilled models) there's no negative prediction, and the node's logic keys off torch.any(conds_out[1]) - on pure CFG-1 models it quietly does nothing. On a normal SDXL workflow with CFG 4-7 it just works. Start at scale 0.5, watch one step in a low-step sample, then decide whether the extra render time is worth it for your use case.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| scale | FLOAT | 0.50-2–10 | — |
| start_at_sigma | FLOAT | 15.000–1000 | — |
| end_at_sigma | FLOAT | 0.000–1000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |