Nodes/raylight/PerturbedAttentionGuidance (Ray)
ComfyUI Node

PerturbedAttentionGuidance (Ray)

Detail Without a Negative Prompt

By komikndr·Created about a year ago·Updated 2 days ago· 409
PerturbedAttentionGuidance (Ray)
  • ray_actors
  • ray_actors
scale3.00

Here's the thing about modern distilled models: they run at CFG 1, which means no second (unconditional) pass, which means the negative prompt does nothing, and which means the usual "push harder for detail" tricks are off the table. PAG (Perturbed Attention Guidance) is the workaround - it generates the perturbed second pass not by dropping the prompt but by breaking the attention itself, so you get a guidance signal on models that can't do traditional CFG. RayPerturbedAttentionGuidance is the Raylight port.

The mechanism is delightfully blunt. On a second forward pass, the node replaces the value stream V in the middle attention block with just V (it short-circuits the attention so the output is basically the values with no mixing - the "perturbation"), then adds a scaled difference between the clean result and that perturbed result to the denoised output. scale (default 3.0) controls how much of that difference you inject. Set it to 0 and the node does nothing at all - it's a bypass, not a different mode.

Why this works on CFG-1 models: the perturbed pass isn't "unconditional," it's broken in a controlled way. The difference between clean and perturbed highlights where the model's own attention is struggling - a proxy for detail that doesn't require a negative prompt. In practice PAG gives a crispness boost and better local structure on DiT models, and because it needs no second condition, it plays nice with guidance-distilled checkpoints where raising CFG would just burn the image.

Where it fits

Any Raylight DiT workflow - Flux, Qwen-Image, Wan, Chroma - where you want a detail push without touching CFG. It's one ray_actors-in/ray_actors-out patch, chainable after Ray Init Actor. It composes with the other post-CFG patches (SkipLayer, NAG) because each hooks a different stage, but as with any guidance stacking, verify on a test image before committing - two detail-pushing mechanisms can overshoot into that plastic, overcooked look the KB warns about.

Install

Part of raylight:

cd ComfyUI/custom_nodes
git clone https://github.com/komikndr/raylight
cd raylight
pip install -r requirements.txt

Restart, or install "raylight" via ComfyUI Manager.

Gotchas

  • This node requires an unconditional pass structure in the sampler - the source builds its perturbation against args["cond_denoised"] and returns early if there's nothing to compare. On a pure CFG-1 single-pass setup it may silently no-op, which is the classic "I added PAG and nothing changed" moment.
  • The middle block is a deliberate choice; PAG's paper found perturbing self-attention in the middle of the DiT is where the signal is. Don't read "why only the middle" as a bug.
CategoryRaylight/extra/guidance

Inputs (2)

NameTypeDefaultDescription
ray_actorsRAY_ACTORS
scaleFLOAT3.000–100

Outputs (1)

NameTypeDescription
ray_actorsRAY_ACTORS