Nodes/CFG Megapack/Automatic CFG (Extraltodeus)
ComfyUI Node

Automatic CFG (Extraltodeus)

Stop guessing the scale, let the node pick it

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
Automatic CFG (Extraltodeus)
  • model
  • MODEL
◄scale-1.0►
◄reference_scale8.0►
◄top_k0.25►
◄modehard►
◄spaceauto (the method's own)►

Every other node in this pack asks you a question about a scale. This one is the community answer to that question, and it's the most popular idea in the whole batch: Extraltodeus's Automatic CFG node has been a standard part of SDXL workflows for years, its update threads pulling scores in the 70s–120s, and its whole selling point is that you stop setting CFG at all.

The trick is that a single global guidance scale is a blunt instrument. The four channels of an SDXL latent aren't doing the same job - one of them carries most of the luminance-ish structure, others carry color information - and one scale multiplies all of them equally. Automatic CFG picks a scale per channel, at each step, chosen so that channel's guided range lands on the range you'd get at a reference scale. You name the reference (reference_scale, default 8) and let it do the arithmetic per channel.

Inputs

  • model - the usual wire from the loader.
  • scale (default -1) - the guidance scale for the rule; -1 takes the sampler's cfg. As with everything in the pack, this still matters - Automatic CFG corrects what CFG produced, it doesn't replace the base scale.
  • reference_scale (default 8) - the scale whose range you're targeting. 0 means "use the sampler's cfg". This is the input people actually tune: it's the answer to "what CFG do I wish I was running", and 8 is a sensible SDXL answer. Lower it (5–6) for a softer, less contrasty image.
  • top_k (default 0.25) - the share of values averaged to measure that range. The higher it is, the more the measurement is pulled around by outliers; 0.25 keeps the extremes out of the average.
  • mode (default hard) - how the range is measured. The options are hard, soft, hard_squared and range, and hard is the community node's classic behaviour. Probe the others only once you know what plain hard does on your model, or you're changing two things at once.
  • space - auto uses the method's published space (noise prediction).

Output: a MODEL.

Install

# ComfyUI Manager: search "CFG Megapack" -> Install -> restart
# or:
comfy node install comfy-cfg-megapack
# or by hand:
cd ComfyUI/custom_nodes && git clone https://github.com/AbstractEyes/comfy-cfg-megapack

No dependencies and nothing to download - the pack is torch plus the standard library. ComfyUI 0.38+ is required, since it uses comfy_api.latest.

The one you'll want to compare against

There are now two Automatic CFGs in most people's custom_nodes folder: Extraltodeus's original pack (which also brings attention modifiers, temperature and preset saving) and this paper node. They are not the same implementation - this one is the pack's re-implementation of the rule, sitting on the pack's shared engine, which means it composes with the pack's other stages. If you want the original's extras, install the original; if you want to chain this with a schedule or a correction, use this one. Running both on the same model wire is pointless - ComfyUI's model carries a single CFG function and the last node chained wins.

Also worth knowing from the original's history, because it's the reason the node got popular: the Extraltodeus pack discovered it could disable the unconditional pass entirely for a large speed win (its "uncond disabled" update). This pack's node does the opposite: the hook it installs sets ComfyUI's disable_cfg1_optimization flag, so the unconditional pass always runs. Automatic CFG needs u to do its per-channel arithmetic; there's no way around that. If your goal is speed, this isn't the node for it.

Practical setting notes

Automatic CFG is at its best when your problem is global - the whole image is too contrasty, or too flat, at every scale you've tried. It is at its worst when your problem is local (one subject, one region), which is a job for a mask or a regional prompt rather than a scale.

If the output looks like it lost punch, reference_scale is probably too low; if it looks like an over-sharpened SDXL render from 2023, it's probably too high. And keep in mind you're also, at this point, comparing against the whole correction family in this pack - CFG-Renorm caps the norm, EP-CFG matches energy, CFGNorm matches per-pixel lengths. Those are one-line corrections to a scale you already chose; this one chooses the scale. Different jobs, occasionally overlapping results.

CategoryCFG Megapack/papers/combining the two predictions

Inputs (6)

NameTypeDefaultDescription
modelMODEL—
scaleFLOAT-1.0-1–100The guidance scale w for this rule. -1 uses the sampler's cfg value.
reference_scaleFLOAT8.00–30The scale whose range is targeted (0 = the sampler's cfg).
top_kFLOAT0.250.01–1Share of values averaged for the range.
modeCOMBOhardHow the range is measured.
spaceCOMBOauto (the method's own)Where the rule is computed. Linear rules give the same image in any space; nonlinear ones do not. 'auto' uses the space the method was published in (noise for most, denoised for APG and the angle rule, velocity for flow models).

Outputs (1)

NameTypeDescription
MODELMODEL—