Nodes/ComfyUI-latent-ops/LatentOperationClampMax
ComfyUI Node

LatentOperationClampMax

Clip the ceiling on your latent

By hnmr293·Created about a year ago·Updated about a year ago· 2
LatentOperationClampMax
    • op
    max1.0000

    Sometimes only one side of your latent is out of control. A nonlinearity fires hot, a few channels spike, and you've got a handful of huge positive values dragging the whole preview into white. LatentOperationClampMax handles exactly that: it pins every value above a ceiling you choose and leaves the rest of the distribution alone. It's the one-sided version of LatentOperationClamp, and it's what you reach for when the floor is fine.

    It's from hnmr293's ComfyUI-latent-ops pack, and like every Operation node there, it emits a deferred recipe rather than touching a latent directly.

    How it works

    The node captures your max and builds a closure that runs latent.clamp(max=max) when it's finally applied. Every element above max snaps down to it; nothing else changes. Note this is one-sided clipping - values below max flow through untouched, which is the whole point. If your problem is negative runaway instead, you want the sibling that clamps the bottom.

    What matters

    • max - FLOAT, default 1.0. The ceiling. The author's tooltip: "Maximum value to clamp to."
    • op - the only output. A LATENT_OPERATION - a deferred operation, not a result.

    That op output is the pack's signature gotcha: nothing in the pack applies an op for you, so you need a consumer that accepts the LATENT_OPERATION type (or a tiny custom node that calls op(latent["samples"])). Without it, the node is inert.

    Installing it

    Same pack, same trivial install: no requirements.txt, no model files, pure torch. ComfyUI Manager → search "ComfyUI-latent-ops" → install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hnmr293/ComfyUI-latent-ops
    

    Restart ComfyUI; it's under hnmr/latent_ops.

    Troubleshooting

    If your preview is still blown out after clamping, check that the op is actually being applied - the deferred-op wiring is the usual culprit, not the value. If spikes keep returning, your max is probably above where the real action is; inspect the latent's distribution first (LatentToHist in hnmr293's other pack, or a preview chain) before guessing at a ceiling. And when you find yourself clamping both directions, just use the two-sided Clamp node and save a node.

    Categoryhnmr/latent_ops

    Inputs (1)

    NameTypeDefaultDescription
    maxFLOAT1.0000-10000–10000Maximum value to clamp to.

    Outputs (1)

    NameTypeDescription
    opLATENT_OPERATION