ComfyUI Node

CFGStar

Fix the line your CFG extrapolates from, instead of cranking the scale

By bvhari·Created about a year ago·Updated about a year ago· 1
CFGStar
  • model
  • MODEL

The short version

CFG works by extrapolating: uncond + scale * (cond - uncond). That formula assumes your unconditional prediction is a good anchor to push away from. Often it isn't - and when it's off, you respond by raising CFG, which just makes the burn worse. CFGStar is a one-node fix for that. It rescales the unconditional prediction so it lines up with the conditional one first, then applies your CFG scale. Same prompt adherence, but without the oversaturation and melted faces you get from cranking the dial.

It's a model patch with exactly one input and one output. Feed it the MODEL you'd normally wire into a KSampler, take its MODEL output, done. No knobs, no model files, no extra dependencies. You can't really misconfigure it, which is why it's worth having around.

How it works

ComfyUI's standard CFG line is uncond_pred + (cond_pred - uncond_pred) * cond_scale. The CFGStar hook (registered as a post-CFG function on a clone of your model via set_model_sampler_post_cfg_function) inserts one step in front of that:

s = sum(cond * uncond) / (sum(uncond * uncond) + 1e-8)
uncond_scaled = uncond * s
return uncond_scaled + cond_scale * (cond - uncond_scaled)

That s is the least-squares projection coefficient - the single scalar that, multiplied by the unconditional prediction, makes it as close as possible to the conditional one. It's computed per channel (summed over the spatial dimensions), which is why the author describes this as the "per channel" scaled CFG. Then CFG runs as usual, but from a corrected reference.

This is the optimized-scale half of the paper behind it, CFG-Zero*: Improved Classifier-Free Guidance for Flow Matching Models (arXiv 2503.18886). The paper's argument: early in a flow-matching trajectory the velocity estimate is inaccurate, and plain CFG steers samples toward wrong trajectories as a result. The optimized scale corrects for that inaccuracy. The node only implements that piece - not the paper's "zero-init" trick of blanking the first few solver steps - so don't expect the full method, just the part that's cheap to bolt on.

Two honest caveats from the code. It does not skip the double pass, so you still pay normal CFG compute. And at CFG 1 it does nothing, mechanically: ComfyUI skips computing the unconditional pass entirely at scale 1, uncond comes through as zeros, s collapses to 0, and the node's output is just your conditional prediction. If you want it to matter, you need real CFG above 1.

Where it shines

The community consensus use is Wan 2.x video - the same post-CFG idea showed up in Wan I2V workflows around its release, and it suits any non-distilled model that runs genuine CFG in the 4–7 range. SD 1.5 and SDXL work fine too. The typical move: keep your normal CFG and A/B against the patched model; you'll usually find you can hold the same prompt adherence with a scale one or two points lower, or keep the scale and get noticeably tamer colors.

Install and troubleshooting

Install is boring in the good way. In ComfyUI Manager search CFGStar (pack title ComfyUI_CFGStar), or:

cd ComfyUI/custom_nodes
git clone https://github.com/bvhari/ComfyUI_CFGStar

Restart ComfyUI. There's no requirements.txt and no model download - the only dependency is PyTorch, which ComfyUI already ships. It's registered in the Comfy Registry, so Manager handles updates.

Real-world gotchas, from the code and the KB:

  • No visible change at your usual settings? Check your CFG. If it's at 1 (Turbo/Lightning/guidance-distilled models, most of 2026's releases), the node is a silent no-op - it's not a NAG-style negative-prompt restore, it needs real guidance. This catches a lot of people.
  • Still burning at CFG 7? The corrected reference already buys you adherence, so drop the scale a notch instead of raising it.
  • Flux? Flux's guidance parameter isn't true CFG, so don't expect this to do anything meaningful there.
  • It won't speed up generation or cut VRAM. It's a quality patch, not an accelerator.
Categoryadvanced/model

Inputs (1)

NameTypeDefaultDescription
modelMODEL

Outputs (1)

NameTypeDescription
MODELMODEL