Nodes/pre_cfg_comfy_nodes_for_ComfyUI/Pre CFG variable scaling
ComfyUI Node

Pre CFG variable scaling

A CFG that fades across the generation — start strong, finish clean

By Extraltodeus·Created 2 years ago·Updated about a year ago· 66
Pre CFG variable scaling
  • model
  • MODEL
target_scale5.0
target_as_starttrue
proportional_to

A fixed CFG is a compromise. High guidance early gets your composition right; low guidance late keeps the colors from burning and the details from turning to plastic. "Pre CFG variable scaling" is the author's answer: a single node that makes your effective CFG move across the generation, from one value to another, without changing your sampler at all.

The mechanism is worth understanding because it's cleverer than it looks. The node can't just tell the sampler to use a different scale - the KSampler's cfg input is what it is. Instead it does the next best thing: it rewrites the negative prediction so that the CFG formula uncond + scale * (cond − uncond) produces the effective guidance you want. Given the sampler's cond_scale, it computes a blend ratio (target − 1) / (cond_scale − 1) and mixes the uncond toward the cond by that amount. Net result: that step behaves as if your CFG were target, even though the sampler is still running at its own scale. Same trick the pack's automatic-CFG node uses, just exposed with a schedule.

The inputs that matter:

  • target_scale - where your effective CFG lands at the other end of the run. Default 5.
  • target_as_start - the boolean that decides the direction. If true (default), the sampler's CFG is the value you start at and target_scale is where you finish; set it false and it's inverted. The defaults give you a high-CFG start that eases down to 5 by the end.
  • proportional_to - what the ramp is measured against: sigma (progress through the denoising schedule) or steps progression (raw step count). Sigma-based is usually the more faithful choice since steps aren't uniformly spread across sigmas, but both work.

There's no sigma window - the ramp runs for the whole generation by default, which is what you want from a schedule. And note the "variable" here is effective CFG, not a slider you wiggle: you pick two endpoints and a ramp, the node does the rest. If you instead want arbitrary per-step control, the pack's gradient-scaling node is the wilder cousin (it drives scale from an image/mask and can go to 500), but that's a different tool entirely.

The author's framing for the whole pack is that these chain together and "the order matters and depends on your needs," and variable scaling is one of the genuinely useful, non-gimmicky ones. It's essentially a no-cost dynamic-CFG schedule - the math is a weighted average per step, no extra forward passes - and it's the node I'd actually reach for over a hand-built per-step CFG ladder in a custom sampler.

Shared pack caveats apply: it needs a negative prediction to rewrite, so on CFG-1 / guidance-distilled models it bails (if not torch.any(conds_out[1]): return conds_out) and does nothing; and the author's testing was SDXL. Install is the usual:

cd ComfyUI/custom_nodes && git clone https://github.com/Extraltodeus/pre_cfg_comfy_nodes_for_ComfyUI

or ComfyUI Manager → search pre_cfg_comfy_nodes_for_ComfyUI → restart. No dependencies, no downloads. Start with the defaults on an SDXL workflow, watch how the late steps clean up, then flip target_as_start to feel the difference in direction.

Categorymodel_patches/Pre CFG

Inputs (4)

NameTypeDefaultDescription
modelMODEL
target_scaleFLOAT5.01–100
target_as_startBOOLEANtrue
proportional_toCOMBO2 options: sigma, steps progression

Outputs (1)

NameTypeDescription
MODELMODEL