Nodes/ComfyUI-latent-ops/LatentOperationReLU
ComfyUI Node

LatentOperationReLU

The nuclear option for latents, and why you should think twice

By hnmr293·Created about a year ago·Updated about a year ago· 2
LatentOperationReLU
    • op
    alpha1.0000

    ReLU is the most famous activation function in machine learning and, applied to a latent, one of the most destructive things you can do. It sets every negative value to zero. Latents are roughly zero-mean distributions - for SD/SDXL they sit in a band around ±3 - which means ReLU doesn't trim a few stray negatives, it zeros out roughly half of the tensor. This node does exactly that, and you should have a specific reason before you click it.

    The mechanism

    def relu(latent, **kwargs):
        return torch.nn.functional.relu(latent * alpha)
    

    One input: alpha (FLOAT, default 1.0). As with every activation node in hnmr293/ComfyUI-latent-ops, alpha is an input gain - the latent is multiplied by it before ReLU runs. alpha = 1 is pass-through-gain; higher alpha amplifies the latent first, which pushes more of the distribution above zero before the rectification. That's the one lever you get. No negative slope, no leak, no threshold.

    What this does to a latent is a hard edit: the negative lobe of the distribution collapses to exactly zero, and all the information encoded in "how negative" a value was is gone. Downstream, the sampler sees a distribution that's been shoved half-positive - expect weird, washed, or outright broken decodes unless that's the experiment. The honest framing: ReLU-on-a-latent is a research/curiosity tool, not a fix for a bad render. If your goal is "nonlinear shape without destroying the negatives," the pack's LatentOperationLeakyReLU (keeps a scaled negative lobe) or LatentOperationMish/LatentOperationSiLU (smooth floors) are far less violent options. ReLU is for when you specifically want a hard rectification.

    The op output and the apply trap

    The output is op, type LATENT_OPERATION - a deferred closure, not a result. This whole pack builds operation descriptions and ships no apply node, so you need a consumer of LATENT_OPERATION (Sonar's SonarApplyLatentOperationCFG is the known one) or your own apply node. Wire op directly into a VAE Decode and you'll get a type mismatch - the universal first-bounce with this pack, and it's by design. Nothing applies itself here.

    Install

    Boring, quick, zero risk. ComfyUI Manager → search ComfyUI-latent-ops, or:

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

    Restart ComfyUI. There's no requirements.txt and nothing downloads - pure PyTorch and torch.nn.functional, both already in your ComfyUI. This is the workbench of hnmr293 (the sd-webui-cutoff and llul author), a pack with essentially no community footprint, so expect to read source rather than tutorials. Everything registers under hnmr/latent_ops. And when you're tempted by an activation node in this pack, remember the source is four small files - the code tells you exactly what you're signing up for.

    Categoryhnmr/latent_ops

    Inputs (1)

    NameTypeDefaultDescription
    alphaFLOAT1.0000-10000–10000

    Outputs (1)

    NameTypeDescription
    opLATENT_OPERATION