Nodes/CFG Megapack/Dynamic Thresholding (Imagen; Saharia et al. 2022)
ComfyUI Node

Dynamic Thresholding (Imagen; Saharia et al. 2022)

The SD1.5 anti-burn trick, rebuilt as a node

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
Dynamic Thresholding (Imagen; Saharia et al. 2022)
  • model
  • MODEL
◄scale-1.0►
◄p0.995►
◄s_max1.0►
◄spaceauto (the method's own)►

If you used Automatic1111 in 2023, you already ran this - the Dynamic Thresholding extension by mcmonkey was the standard answer to "why is my image neon at CFG 12", and the wider community has always been a bit split on it. Reddit's recurring thread title is literally "Does Dynamic Thresholding actually work for anyone?" It does, in a narrow and specific way, and this node is the paper form: the technique Imagen's authors (Saharia et al., NeurIPS 2022) described for keeping sampled pixel values inside range at high guidance scales.

The mechanism, honestly

Dynamic thresholding doesn't touch the guidance direction at all. It leaves CFG alone, looks at the denoised image it produced, and clips. For each image, take the absolute values, find the p-th percentile, never let that value fall below s_max, and divide every pixel by it. Anything beyond the threshold is squashed toward the middle; nothing below it moves.

That's why its fans and its critics are both right. It reliably kills the blown-out, over-contrasty look at high CFG. It also does nothing whatsoever about the other high-CFG failure modes - the composition weirdness, the fried details, the wrong number of limbs - and if your threshold bites in a region that should have held detail, you get a flat, plasticky image instead. It is a clamp, not a fix.

Note the phrase "on the denoised image": this is an x0 rule. That's why the space input exists and why it matters here more than for a linear rescale.

Inputs

  • model - from your loader, before the sampler.
  • scale (default -1) - -1 uses the KSampler's cfg. Set it if you want the model chain to override the sampler.
  • p (default 0.995) - the percentile that sets each image's clip value. Lower p = more aggressive clipping. On SD1.5/SDXL the useful band is roughly 0.99–0.999; below 0.99 you're mashing everything together.
  • s_max (default 1) - a floor under the clip value, so the threshold can never collapse to zero and divide your latent into noise. 1 reproduces the static clip; raise it to loosen the whole thing.
  • space - auto (the method's own) computes it on the denoised prediction, which is the paper's space. Changing the space here genuinely changes the image.

Output is a MODEL. Into KSampler's model input, done.

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

Nothing extra to download - no requirements.txt, no model files, just torch and the standard library. Requires ComfyUI ≥ 0.38. You can sanity-check the pack's examples from Workflow > Browse Templates > Custom Nodes > comfy-cfg-megapack.

When to reach for it - and when not to

Reach for it when you want high CFG for prompt adherence and only the color/saturation is the problem. It plays fine with SD1.5 and SDXL finetunes, where raising CFG is the normal move.

Don't reach for it on a guidance-distilled 2026 model at CFG 1. There is no over-saturation to clamp, the rule has nothing to do, and the pack's hook has switched off the CFG-1 shortcut that made those models fast. If your Z-Image Turbo render looks burnt, the fix is lowering CFG, not thresholding harder - CFG 3 on a distilled model does what CFG 12 does on SDXL.

Two other things to keep in mind: the CFG-function slot is shared with other packs (RescaleCFG, Mahiro, RenormCFG), and in ComfyUI the last node chained wins, so verify this one is actually the one in charge. And if you're chasing the exact mcmonkey behavior from the A1111 days rather than the Imagen paper, the same pack ships Mimic-Scale Thresholding and the CFG Correct: Magnitude node with a percentile_rescale method - those are separate nodes, not options on this one.

CategoryCFG Megapack/papers/combining the two predictions

Inputs (5)

NameTypeDefaultDescription
modelMODEL—
scaleFLOAT-1.0-1–100The guidance scale w for this rule. -1 uses the sampler's cfg value.
pFLOAT0.9950.5–1The percentile that sets each image's clip value.
s_maxFLOAT1.01–20The clip value never goes below this (1 = the static clip).
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—