Implementation of Self-Rectifying Diffusion Sampling with Perturbed-Attention Guidance (D. Ahn et al.) as an extension for ComfyUI and SD WebUI Forge.
Tested to work with SD1.5 and SDXL.
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.
Currently not implemented. PRs are welcome!
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. Should be << thanscale
.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.