Nodes/ComfyUI-latent-ops/LatentOperationHardSwish
ComfyUI Node

LatentOperationHardSwish

The cheap, smooth-sounding Swish

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

    Swish (a.k.a. SiLU) is the smooth activation that quietly took over neural network design - and HardSwish is its piecewise-linear approximation, the version that ships in mobile-oriented models because it's nearly free to compute. x * hardsigmoid(x) looks like a curved activation but is built from straight segments. If you want that soft, non-monotonic character in latent space without paying for a transcendental function, this is the one.

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

    How it works

    The node captures alpha and builds a closure that runs torch.nn.functional.hardswish(latent * alpha) when applied. At the default alpha = 1.0, large negatives approach 0, small negatives dip slightly below 0, and positives grow roughly linearly before the curve bends over - a recognizable Swish shape made of line segments. The alpha input pre-scales the latent, so higher values make the whole curve respond faster around zero.

    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, one more time: the op output won't connect to a latent input. This pack ships no Apply node, so you need a consumer that accepts LATENT_OPERATION, or the op never runs. Every Operation node in this pack works the same way.

    Installing it

    No deps, 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 honest note: between HardSwish and the plain SiLU in this same pack, HardSwish saves you essentially nothing at latent scale - the "cheap" wins matter on phones, not in a graph running on your GPU. Reach for it if you like the piecewise character or want determinism across platforms; otherwise the smooth version or SiLU is fine. And remember the output is unbounded on the positive side, so clamp or normalize before preview if the range matters.

    Categoryhnmr/latent_ops

    Inputs (1)

    NameTypeDefaultDescription
    alphaFLOAT1.0000-10000–10000

    Outputs (1)

    NameTypeDescription
    opLATENT_OPERATION