ContrastiveCFG Guider (Chang et al. 2024)
Weight the negative by how far it already got
- model
- positive
- negative
- null
- GUIDER
The thing nobody tells you about negative prompts is that a fixed negative weight is wrong most of the time. You write "blurry, ugly, deformed" with a weight of 1 and get a sharp, clean, anatomically normal image - at which point the negative is still being applied with the same force it had when the image was garbage. You're now subtracting a direction that describes a problem you no longer have.
ContrastiveCFG (Chang, Lee, Chung & Ye, ICML 2026) makes the weight adaptive, and the rule is elegant: each direction is weighted by how far it already is from the null prompt. If your positive prompt hasn't pulled the sample far from the empty prompt yet, it's still weak, so push harder on it. If your negative's direction is already well established - the model is already nowhere near the thing you're avoiding - back off on the negative. In the authors' words, more push while the positive is weak, less negative once the negative is far.
It's a guider, so like the other negative-prompt nodes here it lives on the SamplerCustomAdvanced side of the graph rather than patching a model.
Inputs
- model - the model wire.
- positive, negative, and null - three separate conditioning inputs.
nullneeds a genuinely emptyCLIP Text Encode; the tooltip calls it "the empty prompt: the true unconditional", and the whole rule is defined relative to it. Wiring your negative intonullbreaks the method rather than erroring. - cfg (default 7) - the scale. The guider owns it because SamplerCustomAdvanced's guider input is
where the guidance lives; there's no
scaleinput on this node. - w_neg (default -1) - the negative weight.
-1means "same ascfg", which is the sane starting point; the range goes to 30 if you want to see what happens. - tau (default -1) - the temperature, and the interesting one:
-1means calibrated per image. The method's whole point is that the weighting should follow the sample's own state, so leaving it at -1 is usually correct, and setting a positive number freezes the calibration to your value. - space -
autouses the method's published space.
Output: a single GUIDER, into SamplerCustomAdvanced.
Install
# ComfyUI Manager: search "CFG Megapack" -> Install -> restart
# or:
comfy node install comfy-cfg-megapack
# or by hand:
cd ComfyUI/custom_nodes && git clone https://github.com/AbstractEyes/comfy-cfg-megapack
No dependencies and nothing to download - the pack is torch plus the standard library. ComfyUI 0.38+ is required.
What you're paying for it
Three model predictions per step (positive, negative, null), where classic CFG uses two and skips the
second at cfg 1. On an SDXL render with a heavy workflow you'll notice; on a 5-step distilled model
you'll notice a lot. Also note the pack's hook never enables disable_cfg1_optimization - it's the
opposite, the pack needs the unconditional path - so you're not going to claw that time back by
dropping cfg.
The consolation is that this is the one class of node in the pack that does something on a guidance-distilled model. At cfg 1 the standard sampler has no unconditional pass and the negative box is inert; a guider constructs the passes explicitly, so negatives work again. If you're on a 2026 model and missing your negative prompts, contrastive weighting is a more principled entry point than just cranking the weight.
Where it sits in the pack's negative-prompt menu
Same folder, four neighbours, all guiders: Perp-Neg (use only the perpendicular part of the
negative, so it can't cancel the positive), Composable NOT (u + w(c - n), the literal
subtraction), Signed guidance (both prompts measured from the null), and Safe Latent Diffusion
(steer away from a concept only where the image is actually moving toward it, with momentum and a
warm-up). ContrastiveCFG is the one to pick when your negative is working too well in the late
steps - over-clean, plasticky, losing texture - because that's precisely the failure mode its adaptive
weighting addresses.
The pack's general-purpose guider node, CFG Guider: Positive, Negative and Null, implements the
simpler rules (perp_neg, separate_negative, and negative_as_null for a reference that is
bit-identical to ComfyUI's own CFGGuider). If you want to measure whether ContrastiveCFG earns its
three passes, run negative_as_null as the control on the same seed - anything else is comparing two
changes at once.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| positive | CONDITIONING | — | |
| negative | CONDITIONING | — | |
| null | CONDITIONING | The empty prompt: the true unconditional. | |
| cfg | FLOAT | 7.00–100 | — |
| w_neg | FLOAT | -1.0-1–30 | Negative weight (-1 = w). |
| tau | FLOAT | -1.00-1–100 | Temperature (-1 = calibrated per image). |
| space | COMBO | auto (the method's own) | Where the rule is computed. Linear rules give the same image in any space; nonlinear ones do not. 'auto' uses the space the method was published in (noise for most, denoised for APG and the angle rule, velocity for flow models). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| GUIDER | GUIDER | — |