APG: Adaptive Projected Guidance (Sadat et al. 2025)
Crank CFG to 12 without the image melting
- model
- MODEL
Here's the deal every SDXL user knows in their bones: push CFG past about 9 and the prompt adherence goes up while the image goes to hell - neon colors, clipped highlights, plastic skin. That isn't superstition. It's the geometry of what CFG does. APG (Adaptive Projected Guidance, Sadat, Hilliges & Weber, ICLR 2025) is the most useful of the recent attempts to fix it, and this is the pack's implementation, with the paper's own defaults.
It's also the one node in the pack with a genuinely large Reddit footprint behind the idea, mostly via SDNext and Wan workflows rather than this pack - people adopt APG long before they know what it stands for.
How it works
Plain CFG takes the difference g = c - u and multiplies it by w - 1. APG splits that difference
into two pieces at every pixel: the part that points along the conditional prediction c, and the
part perpendicular to it. Then it treats them very differently.
The parallel part is the one that scales up saturation, so it gets multiplied by eta - at the
paper's default of 0, it's switched off entirely. The perpendicular part carries the actual
compositional change, so it's kept. On top of that, the norm of g is capped, and a reverse momentum
term subtracts a fraction of the previous step's difference, which stops the push from
compounding. Written out, the paper's form is c + (w - 1)(g_perp + eta · g_par).
The upshot: high scales keep obeying the prompt without the whole image running off the gamut. This
is the mechanism the pack's CFG Mix: Direction Rules node exposes as one of four rules, and the pack's
CFG Govern: Angle Band node is a stricter relative of the same idea.
Inputs that matter
Five inputs, and two of them you should think about:
- model, and scale -
-1means "use the KSampler's cfg", which is the sane default. - eta (default 0) - how much of the along-
ccomponent survives.eta = 1with no cap and no momentum is exactly plain CFG, which makes it a free baseline switch. - norm_threshold (default 15) - the cap on the size of
g, in the latent's own units.0is no cap. If your images look unchanged, the cap is probably biting at a level your image never reaches; if they look flat, it's biting too hard. Tune it near APG's typicalgsize for your model, not by copying the number to a different architecture. - momentum (default -0.5) - the paper's SDXL value, negative because it's reverse momentum.
0turns it off. - formulation -
paperisc + (w-1) g';comfyuiisc + w g'(one unit more guidance, so it hits differently at the same number);diffusersisu + w g'. If you're porting settings from another UI, this is why your scale doesn't match. - space -
autouses the denoised image, which is where APG was published. Its projection is nonlinear, so changing the space changes the picture.
Output is a MODEL. Wire it between your loader and the sampler; the sampler's cfg is your scale.
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, no model downloads - it's pure torch and stdlib on top of ComfyUI. It needs ComfyUI 0.38 or newer.
Traps worth knowing
Only one CFG function per model. ComfyUI's model carries a single CFG-function slot. If you also loaded a RescaleCFG or Mahiro node from another pack after this one, the last one chained wins and APG quietly does nothing.
The pack always runs the unconditional pass. Its hook disables ComfyUI's CFG-1 optimization, so
on a distilled checkpoint where you'd normally run at cfg 1 you lose the "second pass is skipped"
speedup the moment any pack node touches the model. At cfg 1 these rules are also inert by
construction - w = 1 means no guidance to project.
Compare properly. Queue once with another seed first - ComfyUI's very first sampling after a
model load rounds slightly differently, so a fresh A/B pair can differ for reasons that have nothing
to do with APG. The pack's example_workflows/ templates render plain CFG and the variant from one
seed, which is the right way to judge it.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| scale | FLOAT | -1.0-1–100 | The guidance scale w for this rule. -1 uses the sampler's cfg value. |
| eta | FLOAT | 0.000–1 | Weight of the part along c (1 with no cap and no momentum = plain CFG). |
| norm_threshold | FLOAT | 15.00–100 | Cap on the norm of g (0 = no cap; choose near its typical size). |
| momentum | FLOAT | -0.50-1–1 | Reverse momentum on g (paper SDXL -0.5; 0 = off). |
| formulation | COMBO | paper | paper: c + (w-1) g'; comfyui: c + w g'; diffusers: u + w g'. |
| space | COMBO | auto (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)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |