ComfyUI Node

MegaCFGGuider

Warm-up, decay, and a reference-image tug, all in one guider

By Clybius·Created 3 years ago·Updated 2 years ago· 104
MegaCFGGuider
  • model
  • positive
  • negative
  • latent_image
  • GUIDER
cfg_max8.0
cfg_min1.0
warmup_percent0.50
mean_cfg0.0
image_guidance1.00
image_weighting
weight_scaling1.00

MegaCFGGuider is the "why choose" answer to guider nodes: it rolls dynamic CFG and reference-image guidance into one GUIDER output you plug into a custom sampling node. From the ComfyUI Extra Samplers pack by Clybius, this is the Swiss-army guider - CFG that ramps, CFG that decays, and a pull toward a reference latent, all with weights you control.

First, the CFG side. Instead of a flat classifier-free-guidance value, you give it a cfg_max, a cfg_min, and a warmup_percent. During the early part of sampling it applies the high CFG, then eases down toward cfg_min as denoising proceeds - the classic recipe for "strong prompt lock at the start, less overcooking at the end." That dynamic-CFG pattern is worth knowing about regardless of this pack: a fixed high CFG is what produces burned, oversaturated images, and ramping it down late in sampling is one of the standard fixes.

The second feature is the genuinely unusual part: optional image guidance. Wire a latent_image in (same size as the diffusion latent) and set image_guidance above 0, and the guider tugs each step's result toward that reference latent via a post-CFG correction. image_weighting (linear down / cosine down) controls how hard the tug pulls in early steps versus late, and weight_scaling shapes the curve. This is a different mechanism from img2img - you're not injecting noise, you're steering the denoised output toward a target composition, which makes it useful for "hold the layout, re-render the content" experiments.

The inputs that matter:

  • cfg_max / cfg_min / warmup_percent - the dynamic CFG envelope. mean_cfg (default 0) optionally pushes the effective CFG toward a target; leave at 0 to start.
  • image_guidance - 0 disables the image tug entirely; 1 is a reasonable first value.
  • image_weighting - linear down / cosine down. Both fade the reference's influence over the run.
  • latent_image - optional. Needs to match the diffusion latent's size (VAE-encode your reference).

Output: a single GUIDER, fed into the guider input of SamplerCustom, SamplerCustomNoise, etc., in a custom sampling chain.

The source shows the reference mechanism plainly: it projects the reference latent, computes a residual against the positive conditioning, and adds (cfg_result - residual) * image_guidance * weight to the CFG output each step. It's all in-graph - no API, no extra files.

Install is the shared pack routine (ComfyUI Manager → "ComfyUI Extra Samplers", or clone + restart), dependency kornia, no models. Where people get burned: feeding a reference latent of a different size than the diffusion latent, or cranking image_guidance into double digits and getting output that looks like it's fighting itself. Start with image_guidance at 1, weight_scaling at 1, and a linear weighting, then move one knob at a time.

Categorysampling/custom_sampling/guiders

Inputs (11)

NameTypeDefaultDescription
modelMODEL
positiveCONDITIONING
negativeCONDITIONING
cfg_maxFLOAT8.00–100
cfg_minFLOAT1.00–100
warmup_percentFLOAT0.500.01–1
mean_cfgFLOAT0.00–100
image_guidanceoptFLOAT1.00-1000–1000
image_weightingoptCOMBO2 options: linear down, cosine down
weight_scalingoptFLOAT1.000.01–100
latent_imageoptLATENT

Outputs (1)

NameTypeDescription
GUIDERGUIDER