Nodes/Comfy Latent Tools/Generic Attention Guidance
ComfyUI Node

Generic Attention Guidance

One node, twelve ways to poke at attention — PAG included

By JTriggerFish·Created 2 years ago·Updated about a year ago· 4
Generic Attention Guidance
  • model
  • MODEL
guidance_typeRandomDrop
guidance_weight1.5
param11.00
param20.00
param30.00
apply_rescaling_to_alternate_guidancefalse
rescaling_method VSpaceRescale
rescaling_fraction0.70
unet_blockmiddle
unet_block_id0
guidance_start_sigma7.00
guidance_end_sigma0.00
time_perturbation_std0.00
unet_block_list

Perturbed Attention Guidance (PAG) has a reputation problem. When it lands, it's the trick that "cleaned up compositions" and made people rave back in 2024; when it misses, it deep-fries your image - oversaturated, overcooked, like someone turned CFG up to eleven. GenericAttentionGuidance from Comfy Latent Tools is a single model-patch node that hands you PAG plus eleven other ways to perturb attention, wrapped in rescaling methods built specifically to stop the deep-frying.

It sits in the model_patches/unet category. You feed it a MODEL, it clones and patches the sampler, and the patched MODEL goes into your KSampler in place of the original. Output is a single MODEL; nothing else changes in your workflow.

How it works

Classifier-free guidance normally extrapolates the conditioned prediction away from the unconditioned one. Attention guidance adds a third term: a perturbed forward pass of the UNet, computed with a damaged attention function in one chosen block, and the final output is steered by the difference between that perturbed prediction and the normal one, scaled by guidance_weight (default 1.5).

Which damage you apply is the guidance_type dropdown - all twelve are in the schema: ValueRescale, Scramble, RandomRotation, Fuzzy, AAT, SEG, PAG, Permute, RandomDrop, RandomSubspace, SVD, Phase. The classic one is PAG, which simply ignores the attention matrix and passes the values straight through (the "identity attention" idea from the PAG paper - real thing, still 140+ threads on Reddit since 2024). RandomDrop (the default) randomly drops tokens before attention. The others range from scrambling to phase-shifting in FFT space.

Here's the part that fixes PAG's bad reputation. A raw PAG guidance term pushes dynamic range off a cliff, which is the oversaturation. The rescaling_method dropdown (VSpaceRescale default, PredSpaceRescale, SNF, Softmax, Normalize, OrthogonalComponent) rebalances the combined prediction so you keep the fidelity gain without the saturation, and rescaling_fraction (default 0.7) blends between rescaled and unscaled. The pack author's own note for the PAG variant: start with weight around half your CFG and a post-rescale close to 1.0.

The inputs that actually matter

  • guidance_type - which perturbation; PAG and RandomDrop are the sane starts.
  • guidance_weight - strength of the extra guidance term.
  • param1 / param2 / param3 - per-type tuning knobs. They mean different things per type and the node won't tell you; e.g. AAT wants param2 near −100, RandomRotation wants param2 in 0–1. Check the pack source if you go deep.
  • rescaling_method + rescaling_fraction - the anti-deep-fry controls.
  • unet_block (input/middle/output) and unet_block_id - which block's attention gets perturbed; middle/0 is the default. unet_block_list is an optional string if you want several blocks at once.
  • guidance_start_sigma (7) / guidance_end_sigma (0) - the noise window where the guidance actually runs. Above start_sigma, early chaotic steps, the node stands aside and lets plain sampling happen.

One honest cost: every PAG-style method adds a second UNet forward pass per step, so sampling time roughly doubles. The author claims samplers converge faster with it on, so you can sometimes shave steps to compensate - but budget for the slowdown first.

Install and gotchas

ComfyUI Manager, search Comfy Latent Tools, install, restart. Or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/JTriggerFish/ComfyLatentTools

Then restart ComfyUI. No model files to download, and the only dependencies are torch, torchvision, pillow and numpy - nothing exotic.

Where people get burned: this pack is openly experimental - the README literally says "MANY MISSING NODES HERE - WILL BE UPDATED" - and the guidance types need real tuning; the defaults are starting points, not answers. If you see oversaturation creeping back, rescaling_fraction isn't catching it - raise it toward 1.0. Start with PAG + VSpaceRescale, weight about half your CFG, and change one thing at a time. That's the workflow, not a bug.

Categorymodel_patches/unet

Inputs (15)

NameTypeDefaultDescription
modelMODEL
guidance_typeCOMBORandomDrop12 options: ValueRescale, Scramble, RandomRotation, Fuzzy, AAT, SEG, +6
guidance_weightFLOAT1.50–100
param1FLOAT1.00-1–1
param2FLOAT0.00-1–1
param3FLOAT0.00-1–1
apply_rescaling_to_alternate_guidanceBOOLEANfalse
rescaling_method COMBOVSpaceRescale7 options: None, PredSpaceRescale, VSpaceRescale, SNF, Softmax, Normalize, +1
rescaling_fractionFLOAT0.700–1
unet_blockCOMBOmiddle3 options: input, middle, output
unet_block_idINT0
guidance_start_sigmaFLOAT7.000–15
guidance_end_sigmaFLOAT0.000–15
time_perturbation_stdFLOAT0.000–1
unet_block_listoptSTRING

Outputs (1)

NameTypeDescription
MODELMODEL