$ show pamparamm/sd-perturbed-attention
This repository provides a collection of custom nodes for ComfyUI and SD WebUI (reForge) that implement various guidance techniques for diffusion models. It includes implementations of Perturbed-Attention Guidance (PAG), Smoothed Energy Guidance (SEG), Sliding Window Guidance (SWG), PLADIS, Normalized Attention Guidance (NAG), Token Perturbation Guidance (TPG), Frequency-Decoupled Guidance (FDG), Momentum Guidance (MG), and Sliding Mode Control CFG (SMC-CFG). The architecture consists of modular node files, shared utility functions, and backend compatibility layers. Key entry points are the ComfyUI extension registration in __init__.py and the reForge integration scripts in the scripts directory. The system modifies the denoising process of diffusion models by injecting guidance computations at specific U-Net blocks, enhancing image quality and control.
The LLM identified 2 files worth highlighting for reuse:
Contains reusable functions for parsing U-Net block specifications, applying guidance rescaling, sliding window predictions, saliency-adaptive noise fusion, and vector projection. These functions are independent, solve common problems in diffusion model guidance implementations, and have minimal dependencies (only PyTorch and standard library).
Provides a standalone implementation of Entmax15 and Sparsemax activation functions used for sparse attention in the PLADIS node. This module has no dependencies beyond PyTorch and can be extracted for use in any project requiring sparse activations, demonstrating self-contained, reusable mathematical implementation.