ComfyUI Node

Apply APG CFG

Crank your CFG to 15 without deep-frying the image

By logtd·Created 2 years ago·Updated 2 years ago· 29
Apply APG CFG
  • model
  • MODEL
eta1.00
norm_threshold0.30
use_momentum
momentum0.05

Half of the "why is my SDXL image burned" posts you'll ever read get answered with the same three words: lower your CFG. Fair advice, but it misses the point. CFG is how hard you're pushing the model to actually do what you asked - the last thing you want is less of it. This node is the have-it-both-ways answer. It swaps ComfyUI's default classifier-free guidance math for APG (Adaptive Projected Guidance), a 2024 method that lets SD 1.5/SDXL-lineage models run at CFG 10–20 without the oversaturation, blown contrast, and melted faces that normally show up around 10–12. The pack README's demo images are all SDXL at CFG 15, APG off vs on - it's not a subtle tweak.

APGFunction is the only node in the logtd/ComfyUI-APGScaling pack, and it's a small one. It shows up in ComfyUI as "Apply APG CFG."

How it works

APG belongs to the "CFG patcher" family you'll hear mentioned alongside Skimmed CFG, AutoCFG, Perturbed Guidance, and PAG - they all replace ComfyUI's one-line CFG formula, uncond + (cond - uncond) * scale, with something smarter. Where vanilla CFG just multiplies the whole guidance direction by the scale and slams it in, APG first splits the update into two components relative to the conditional prediction: one parallel to it and one orthogonal to it. The paper's bet is that the orthogonal part is what fixes structure and composition while the parallel part is what overdrives saturation and burns the image. So APG keeps the orthogonal part at full strength and lets you scale the parallel part separately (that's eta), and it clamps the total update's magnitude so no single step can shove the image too far (norm_threshold). Result: you can jack up the CFG number for real prompt adherence and the burn just… doesn't arrive.

Under the hood it clones your model and installs a custom sampler-CFG function on the clone, so your original loader node is untouched and the patch only affects the sampler that patched output feeds. And there's no speed penalty beyond regular CFG - same two forward passes, just a different way of combining them.

The inputs that matter

Five inputs, and after the first run you'll basically only touch two:

  • model - wire this from your checkpoint or UNET loader.
  • norm_threshold (default 0.3) - caps how big the guidance update can be per step. Too low and you lose prompt adherence; too high and the burn creeps back.
  • eta (default 1.0) - how much of the parallel component survives. This is your saturation dial.
  • use_momentum / momentum (default enable / 0.05) - a running average of the guidance direction across steps to smooth jitter. The buffer auto-resets when sigma jumps back up, like on a second-pass/high-res generation. Leave these alone until you've got a feel for the other two.

The single output is a patched MODEL, straight into the KSampler's model input.

Install

One-node pack, zero dependencies beyond PyTorch (which ComfyUI already has - no requirements.txt, no model files to download). Easiest via ComfyUI Manager: search "ComfyUI-APGScaling", install, restart. Or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/logtd/ComfyUI-APGScaling

Restart ComfyUI and the node appears under the apg category.

Where people trip

  • Order matters. It's a model patch, so the community consensus holds: Loader → LoRAs → CFG modifiers like this → KSampler. Plug it in before the LoRAs and the LoRA weights won't see the patched model path cleanly.
  • It earns its keep at high CFG. At 7 it's roughly a no-op; the whole point is pushing to 12–20. Start around 15 like the README's examples, then tune.
  • It's an SD-family tool. SD 1.5, SDXL, Pony, Illustrious, and similar DDPM-style checkpoints - that's where CFG is a real knob. On guidance-distilled flow models (CFG 1 by design) there's nothing to amplify, so don't bother. People do reach for it on Wan video too, but the same CFG-too-high logic applies.
  • Negatives still work. It replaces the combination math, not the unconditional pass, so your negative prompt behaves normally - good, because that trips people up with some CFG hacks.

If your first attempt looks washed out, raise norm_threshold a little before you blame the node - defaults are tuned to be safe, not maximum.

Categoryapg

Inputs (5)

NameTypeDefaultDescription
modelMODEL
etaFLOAT1.000–10
norm_thresholdFLOAT0.300–10
use_momentumCOMBO2 options: enable, disable
momentumFLOAT0.05-1–1

Outputs (1)

NameTypeDescription
MODELMODEL