Negative cross attention
This model patcher subtracts your negative prompt inside the attention, not via CFG
- model
- Model
The pitch
Every SDXL generation runs the model twice per step: once with your positive prompt, once with the negative (or empty) one, and the gap between them - scaled by your CFG - is what steers the image. That classifier-free guidance trick is ancient and it works, but it means your negative prompt only ever influences the output indirectly, as one half of a whole-model subtraction.
This node does something weirder: it patches the model's cross-attention so the negative conditioning is subtracted inside the attention math, at every layer, instead of as guidance. The author - Extraltodeus, the same person behind depthmap2mask and CLIP-Token-Injection - calls it an experiment, and it really is one. It's been tested on SDXL and SD 1.x only, last touched in March 2025, and the README is upfront that it doesn't work with Flux. But for SDXL it's a legitimately interesting way to spend an afternoon.
Honest framing: if what you want is negative-prompt control on a CFG-1 or distilled model, the tool you actually want is NAG (ComfyUI-NAG). This pack is a different job - pushing negative influence harder, or keeping your unconditional pass genuinely unconditional on classic SD models.
How it works
It's a model patcher, same family as every "plug right after the model loader" node. It clones your MODEL and replaces the cross-attention (attn2) call on all 12 blocks of the input, middle, and output stages. The companion node in this pack - "Negative cross attention concatenate" - first sneaks your negative conditioning onto the end of your positive one. The patcher then splits that combined tensor in half before attention: first half positive tokens, second half negative.
Inside the patched attention it computes softmax attention against the positive keys/values and against the negative keys/values, subtracts the negative result from the positive one, projects the difference, and adds it into the attention weights scaled by strength. Net effect: the negative prompt bends attention away from what it describes, without ever adding an extra model pass.
The patcher also installs a safety net: a post-CFG check that aborts generation the moment it sees NaN or inf values instead of rendering out a dead image. Nice touch, and a hint at how spicy this patch can get.
The inputs and output
Only three wires to think about:
- model (MODEL): your checkpoint, straight from the loader.
- strength (FLOAT): how hard the negative difference is pushed into the attention weights. Default 1.0, range 0–100, step 0.25. Below 1 is subtle; crank it and expect overblown results - the author warns you'll want an anti-burn or a low CFG if you double down.
- Model (MODEL): the patched model, wired into your sampler's
modelinput.
Installing it
Standard stuff. Either search ComfyUI Manager for "Negative-attention-for-ComfyUI-" and click install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Extraltodeus/Negative-attention-for-ComfyUI-
Then restart ComfyUI. That's the whole install - the repo has no requirements.txt at all, no models to download, no Python deps beyond what ComfyUI already ships. It only imports ComfyUI's own attention module and torch.
Wiring it up
CheckpointLoader → Negative cross attention → KSampler (model)
CLIPTextEncode(positive) ─┐
├→ Negative cross attention concatenate → Positive → KSampler (positive)
CLIPTextEncode(negative) ─┘ → Negative → KSampler (negative)
The concatenate node is mandatory - without it there's no negative half to subtract and this node has nothing to do.
Gotchas
- SDXL / SD 1.x only. Flux, no. The author spent two hours hunting for the equivalent cross-attention patch hook and never found it; the README literally asks for help.
- The effect can be subtle. The community's general verdict on SDXL negative-attention guidance is that it's weaker than people hope. This is the fiddly, experimental version of that idea.
- The patch falls back to plain attention if the concatenated conditioning is short enough (≤ 77 tokens) that there isn't really a second half to split - rare on SDXL, but
crop_to_shortestwith terse prompts can trigger it, and the trick silently stops applying. - Doubling down with the concatenate node's
invertmode? Keep strength sane or drop CFG. Burned, over-saturated images are the expected failure mode.
Should you use it?
It's a toy with a good idea in it, and that's fine. If you want a permanent negative-prompt improvement on SDXL, tune your embeddings and CFG first. Reach for this when you want to actually see how negative conditioning steers attention.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| strength | FLOAT | 1.000–100 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Model | MODEL | — |