LatentOperationHardSigmoid
Sigmoid's fast, piecewise cousin
- op
If sigmoid is the smooth "squash everything into 0-1" curve, HardSigmoid is the same idea built from straight lines. It's piecewise: flat at 0 below a threshold, flat at 1 above it, and a linear ramp in between. Faster to compute, dead simple to reason about, and - because it's bounded between 0 and 1 - it's a natural fit when you want to push latent values into the range that a 0-1 preview expects.
It's one of the activation nodes in hnmr293's ComfyUI-latent-ops pack, and like the rest of the Operation family it builds a deferred recipe rather than touching a latent directly.
How it works
The node captures alpha and builds a closure that runs torch.nn.functional.hardsigmoid(latent * alpha) when applied. The alpha pre-scales the latent: at the default 1.0, values below about -3 saturate to 0, values above about 3 saturate to 1, and everything in between follows a linear ramp through 0.5 at zero. Raise alpha and the ramp steepens - more values get pushed toward the extremes. The result is a bounded 0-1 output, which makes it a natural partner for Latent01ToImage if you want to preview without extra normalization.
What matters
alpha- FLOAT, default 1.0, range -10000 to 10000, step 0.0001. Pre-scale of the input.op- the only output. ALATENT_OPERATION- a deferred operation.
And the pack-wide rule: the op output isn't a latent and won't connect to one. This pack ships no Apply node, so you need a consumer that accepts LATENT_OPERATION - otherwise nothing happens. It's the same story for every Operation node in the pack.
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 flat regions are the gotcha: because hard sigmoid saturates, values outside the ramp range get pinned to exactly 0 or exactly 1, which erases gradient detail. If your latent's distribution is mostly out in the saturated zones, you'll lose more than you keep - consider a softer curve (GELU or tanh) or normalize first so more of the data lands on the linear ramp. And if you need the mirror-image curve for zero-centered data, pair it with the 0.5 shift or reach for tanh.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| alpha | FLOAT | 1.0000-10000–10000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| op | LATENT_OPERATION | — |