Nodes/ComfyUI Model Bending/Latent Operation (Threshold)
ComfyUI Node

Latent Operation (Threshold)

The threshold op for model bending

By abuzreq·Created about a year ago·Updated 3 months ago· 21
Latent Operation (Threshold)
    • LATENT_OPERATION
    threshold0.00

    This is the "keep only the strong stuff" node. Latent Operation (Threshold) returns a LATENT_OPERATION that walks every value in a latent and zeroes out anything whose absolute value falls below your threshold. Weak signal dies, strong signal survives, and the effect of a threshold operation can be anything from a subtle cleanup to completely reorganizing whatever the denoiser produces next.

    It lives in abuzreq/ComfyUI-Model-Bending, the pack that does "model bending" - intercepting a diffusion model's activations at a chosen layer during sampling and poking them. Threshold is one of the simplest pokes, which makes it a good first node to reach for while you're learning the pack's wiring. It's also the sibling of the Threshold Module (Bending) node, which does the same math but emits a BENDING_MODULE instead of a LATENT_OPERATION. Different output type, same idea.

    How it works

    A latent operation is just a function that takes a latent tensor and returns one of the same shape. This one applies the hard threshold from the pack's bendutils:

    y if abs(y) >= threshold else 0
    

    So at threshold = 0 it's a no-op - every value has an absolute value ≥ 0 - and as you raise the threshold you progressively kill the quietest channels. Because latents in SD-family models are dense and low-magnitude, you generally need values well above 0 to see anything happen. The operation is applied to whatever consumes the LATENT_OPERATION output.

    The inputs that matter

    There's exactly one input, which makes this node refreshingly hard to mess up:

    • threshold (FLOAT, default 0) - the cutoff. Raise it to delete more.

    The single output, LATENT_OPERATION, wires into one of three places:

    • LatentApplyOperationCFGToStep - apply the op to the latent at exactly one denoising step.
    • ConditioningApplyOperation - apply it to CLIP-encoded conditioning instead of a latent.
    • Latent Operation To Module - convert it into a BENDING_MODULE so you can bend the UNet or a VAE with it.

    Installing

    The whole pack installs at once - you don't install this node by itself.

    cd ComfyUI/custom_nodes
    git clone https://github.com/abuzreq/ComfyUI-Model-Bending
    

    Then restart ComfyUI and refresh your browser. You can skip the clone and use ComfyUI Manager instead: search for ComfyUI-Model-Bending under Custom Nodes. The pack's requirements.txt is just kornia and scikit-learn, both auto-installed by Manager, and there are no model files to download. One quirk: the README's manual-clone snippet tells you to name the folder ComfyUI-Web-Bend-Demo - that's stale copy-paste from the web-demo era. Keep the folder name ComfyUI-Model-Bending to match the repo.

    Common gotchas

    Start small. A threshold that sounds reasonable on paper can gut the latent entirely and give you a gray smear - that's expected, it's the nature of this pack, and it's how you learn which layer responds to what. Because the operation mutates values in place during sampling, effects compound across steps; if you only want a one-step jolt, gate it with LatentApplyOperationCFGToStep rather than bending every step. And remember the threshold of 0 default: if you plug this in and nothing changes, that's not a bug, you just haven't raised the knob yet.

    This is an experimental, tinkerer's tool - there's no "correct" setting, and the pack's own catalog of results treats these knobs as a space to explore, not a recipe to copy. Crank it, preview, and back off.

    Categorymodel_bending

    Inputs (1)

    NameTypeDefaultDescription
    thresholdFLOAT0.00

    Outputs (1)

    NameTypeDescription
    LATENT_OPERATIONLATENT_OPERATION