Nodes/ComfyUI-latent-ops/LatentOperationCosh
ComfyUI Node

LatentOperationCosh

The hyperbolic curve you'll reach for exactly once

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

    Let's be honest about Cosh: it's the node you'll add to your graph once, stare at the result, and probably never need again. Hyperbolic cosine is the smooth, even, upward-curving function - it treats positive and negative inputs identically and grows without bound, so it's not a compressor or a squasher. What it's good for is expanding a latent's dynamic range in a controlled, symmetric way, or experimenting with curves that most latent workflows never touch.

    It's part of hnmr293's ComfyUI-latent-ops activation family, and it follows the pack's standard deal: it hands you a deferred operation, not a result.

    How it works

    The node captures your alpha and builds a closure that runs torch.cosh(latent * alpha) when applied. The alpha pre-scales the latent before the curve - at the default 1.0 you get plain cosh, and raising alpha makes the curve steeper so values explode faster as they move away from zero. Cosh is even: cosh(-x) == cosh(x), and cosh(0) == 1, so everything maps to 1 and up. That's a genuinely different behavior from tanh (which squashes to -1..1) or ELU (which saturates negatives) - if your experiment specifically needs symmetric expansion, this is the one.

    What matters

    • alpha - FLOAT, default 1.0, range -10000 to 10000, step 0.0001. Pre-scale of the input.
    • op - the only output. A LATENT_OPERATION - a deferred operation.

    And the pack-wide rule: the op output won't plug into a latent input. The pack ships no Apply node, so you need a consumer that accepts LATENT_OPERATION (or a tiny custom apply node), or nothing happens. This applies to every Operation node in the pack - Cosh is not special.

    Installing it

    Same pack, same trivial install: pure torch, no requirements.txt, no model files. 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

    The two failure modes are the pack's two constants. An op output that won't connect anywhere = missing Apply step, not a broken install. And a result that looks like a whiteout = you forgot cosh grows without bound; even modest values balloon fast, so pair it with a Clamp or a NormalizeMinMax before decoding, or the dynamic range will eat your preview. If you just wanted to squash into -1..1, you grabbed the wrong curve - that's tanh or HardTanh.

    Categoryhnmr/latent_ops

    Inputs (1)

    NameTypeDefaultDescription
    alphaFLOAT1.0000-10000–10000

    Outputs (1)

    NameTypeDescription
    opLATENT_OPERATION