Pre CFG gradient scaling
Steer a generation toward an image — no ControlNet, no ML, no extra model
- model
- input_mask
- input_latent
- MODEL
This is the flagship of the pack, and it's the one worth reading about. Pre CFG gradient scaling steers a generation toward matching an input image - light direction, color palette, even coarse layout - using pure arithmetic, no ControlNet, no extra model, no added render time. It exploits the slack that the CFG scale leaves in the sampling: the CFG formula's "wiggling room" between the cond and uncond predictions, which the node reshapes so the generation's values land closer to your guide image.
Here's the mental model, stripped down. CFG lets you pick how hard to push toward the prompt. This node, instead of using one flat scale for the whole image, computes a per-pixel scale map: it denoises at a low CFG and at a high CFG, compares both against your guide, and picks - for each pixel - the scale that best matches the guide's value. A giraffe is just an apple with different values, as the author puts it: this can't tell objects apart, it only matches numbers. That's the whole honest scope of the trick, and it's also why it's so fast and so useful for value-based things like lighting, color, and gradients.
The inputs, in order of what you'll actually touch:
maximum_scale(default 80) andminimum_scale(default 4.5) - the range of "CFG-equivalent" scales the node is allowed to use to match the guide. The author suggests you can push max as high as 500 and still get an output; 1000 means stop before the end.strength(default 0.5) - overall effect multiplier. Lower it if results feel too smooth.end_at_sigma(default 0.28) - stop the matching this early; stopping before the very end gives better results at extreme scales.converging_scales(default on) - makes min/max scales drift toward your sampler's own scale as generation progresses, weakening pattern-matching but usually improving the final image and allowing a bigger max.invert_mask(default off) - flips the mask's effect.
The optional inputs carry the guide: input_latent is an encoded image to match, and input_mask either confines the matching to a region or, when connected alone with no latent, becomes a per-area CFG scale. Nothing connected at all uses the positive prediction as the guide for 74% of the sigma range and the negative for the rest. It can be chained multiple times as long as the strengths sum to 1 or less - and the pack's Empty RGB image and Gradient RGB image nodes exist specifically to feed it guides.
When is it the right tool? ControlNet is still the choice for people, poses, and anything semantic. Gradient scaling wins on the value-driven stuff - a light-from-the-left gradient, a vignette, a color-field influence, a black-and-white pattern - at zero model cost and zero extra inference time. It's the author's own framing: faster than img2img, more flexible than a post-treatment, and completely non-ML.
Install with the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Extraltodeus/pre_cfg_comfy_nodes_for_ComfyUI
or via ComfyUI Manager searching pre_cfg_comfy_nodes_for_ComfyUI, then restart. No models, no extra dependencies - which is the whole point.
Where people get burned: expecting it to do ControlNet's job (it can't tell a banana from a person), and cranking strength plus a huge maximum_scale together (start near the defaults and tune one thing at a time). It's the most capable node in this pack, and it rewards exactly as much patience as you put in.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| maximum_scale | FLOAT | 800–1000 | It is an equivalent to the CFG scale. |
| minimum_scale | FLOAT | 4.50–10 | It is an equivalent to the CFG scale. |
| strength | FLOAT | 0.50–10 | — |
| end_at_sigma | FLOAT | 0.280–1000 | — |
| converging_scales | BOOLEAN | true | — |
| invert_mask | BOOLEAN | false | — |
| input_maskopt | MASK | If only a mask is connected the scale becomes a CFG scale of what is being masked. When a latent is connected the mask defines what will be modified by the node. | |
| input_latentopt | LATENT | If a latent is connected the scale becomes the maximum scale allowed in which to seek similarity. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |