ComfyUI Node

Subtract noise mean

Subtract its mean before you sample

By Extraltodeus·Created 2 years ago·Updated about a year ago· 66
Subtract noise mean
  • latent_input
  • LATENT
enabledtrue

Random noise is supposed to be centered around zero. Sometimes it isn't - a freshly generated latent can carry a small bias, and that bias is one of the quiet culprits behind color casts and flat, milky images. "Subtract noise mean" is the preemptive version of the fix: it removes the mean from your latent before the sampler ever runs, so the drift never gets a chance to color the output.

This is the sibling to the pack's "Pre CFG subtract mean" node, and the split is worth getting straight because they live in different places in your workflow. Pre-CFG subtract mean works on the model's noise predictions, every step, as a model patch. This node works on a latent - the initial noise you're handing to the KSampler - and does it once, up front. The most natural spot is between your Empty Latent (or image-to-image encode) and the KSampler's latent input. If you're encoding a real image and the encode comes out with a visible tint, subtract the mean before sampling and the cast often walks away.

The mechanism is trivial: it iterates the latent's samples and does sample -= torch.mean(sample) for each one, recentering it at zero. No model involved, no sampler hook - it's a plain latent transform. It's also the cheapest node in this pack: one mean subtraction, done once, zero impact on sampling speed.

Inputs and output are both as minimal as it gets:

  • latent_input - the LATENT to clean. Note it's marked forceInput in the source, meaning you must wire it in; ComfyUI won't show it as a widget you can type into.
  • enabled - on/off, default on, so you can A/B instantly.
  • Output: LATENT, feeding your KSampler's latent input.

Where it fits: for img2img and inpainting workflows that encode a source image, a mean-offset latent is a real, reproducible phenomenon, and this is a surgical fix. For pure text-to-image you're subtracting a near-zero mean from already-good noise and likely changing nothing - don't expect a revolution there.

The usual pack caveats apply in reverse here: this one doesn't need a negative prediction or a CFG hook, so it works fine even on CFG-1 and guidance-distilled workflows (it's just a tensor op). The author's testing emphasis is SDXL, but a mean subtraction is architecture-agnostic, so it transfers. It's in the latent category for a reason - it's a utility, not a pre-CFG experiment.

Installation, same as the whole pack:

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

or ComfyUI Manager → search pre_cfg_comfy_nodes_for_ComfyUI → restart. No dependencies, no model downloads. Add it between your encode and sampler on an img2img workflow, flip enabled off and on, and you'll know within one render whether it's doing anything for you.

Categorylatent

Inputs (2)

NameTypeDefaultDescription
latent_inputLATENT
enabledBOOLEANtrue

Outputs (1)

NameTypeDescription
LATENTLATENT