Nodes/CFG Megapack/SAMG: spatially adaptive guidance (Li et al. 2026)
ComfyUI Node

SAMG: spatially adaptive guidance (Li et al. 2026)

A different cfg for every pixel, so the busy parts stop burning

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
SAMG: spatially adaptive guidance (Li et al. 2026)
  • model
  • MODEL
◄scale-1.0►
◄w_min-1.0►
◄w_max-1.0►
◄spaceauto (the method's own)►

If you've ever seen one part of an image look great and another part look cooked on the same render, you've met the problem SAMG is about. Guidance pushes hardest where the conditional and unconditional predictions disagree most - and that disagreement isn't uniform across the frame. It's concentrated at edges, textures, small objects, hair, foliage, fine text. So a single global cfg over-guides exactly the regions that were already fragile.

SAMG (Li et al., arXiv 2026) replaces that one number with a per-pixel scale. Busy pixels get a low scale, calm pixels get a high one. That's the entire idea, and it costs nothing in wall-clock time.

The mechanism

At each step you have the guidance difference delta = c - u. Per pixel, take the energy E = mean(delta²) across channels, then normalize it per image:

E_hat = (E - min E) / (max E - min E)
Omega = w_max - E_hat * (w_max - w_min)
d_hat = u + Omega * delta

So the pixel with the most guidance energy in the frame gets w_min and the calmest one gets w_max, with everything else interpolated. It's a per-image min/max, which means it re-normalizes every step - the mask follows the image as it forms rather than locking in place early.

The paper's own defaults were [5, 12] at a base scale of 7.5 on SD1.5/SDXL; the node's -1 values derive the pair from your scale as [w × 2/3, w × 1.6], which is that ratio.

Inputs and output

  • model - loader → node → sampler.
  • scale - the w this rule uses; -1 takes the sampler's cfg.
  • w_min - "Scale at high-energy pixels (-1 = w 2/3)". Leave it on -1 unless you're deliberately retuning; this is the end that controls the burn.
  • w_max - "Scale at calm pixels (-1 = w 1.6)". The end that keeps flat regions from drifting into mush.
  • space - auto (the method's own). The energy is computed on the difference, and while the squaring is nonlinear it's a fairly forgiving rule in practice.

One output: MODEL. Note the two ends are also permitted to be set explicitly, and setting them equal makes the node plain CFG - a useful control for an A/B pair.

Why you'd actually reach for it

It's the cheap answer to over-saturation when a rescale is too blunt. Standard-deviation rescale operates per image, so one blown-out region drags the correction for the whole frame; SAMG localizes it. It also composes with everything else, because it writes the combine stage rather than the correction stage.

The counterargument: it's per-pixel noise-shaped by min/max statistics, so on very early steps of a mostly-flat latent, the normalization is dividing by a tiny range and the mask is close to noise-driven. It tends to settle quickly, but if you're chasing exactness in an A/B comparison, that's a source of small differences.

Install

Manager → search CFG Megapack → install → restart. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/AbstractEyes/comfy-cfg-megapack

There's no requirements.txt and nothing to download; the pack leans on torch and the stdlib. It does need a recent ComfyUI, since every node is written against comfy_api.latest (the README reports 0.38.0 with torch 2.11, GPU and CPU-only). On an older build the pack won't import and you'll get nothing in the node search.

Where people get burned

It's not a schedule. SAMG changes the scale per pixel within a step; if your problem is "the first ten steps are over-guided", you want a guidance schedule or a window, not this.

Retune w_min/w_max for your scale. The auto ratios come from SD 1.5/SDXL at cfg 7.5. At cfg 12 the auto pair becomes about 8 and 19 - at that point you're barely reducing guidance in the busy pixels, because 8 is still a lot. If you're up at cfg 12–14, set w_min explicitly, something like 5–6, and leave w_max on auto.

Don't invert them. The schema lets you set w_min above w_max, which flips the rule into "guide the busy pixels hardest" - the exact opposite of the paper.

Slot conflict, as always. If another pack's RescaleCFG / Mahiro / RenormCFG node is chained after this one, it owns ComfyUI's single CFG-function slot and SAMG is silently inert. Drop in CFG Plan Readout when in doubt; it prints what's actually installed on the model.

It won't save a bad prompt. If the model is hallucinating structure, more guidance in the calm regions won't fix the structure, it'll just paint it confidently.

CategoryCFG Megapack/papers/frequency and space

Inputs (5)

NameTypeDefaultDescription
modelMODEL—
scaleFLOAT-1.0-1–100The guidance scale w for this rule. -1 uses the sampler's cfg value.
w_minFLOAT-1.0-1–30Scale at high-energy pixels (-1 = w 2/3).
w_maxFLOAT-1.0-1–30Scale at calm pixels (-1 = w 1.6).
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—