Nodes/ComfyUI-sonar/SonarLatentOperationQuantileFilter
ComfyUI Node

SonarLatentOperationQuantileFilter

Clip the wild outliers in your latent, during sampling

By blepping·Created 3 years ago·Updated 15 days ago· 49
SonarLatentOperationQuantileFilter
    • LATENT_OPERATION
    quantile0.850
    dim1
    flattentrue
    norm_factor1.000
    norm_power0.500
    strategyclamp

    SonarLatentOperationQuantileFilter applies quantile normalization to a latent mid-sampling, clipping the extreme outlier values that can blow out a generation. If your images sometimes come out with harsh, blown-out highlights or crunchy artifacts that look like a few values ran away with the whole latent, this is the targeted fix: it doesn't average, it clips to the distribution.

    What quantile normalization means

    Normal "normalize to 1.0" squashes everything proportionally, so one wild outlier drags the whole distribution down. Quantile normalization works differently: it finds the value at a given quantile (say the 85th percentile) and treats everything beyond it as an outlier, clipping or reshaping it. Result: the bulk of your latent keeps its relative character, and the insane tail gets tamed. The tooltip example is precise - a quantile of 0.75 means outliers above the 75th percentile get handled.

    The inputs that matter

    • quantile - default 0.85. 1.0 or 0.0 disables the normalization entirely. Values like 0.75–0.85 are the sensible range; the right number depends on how extreme your inputs are. The experimental twist: a negative quantile treats values closest to zero as the "extreme" ones instead.
    • strategy - how outliers are handled, and this is a deep one: 43 choices. The accessible headliners are clamp (pin to the boundary), scale_down, tanh, and the various sin/sigmoid shapes. zero returns zero outside the quantile range and reverse_zero keeps only the outliers - the tooltip notes those two only make sense if you're adding the result to other noise. Most of the 43 are experiments; start with clamp or tanh.
    • dim - which dimensions to normalize over: global or an explicit dim. Image latents are batch/channel/row/column; video latents add a frame dim (so 2 is the frame axis on 5D latents, but the row on 4D ones - mind the shape you're actually feeding).
    • flatten - default true, flattens before normalizing. Try disabling if you want per-row/column influence, though the tooltip warns that produces strong row/column bias.
    • norm_factor and norm_power - the multiplier just before clipping (leave at 1) and the exponent applied after (0.5 default; below -0.3 gets strange).

    Output is a LATENT_OPERATION, meant for a consumer like the pack's SonarApplyLatentOperationCFG - the node description notes this one is the operation-based sibling of the pack's standalone quantile-normalization noise node, and it applies to whatever you attach it to (denoised, uncond, and so on).

    Where you'd use it

    Anything where outliers are the failure mode: high-CFG generations that blow out, latent edits that spike values, or after aggressive negative-space operations. Because it runs mid-sampling via an operation consumer, you can also schedule it to only tame the early or late steps.

    Install

    ComfyUI Manager → search "ComfyUI-sonar" → Install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/blepping/ComfyUI-sonar
    

    No models, no extra deps. The author's disclaimer that a lot of this pack is "janky" and best-effort is especially true for the 43 strategy variants - treat the exotic ones as experiments, not gospel.

    Categorylatent/advanced/operations

    Inputs (6)

    NameTypeDefaultDescription
    quantileFLOAT0.850-1–1When enabled, will normalize generated noise to this quantile (i.e. 0.75 means outliers >75% will be clipped). Set to 1.0 or 0.0 to disable quantile normalization. A value like 0.75 or 0.85 should be reasonable, it really depends on the input and how many of the values are extreme. (Experimental) You can also use a negative quantile to consider values closest to 0 to be 'extreme'.
    dimCOMBO1Controls what dimensions quantile normalization uses. Dimensions start from 0. Image latents have dimensions: batch, channel, row, column. Video latents have dimensions: batch, channel, frame, row, column.
    flattenBOOLEANtrueControls whether the noise is flattened before quantile normalization. You can try disabling it but they may have a very strong row/column influence.
    norm_factorFLOAT1.0000.00001–10000Multiplier on the input noise just before it is clipped to the quantile min/max. Generally should be left at the default.
    norm_powerFLOAT0.500-10000–10000The absolute value of the noise is raised to this power after it is clipped to the quantile min/max. You can use negative values here, but anything below -0.3 will probably produce pretty strange effects. Generally should be left at the default.
    strategyCOMBOclampDetermines how to treat outliers. zero and reverse_zero modes are only useful if you're going to do something like add the result to some other noise. zero will return zero for anything outside the quantile range, reverse_zero only _keeps_ the outliers and zeros everything else.

    Outputs (1)

    NameTypeDescription
    LATENT_OPERATIONLATENT_OPERATIONA custom noise chain.