Nodes/sd-perturbed-attention/Token Perturbation Guidance
ComfyUI Node

Token Perturbation Guidance

PAG's idea, one token at a time

By pamparamm·Created 2 years ago·Updated 5 months ago· 299
Token Perturbation Guidance
  • model
  • MODEL
scale3.0
sigma_start-1.00
sigma_end-1.00
rescale0.00
rescale_modefull
unet_block_listd2.2-9,d3

PAG perturbs self-attention wholesale - swap the attention map for something degraded, guide away from it. Token Perturbation Guidance, from the paper of the same name, works at a finer grain: it perturbs at the token level rather than disrupting a whole attention map at once. Same family of trick as everything else in this pack - build a deliberately worse prediction and guide away from it - but a more surgical version of how that degraded prediction gets made.

The most distinctive thing about this node isn't a mechanism detail, though - it's that it ships with an actual opinionated default for where it applies, unlike most of its siblings.

The inputs that matter

  • scale (default 3) - standard guidance strength, same as elsewhere in the pack.
  • sigma_start / sigma_end (both -1) - restrict TPG to a noise window; -1/-1 runs it the whole denoise.
  • rescale / rescale_mode (0 / full) - the same anti-oversaturation valve used by PAG and SEG.
  • Optional unet_block_list - and this is the field to pay attention to. Its default isn't empty or "all blocks" - it's d2.2-9,d3, a specific, narrow slice of the UNet's input blocks. Unlike PAG or SEG, TPG doesn't give you separate unet_block/unet_block_id dropdown fields - this string is the only way to control where it applies, and it comes pre-loaded with the author's own recommended target rather than defaulting to "everything" or "middle only."

Output is a MODEL, wired into your KSampler as usual.

How to install it

ComfyUI Manager: search "Perturbed-Attention Guidance" - TPG ships inside that pack. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/pamparamm/sd-perturbed-attention

Restart. No models to fetch, no extra dependencies.

Common issues & troubleshooting

This is one of the newer, quieter additions to the pack - essentially no community usage trail yet, so treat what follows as grounded reasoning about the schema rather than field-tested advice.

Trying to change where TPG applies and not finding the usual dropdown. There isn't one on this node - unet_block and unet_block_id don't exist here the way they do on PAG and SEG. unet_block_list is the only lever, and if you want the "just target the middle block" behavior those other nodes default to, you'll need to type it explicitly (m0) rather than expect it out of the box - TPG's own default already points somewhere specific (d2.2-9,d3), not at middle.

Wondering why the default block target looks so oddly specific. It is specific on purpose - d2.2-9,d3 targets particular input-block sub-indices rather than a broad sweep, which suggests the author tuned this against those blocks specifically rather than leaving a generic default. If you override it, it's worth A/B-ing against the stock default before assuming your custom target is actually better.

Oversaturated output at higher scale. Same fix as the rest of the pack: enable rescale (start around 0.5–0.7) or try rescale_mode: snf for high-guidance-scale stability.

Categorymodel_patches/unet

Inputs (7)

NameTypeDefaultDescription
modelMODEL
scaleFLOAT3.00–100
sigma_startFLOAT-1.00-1–10000
sigma_endFLOAT-1.00-1–10000
rescaleFLOAT0.000–1
rescale_modeCOMBOfull3 options: full, partial, snf
unet_block_listoptSTRINGd2.2-9,d3Blocks to which TPG is applied.

Outputs (1)

NameTypeDescription
MODELMODEL