Save 4 hours! We auto-setup your workflow! Free!

Drop your workflow.json — we handle every dependency, custom node, and model. Just open the link and run.

Auto-Setup Workflow Json (Free) Now!
ComfyUI > Nodes > comfy-cfg-megapack > PAG: Perturbed-Attention Guidance (Ahn et al. 2024)

ComfyUI Node: PAG: Perturbed-Attention Guidance (Ahn et al. 2024)

Class Name

CFGP_PAG

Category
CFG Megapack/papers/weak branch (a degraded pass of the model itself)
Author
abstracteyes (Account age: 2252days)
Extension
comfy-cfg-megapack
Latest Updated
2026-10-09
Github Stars
0.0K

How to Install comfy-cfg-megapack

Install this extension via the ComfyUI Manager by searching for comfy-cfg-megapack
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter comfy-cfg-megapack in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Description

Applies Perturbed-Attention Guidance to a model, tuning strength and blocks for coherent images.

PAG: Perturbed-Attention Guidance (Ahn et al. 2024):

CFGP_PAG applies Perturbed-Attention Guidance (PAG) to a diffusion model. During image generation, PAG makes an additional prediction in which selected self-attention blocks are perturbed: instead of relating image regions to one another, each position attends only to itself. The generation process is then guided away from that perturbed prediction, which can help the model produce more coherent image structure. The supplied specification describes this guidance as an addition to classifier-free guidance (CFG), not a replacement for it. PAG does not require retraining the model, but its additional prediction can increase generation work. The supplied specification identifies SDXL and SD1.5 UNets, while the node’s block guidance also describes mappings for Anima and other Cosmos-Predict2 transformers; compatibility with a particular model still depends on the implementation’s support check. (arxiv.org)

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Input Parameters:

model

The MODEL to which PAG is applied. Connect the diffusion model you intend to use for image generation. This node returns a modified MODEL for downstream use; it does not generate an image by itself. The interface provides no default or minimum and maximum values for this connection. The implementation checks whether the supplied model supports the required weak-guidance method and can reject an unsupported model.

scale

Controls the strength of the guidance away from the perturbed prediction. A larger value gives that difference more influence during generation; a smaller value reduces its influence. The default is 3.0, the minimum is 0.0, the maximum is 20.0, and the adjustment step is 0.1. The supplied guidance suggests exploring roughly 1.5–5 and starting at 1.5 when CFG is also enabled. These are tuning suggestions, not additional limits; the best result depends on the model and image you are making.

blocks

Selects which self-attention blocks PAG perturbs. This determines where the model’s normal exchange of information between image positions is interrupted for the additional prediction, so changing it can change the visual effect. The default is middle (PAG / SEG default). This is a single-choice setting with these exact options: middle (PAG / SEG default), middle + first output, deep output (output 0-2), deep input (input 7-8), and all SDXL attention blocks. The names describe SDXL blocks; the supplied tooltip says the middle block also exists on SD1.5. For Anima and other Cosmos-Predict2 transformers, it defines middle as the two middle blocks, deep input as the first third, and deep output as the last third. There is no numeric minimum or maximum for this parameter.

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Output Parameters:

MODEL

The MODEL returned with the PAG configuration applied for downstream generation. Connect it where your workflow expects a model, such as the model connection used by a sampler. This output is not an image or a report of image quality: its significance is that subsequent generation can use the selected PAG strength and attention-block choice. Receiving a MODEL output establishes that the node returned a model; it does not, on its own, demonstrate that a complete sampling run succeeded.

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Usage Tips:

  • Start with middle (PAG / SEG default) to evaluate PAG before changing which attention blocks are affected. Compare images using the same prompt, seed, and other generation settings so you can judge the change more clearly.
  • When your workflow already uses CFG, try scale at 1.5 as suggested by the supplied specification, then increase it gradually if the effect is too subtle. The interface’s default is 3.0; it is not the specification’s suggested starting value for the CFG-on case.
  • Explore the other blocks options one at a time if the middle-block setting does not give the result you want. Keep scale fixed during that comparison so you can distinguish the block choice from a strength change.
  • Account for the additional perturbed prediction when estimating generation time or memory needs. PAG’s method requires extra computation during sampling, though the supplied node source does not quantify the overhead for a particular workflow. (arxiv.org)

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Common Errors and Solutions:

ValueError: <model-support details>

  • Explanation: Before returning the modified model, the node calls a weak-guidance support check. If that check reports a problem, the node raises a ValueError containing the check’s details, with the feature name changed to PAG. The supplied source does not provide one fixed full message.
  • Solution: Read the specific support details shown in your error. Try a model and architecture supported by this PAG implementation; the supplied specification identifies SDXL and SD1.5 UNets. Do not assume that every model offering an attention-block choice is compatible.

model input is missing or has the wrong type

  • Explanation: model is a required MODEL connection. A disconnected input, or a connection from an incompatible output type, cannot supply the model the node needs. The supplied source does not specify the host application’s exact validation-message wording.
  • Solution: Connect a MODEL output to model and check that the upstream model loaded successfully.

scale is outside 0.0 to 20.0

  • Explanation: The declared FLOAT input has a minimum of 0.0 and a maximum of 20.0. A value outside that range does not match the node interface. The supplied source does not establish whether your host will reject or adjust an out-of-range value.
  • Solution: Set scale within the declared range. For initial tuning, use the supplied 1.5–5 guidance rather than jumping to an extreme.

blocks value is not one of the listed options

  • Explanation: blocks is a single-choice COMBO input, so an unrecognized value does not match its declared options. This can arise when a saved workflow contains a value that differs from those in the loaded node interface; the exact host validation message is not provided.
  • Solution: Re-select one of the five options shown in the blocks menu. Start with middle (PAG / SEG default) if you are unsure which to use.

Generation fails after the node returns MODEL

  • Explanation: The supplied implementation shows how this node checks support and returns a patched model, but does not establish the cause of every possible downstream sampling failure. A returned MODEL is not evidence that inference completed successfully.
  • Solution: Check the downstream error message first. Confirm the sampler is connected to this node’s MODEL output, then test the same model without PAG to help isolate whether the failure is associated with PAG or another part of the workflow.

PAG: Perturbed-Attention Guidance (Ahn et al. 2024) Related Nodes

Go back to the extension to check out more related nodes.
comfy-cfg-megapack
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

PAG: Perturbed-Attention Guidance (Ahn et al. 2024)