Nodes/ComfyUI-AutomaticCFG/Automatic CFG - Attention modifiers tester
ComfyUI Node Runs on cloud

Automatic CFG - Attention modifiers tester

Brute-force which attention layer your experiment wants

By Extraltodeus·Created 3 years ago·Updated 24 days ago· 428
Automatic CFG - Attention modifiers tester
  • join_parameters
  • Attention modifier
  • Parameters as string
seed0
sigma_start1000.0
sigma_end0.0
self_attn_mod_eval
unet_block_id_input4,5,7,8
unet_block_id_middle0
unet_block_id_output0,1,2,3,4,5
unet_attn

The "Attention modifiers" node lets you aim one eval expression at specific blocks. This one does the same thing, but it cycles through a whole list of blocks as you bump a seed, so you can run one experiment across every candidate layer and see where it does something interesting. It's the difference between asking "does this attention tweak work?" and actually finding where it works.

Mechanically it's trivial: give it a comma-separated list of block IDs per UNet section, and it builds the full sequence (input IDs, then middle, then output), then picks seed % len(sequence). Change the seed by one, the patch moves to the next block. The Parameters as string output even tells you your progress: Progress: 3/11 plus which block is active. Combined with a fixed sampler seed, it's a clean sweep of an attention experiment across the network.

The inputs that matter

  • self_attn_mod_eval - the expression to evaluate inside attention, same grammar as the plain modifier node (q, k, v, extra_options in scope). The defaults listed on the node come pre-filled with a reasonable sweep: input 4,5,7,8, middle 0, output 0,1,2,3,4,5 - 11 blocks total, so seeds 0–10 cover them all.
  • seed - which block in the sequence gets patched. This is a block selector, not an RNG: it's only used for seed % len(sequence).
  • unet_block_id_input / _middle / _output - the candidate lists per section.
  • unet_attn - attn1, attn2, or both.
  • sigma_start / sigma_end - when the patch is active during sampling.

Optional join_parameters chains onto an existing ATTNMOD list, same as the parent node.

Outputs

  • Attention modifier (ATTNMOD) - feed into the Preset Loader, Advanced, Excellent attention, or Custom attentions.
  • Parameters as string - shows Progress, the active block, and the expression, so you can log which seed produced which render.

How you'd actually use it

Pick a modifier expression, wire the output into whichever patch node you're testing, fix your sampler seed, and render seeds 0, 1, 2, ... n. Each seed = the same tweak on a different layer. The blocks where the image changes dramatically are the ones worth keeping; the blocks where nothing happens were never listening anyway. It's the honest way to find what a perturbation does instead of guessing from architecture diagrams.

Same two caveats as every node in this family: the eval string is arbitrary code, so write your own and don't paste strangers', and most of these attention ideas were only really explored on SDXL. If a render errors mid-sweep, it's usually an expression that referenced something undefined - the traceback will tell you exactly which block died, which is, in a way, information.

Categorymodel_patches/Automatic_CFG/experimental_attention_modifiers

Inputs (9)

NameTypeDefaultDescription
seedINT00–18446744073709550000
sigma_startFLOAT1000.00–10000
sigma_endFLOAT0.00–10000
self_attn_mod_evalSTRING
unet_block_id_inputSTRING4,5,7,8
unet_block_id_middleSTRING0
unet_block_id_outputSTRING0,1,2,3,4,5
unet_attnCOMBO3 options: attn1, attn2, both
join_parametersoptATTNMOD

Outputs (2)

NameTypeDescription
Attention modifierATTNMOD
Parameters as stringSTRING