Implementation of Self-Rectifying Diffusion Sampling with Perturbed-Attention Guidance (D. Ahn et al.) as an extension for ComfyUI and SD WebUI Forge.
Works with SD1.5, SDXL and Stable Cascade.
Note
Paper and demo suggest using CFG scale 4.0 with PAG scale 3.0 applied to U-Net's middle layer 0, but feel free to experiment.
Sampling speed without adaptive_scale
is similar to Self-Attention Guidance (x0.6 of usual it/s).
git clone https://github.com/pamparamm/sd-perturbed-attention.git
into ComfyUI/custom-nodes/
folder.
git clone https://github.com/pamparamm/sd-perturbed-attention.git
into stable-diffusion-webui-forge/extensions/
folder.
Use PAG implementation from sd-webui-incantations extension.
scale
: PAG scale, has some resemblance to CFG scale - higher values can both increase structural coherence of the image and oversaturate/fry it entirely.adaptive_scale
: PAG dampening factor, it penalizes PAG during late denoising stages, resulting in overall speedup: 0.0 means no penalty and 1.0 completely removes PAG.unet_block
: Part of U-Net to which PAG is applied, original paper suggests to usemiddle
.unet_block_id
: Id of U-Net layer in a selected block to which PAG is applied. PAG can be applied only to layers containing Self-attention blocks.