Nodes/ComfyUI-latent-ops/LatentOperationSoftmin
ComfyUI Node

LatentOperationSoftmin

Softmin is the softmax that cheers for the smallest value

By hnmr293·Created about a year ago·Updated about a year ago· 2
LatentOperationSoftmin
    • op
    axis-1

    Most of the activation nodes in this pack are pointwise - they look at one value and change that one value. Softmin isn't that. It's a softmax-family operation, which means it looks along an axis, reads a whole row of values, and turns them into a distribution that shines a spotlight on the smallest one. If that sounds like it will wreck a latent, you're not wrong - which is exactly why it's worth knowing before you use it.

    It's one of ~30 nodes in hnmr293/ComfyUI-latent-ops, the latent-math toolbox from the dev behind sd-webui-cutoff and the LLuL latent upscaler. Same pack as the tanh, softplus and softsign nodes; same category, same install, same one-line implementations.

    What it computes

    The source is softmin(latent, dim=axis). If you've used softmax, you already know softmin: it's softmax applied to the negatives - softmax(-x, dim=axis). The consequences are the important part:

    • Values become positive and sum to roughly 1 along the chosen axis. It's a probability distribution, not a rescaled version of your latent.
    • The smallest values along that axis get the largest weights. The minimum takes the crown; everything else is pushed toward zero exponentially fast.
    • It is not elementwise. The default axis = -1 (the last dimension) means for a typical latent shaped [batch, channels, height, width], every row of width values gets turned into its own little distribution.

    So if you're imagining "softmin = a gentle minimum," un-imagine it. This is a normalizing operation that destroys the original scale and structure of the tensor. Applied naively to a latent before decode, you'd get a strip of near-zero values with a single peak per row - structurally fascinating, pictorially nonsense.

    Input, output, and the catch

    One input: axis (INT, default -1, range -10000 to 10000) - which dimension to normalize across. Output is named op, typed LATENT_OPERATION.

    And the catch applies here harder than anywhere: op is a callable, not a latent. The node builds the softmin function and hands you a handle to it, and as of the last commit the pack ships no node that consumes a LATENT_OPERATION. On a stock install you can't plug that output into anything - no KSampler, no VAEDecode, no socket at all. Every function node in this pack has this shape, but softmin is the one where the missing apply node stings most, because the operation is subtle enough that you really want to preview it.

    Who is this actually for? People porting math into ComfyUI. Softmin shows up in attention maps, in some weighting schemes, and in any formula that needs "emphasize the minimum" as a differentiable step. If you're not porting a paper formula, honestly: this is the node in the pack I'd skip. Core ComfyUI already has softmax-family options, and for "shrink the small stuff," a ClampMin or a simple multiply gets you further with fewer surprises.

    Install

    Same as the rest of the pack - ComfyUI Manager (search "ComfyUI-latent-ops") or:

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

    then restart ComfyUI. No requirements.txt, no model downloads, pure PyTorch. Nodes land under hnmr/latent_ops.

    Common issues

    • "Everything turned to near-zero except one spike." That's softmin doing exactly what it says - a distribution along the axis, minimum on top. Not a bug; rethink whether this is the operation you wanted.
    • "My output won't connect." LATENT_OPERATION callable with no consumer in the pack, as shipped. Expected.
    • Wrong axis, wrong result. axis = -1 operates along the last dimension; with latent layout [B,C,H,W] that's across width. Set axis = 1 for channels if that's the direction you meant.
    Categoryhnmr/latent_ops

    Inputs (1)

    NameTypeDefaultDescription
    axisINT-1-10000–10000

    Outputs (1)

    NameTypeDescription
    opLATENT_OPERATION