ComfyUI Node

PowerLawCFG

The CFG dial that thinks per step — PowerLawCFG (powerlaw-cfg_cui-ggf)

By xxiiyu·Created 9 months ago·Updated 9 months ago· 0
PowerLawCFG
  • model
  • MODEL
◄alpha0.90►
◄parameterizationscore►
◄print_debugfalse►

Plain CFG applies one fixed scale to (pos − neg) at every denoising step. PowerLawCFG (powerlaw-cfg_cui-ggf) makes that scale adaptive: it looks at how far apart your positive and negative predictions are at each step and damps or amplifies the guidance accordingly. It comes from the same "generalized guidance" paper as the rest of the cui_generalized_guidance_forms pack (arXiv 2502.07849), and the author is the kind of source worth trusting - he's said flat out that he uses this node on basically every generation with a non-distilled model.

How it works

Both nodes in this pack write the denoised output in the generalized form x_neg + (x_pos − x_neg) · φ_t, where φ_t is a per-step weight. For PowerLawCFG, that weight is

effective scale = ( || x_pos − x_neg ||₂ )^alpha
  • the L2 norm of the difference between the two predictions, raised to the power of alpha, then multiplied by your KSampler's CFG value. Read it as: when the positive and negative predictions basically agree, guidance has nothing to steer with, so it backs off; when they diverge sharply, it leans in. The result is a schedule that's more confident when the model is genuinely torn and quieter when it isn't.

The inputs that matter

Only three widgets, and really only two you'll touch:

  • alpha (FLOAT, default 0.9, range −0.99 to 100) - the exponent. 0 disables the node. Values above 0 are what the paper authors recommend (dampen-when-similar, amplify-when-dissimilar). Below 0 flips it into a mode that speeds up convergence to the target in early steps, which is more of an experiment than a default. The code clamps the effective scale to a minimum of 1, so it can't push you into negative guidance.
  • parameterization (COMBO, default score) - which prediction space the difference is measured in. You do not have to match this to your model type, and in practice score is the most stable, so leave it alone unless you have a reason. x0 is the paper's "rescaled power-law CFG"; eps/v/flow are there for completeness.
  • print_debug (BOOLEAN, default false) - logs the L2 norm, the computed scale, and the effective CFG to the console each step. Flick it on once to see the schedule in action; it's the best way to convince yourself the node is alive.

Output is a single MODEL, wired into the KSampler's model socket. That's the whole hookup.

Where it belongs in a workflow

This is a smarter CFG schedule for non-distilled models - SD 1.5, SDXL, Pony/Illustrious and friends, where you want to push prompt adherence without the usual burn that comes from cranking one static number. On distilled checkpoints (Turbo, Lightning, Flux-family, Z-Image Turbo) skip it: they run at CFG 1 by design and added guidance just burns the image. And remember it multiplies your CFG box, it doesn't replace it - effective CFG = your value × the power-law factor. Start with alpha 0.9 and your usual CFG, then change one thing at a time on a fixed seed.

Installing it

ComfyUI Manager → search CUI-GeneralizedGuidanceForms, or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/xxiiyu/cui_generalized_guidance_forms.git

Restart ComfyUI after. Zero pip dependencies, zero model downloads, GPL-3 - just pure Python that rides on ComfyUI's set_model_sampler_cfg_function hook, so any reasonably current install works.

Gotchas

  • CFG 1 still runs both passes. At alpha ≈ 0 the node disables ComfyUI's CFG-1 skip, because the negative term no longer cancels out. Don't expect the usual half-price speedup.
  • Chasing a bug that's actually RNG. The standing community objection to every CFG trick applies here double: change alpha alone on a fixed seed, and run enough generations to tell a real gain from a luckier seed. Single-image comparisons prove nothing.
  • Weird results on a distilled model aren't a node bug - it's the wrong tool for that regime.

For anyone who runs non-distilled models and wants guidance that behaves, this is the one node in the pack the author actually reaches for daily. Cheap to install, one knob, hard to make worse.

Categoryadvanced/guidance

Inputs (4)

NameTypeDefaultDescription
modelMODEL—
alphaFLOAT0.90-0.99–100The exponent for the 'power law,' which finds a number to multiply `cfg` by at each step. Values > 0 are recommended by the paper authors. 0: disable <0: guidance which speeds up convergence to the target at early times >0: dampen guidance if positive and negative are similar; amplify guidance if positive and negative are dissimilar.
parameterizationCOMBOscoreThe space in which to calculate the scale. You do NOT have to match this with your model type, they can be different. In practice, `score` seems to be the most stable. score: The default implementation. x0: 'Rescaled Power-law CFG' in the paper. eps/v/flow: Other parameterizations for completeness's sake.
print_debugBOOLEANfalsePrint this node's calculations to console at each sampling step.

Outputs (1)

NameTypeDescription
MODELMODEL—