Nodes/raylight/Normalized Attention Guidance (Ray)
ComfyUI Node

Normalized Attention Guidance (Ray)

Get Your Negative Prompt Back on Distilled Models

By komikndr·Created about a year ago·Updated 2 days ago· 409
Normalized Attention Guidance (Ray)
  • ray_actors
  • ray_actors
nag_scale5.0
nag_alpha0.50
nag_tau1.50

At CFG 1, your negative prompt is a ghost - there's no unconditional pass for it to steer, so it sits there doing nothing while you wonder why "blurry, deformed, bad anatomy" has zero effect. The KB's concepts essay calls this the single most confusing thing about the modern model era, and NAG (Normalized Attention Guidance) is one of the two real fixes (the other being "just write constraints positively"). RayNAGuidance is the Raylight port of the NAG node, and it's the one I'd reach for when a distilled-model workflow needs the negative field to actually work.

NAG's trick: instead of extrapolating predictions (which is what CFG does and what distilled models have no second pass for), it operates inside attention. It compares the attention outputs of the positive and negative conditioning passes and steers the negative one toward the positive with a normalized interpolation. Because it intervenes in the attention layer rather than in the guidance extrapolation, it restores negative prompting without requiring a CFG>1 double pass - the exact thing guidance-distilled models (Z-Image Turbo, ERNIE Turbo, Klein distilled, and friends) can't do.

Three inputs, and the defaults are genuinely good starting points:

  • nag_scale (default 5.0) - the guidance strength. The original NAG author's explicit caveat, echoed in the KB, is don't exceed 3. The default here is 5, which is hotter than the author recommends; if you see artifacts, the first thing to try is dialing this to 2–3.
  • nag_alpha (default 0.5) - blend between the guided result and the original positive attention output. 0.5 is a balanced midpoint; lower keeps the original more intact, higher commits harder to the guidance.
  • nag_tau (default 1.5) - the normalization clamp, in L1-norm space. It caps how much the guided attention can deviate from the positive's magnitude, which is what keeps NAG from blowing out.

Where it fits

Any Raylight workflow running a guidance-distilled model where negative prompts matter. It's a ray_actors-in/ray_actors-out patch that also disables the model's CFG-1 optimization (the source calls disable_model_cfg1_optimization() - that's how it gets its second attention pass on a CFG-1 model). Chain it after Ray Init Actor. On classic SD 1.5/SDXL at CFG 7, plain CFG already gives you negatives; NAG there is redundant.

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

The big one is nag_scale. The node's own default (5) contradicts the original author's "max 3" guidance, and that discrepancy is a real trap - if your NAG output looks overcooked, the fix is almost always scale, not the prompt. Also: NAG costs a second attention pass, so expect a slowdown. That's the price of negatives on a CFG-1 model, and it's the honest tradeoff baked into the technique.

CategoryRaylight/extra/guidance

Inputs (4)

NameTypeDefaultDescription
ray_actorsRAY_ACTORS
nag_scaleFLOAT5.00–50
nag_alphaFLOAT0.500–1
nag_tauFLOAT1.501–10

Outputs (1)

NameTypeDescription
ray_actorsRAY_ACTORS