Pt Tanh
Tanh as a node — the activation you've been using without knowing it
- tens_a
- TENSOR
Pt Tanh applies the hyperbolic tangent - the S-curve that squashes any number into the range (-1, 1) - to every element of a tensor. One input, one output, and one of the most useful one-liners in all of deep learning. If you've trained an image model, you've already met tanh whether you realized it or not: it's the classic squashing function baked into everything from classic RNNs to the final activation of diffusion models. This node lets you drop that same nonlinearity anywhere in a ComfyUI tensor pipeline.
It's part of ComfyUI-Pt-Wrapper, a ~200-node pack that puts PyTorch's tensor math and model training into the node graph - no Python required. Pt Tanh is one of the Pt-prefixed math/activation operators (alongside PtReLU, PtSigmoid, PtSoftmax, PtTan…) you use to shape tensors between the big pipeline steps.
How it works
The mechanism is one line of PyTorch: torch.tanh(tens_a), applied element-wise. Every value maps smoothly to (-1, 1): large positive numbers hug +1, large negative numbers hug -1, zero stays zero. That bounded output is exactly why tanh shows up as an activation - it keeps values from running away, which is the opposite of what plain PtTan does near its asymptotes.
Inputs and outputs
The interface is minimal:
tens_a(TENSOR) - the input tensor.TENSORoutput - the element-wise tanh, same shape and dtype.
Wire the output into another math node, into a PtShowText/PtShowSize debug node to see what it did, or use it as the activation inside a model you're assembling from layer nodes.
Where it fits
Two honest uses. First: feature scaling - if a tensor has wild, unbounded values and you want to tame them before they hit a model, tanh is a quick normalizer that preserves sign. Second: building custom models in the graph, where you often want a bounded nonlinearity in a layer chain. It's also just a great teaching node - feed it values, look at the output, and you'll feel what an activation does.
Installing the pack
Install the pack once and all 200 nodes come with it:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Then restart ComfyUI. Or open ComfyUI Manager, search "ComfyUI-Pt-Wrapper", and install - it's on the Comfy Registry so Manager pulls the dependencies (pandas, scikit-learn, transformers, sentencepiece and friends) for you. For a single activation node that's a heavy install, but you get the whole PyTorch-in-ComfyUI toolkit in exchange.
Common issues
- Vanishing gradients in deep chains. Tanh's curve is flat at the extremes, so stacked tanh layers can stop learning in very deep networks - a real, well-documented failure mode, not a bug. For deep stacks, ReLU (
PtReLU) is usually the better default and you'll see it used more in the pack's own example models. - Everything hugging ±1. If your outputs all sit at the extremes, the input scale is probably too large - the signal is being saturated. Scale the input down first.
Niche, yes. But if you're building custom models or taming tensors in the graph, this is the squashing function you want, and now it's a node.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| tens_a | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |