LatentOperationTanh
Tanh your latent before it does something dramatic
- op
Tanh is the "calm down, everything" curve. Squash any number through it and it lands between -1 and 1, smoothly, without the hard edges of a clamp. In a diffusion pipeline you mostly meet it as the final squeeze on a classifier's logits, but this node lets you aim it straight at your latent tensor - the compressed LATENT your sampler is denoising - and reshape it however you like. It's the sort of thing you reach for when you're deliberately messing with the latent between passes instead of treating it as an opaque blob.
It comes from hnmr293/ComfyUI-latent-ops, a small toolbox of math ops for latents by hnmr293 - the Japanese dev behind sd-webui-cutoff (the famous "stop this one token bleeding into the rest of the prompt" extension) and LLuL, a local latent upscaler. The man has been living in latent space since the WebUI era; this pack is his ComfyUI take on the same hobby.
What it actually computes
The math is one line, straight from the source: tanh(latent * alpha). Feed it a latent, and every value gets scaled by alpha, then pushed through the tanh S-curve. A few landmarks so you know what you're buying:
alpha = 1(the default): plain tanh. Values near zero pass through almost unchanged; the further a value sits from zero, the harder it gets pulled toward ±1.alpha > 1: steepens the curve, so more of the tensor gets slammed into the saturated ends. Closer to a hard clip, but still smooth.alpha < 1: flattens it toward a straight line - a mild fade rather than a squeeze.
In practice that means: outliers and hot spots get compressed, the bulk of the latent keeps its shape, and everything stays bounded. If you've ever decoded a latent full of wild values and gotten scorched noise, a tanh pass before VAEDecode is one way to tame it.
The input, the output, and the trap
The single input you set is alpha (FLOAT, default 1.0, range -10000 to 10000). That's it - this node has no other knobs.
The output is where beginners get burned. It's named op and it's type LATENT_OPERATION - not a latent. This node doesn't return a modified tensor; it returns a callable that would apply tanh if something else invoked it. As of the last commit the pack ships no node that consumes a LATENT_OPERATION, so on a stock install you can't wire op into a KSampler or a VAEDecode - the socket simply doesn't exist yet. Think of these as building blocks for a "latent ops apply" node that hasn't landed, or for another pack that declares the same custom type.
That's a real limitation, so don't come looking for a drop-in "tanh my latent" effect. If that's all you want, you can do it today with a plain LatentMath-style multiply and a Clamp, or a custom node that acts directly on LATENT. This node is for when you want the exact function, as a reusable handle, in a graph someone else's apply node can consume.
Install
Nothing special about this one - it's part of the whole pack:
- ComfyUI Manager: search "ComfyUI-latent-ops" and hit install, or
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/hnmr293/ComfyUI-latent-ops, then restart ComfyUI.
No requirements.txt, no model downloads, no extra runtime. It's pure PyTorch (plus torch.nn.functional), which your ComfyUI already ships. All nodes land under hnmr/latent_ops in the node search.
Common issues
- "Why can't I connect
opto anything?" Covered above - the output is aLATENT_OPERATIONcallable, not aLATENT. Not a bug, just a library that's ahead of its consumer. - Expecting a squeeze and getting identity: at
alphanear 0,tanh(alpha*x)is basicallyxtimes a small constant. Crank the alpha before you conclude it's broken. - Quiet repo: the pack was built in a burst in April 2025 and hasn't moved much since. Don't hold your breath for an apply node; check the repo's commits before building a workflow that depends on one.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| alpha | FLOAT | 1.0000-10000–10000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| op | LATENT_OPERATION | — |