Nodes/pre_cfg_comfy_nodes_for_ComfyUI/Post CFG subtract mean
ComfyUI Node

Post CFG subtract mean

Washed-out colors? Subtract the mean and rebalance the palette

By Extraltodeus·Created 2 years ago·Updated about a year ago· 66
Post CFG subtract mean
  • model
  • MODEL
start_at_sigma15.00
end_at_sigma1.00
enabledtrue

Color is where CFG misbehaves most. The whole classifier-free guidance formula - uncond + (cond - uncond) * scale - amplifies whatever difference the two predictions have, and that difference is rarely color-neutral. The result is the drift you've definitely seen: images that come out tinted, muddy, or slightly gray even when the prompt asked for vibrant color. Post CFG subtract mean is the pack's fix - after the CFG combination, it subtracts the prediction's own mean, re-centering the values so the color balance stops drifting.

That's the whole mechanism, and it's a good one. The node hooks ComfyUI's post-CFG function (the pack is mostly pre-CFG, hence the name difference), running after the guidance math has combined the two predictions. At that point it computes the mean of the denoised result and subtracts it from itself, per batch item - a zero-sum recentering that doesn't add or remove overall energy but does kill a persistent DC offset, which is exactly the kind of thing that reads as a color cast. It's the same idea as the author's Pre CFG subtract mean node, just applied after instead of before, and the README's one-line description is accurate: "subtract prediction mean: gives more balanced colors."

The inputs are the standard trio you'll see across this pack: start_at_sigma (default 15) and end_at_sigma (default 1) gate when the node is active - and note it stops at sigma 1 rather than 0, so the very final cleanup steps are left alone, which the author found preserves fine detail - plus enabled (default on) for instant A/B. Below sigma 15, the mean-subtraction only touches the later, refinement phase of sampling; the coarse structure in the noisy early steps is left untouched.

When is this actually the answer? If your images come out consistently gray or with a color cast that survives VAE changes and CFG adjustments, this is a cheap fix to try before you blame the checkpoint. It's also a natural companion in a chained pre-CFG setup - stack it after a node that's been aggressively scaling predictions (which tends to shove the mean around) to rebalance what the scaling disturbed.

Like everything in this pack, it's a model patch - model in, patched model out - and it's in the model_patches category. Install is the pack standard:

cd ComfyUI/custom_nodes
git clone https://github.com/Extraltodeus/pre_cfg_comfy_nodes_for_ComfyUI

or search pre_cfg_comfy_nodes_for_ComfyUI in ComfyUI Manager and restart. No models, no extra dependencies.

Is it always a win? No - subtracting the mean is a global move, and some images want their off-center palette. But as a first-line color-balance tool on a fixed seed, it's fast, safe, and the README-endorsed answer to washed-out output.

Categorymodel_patches

Inputs (4)

NameTypeDefaultDescription
modelMODEL
start_at_sigmaFLOAT15.000–1000
end_at_sigmaFLOAT1.000–1000
enabledBOOLEANtrue

Outputs (1)

NameTypeDescription
MODELMODEL