ComfyUI Node

Ptf Tanh

The centered activation that squeezes into -1 to 1

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptf Tanh
    • PTCALLABLE

    Tanh is the classic squashing activation: it takes any real number and compresses it into (-1, 1), centered on zero. Ptf Tanh hands you that function as a callable component - no inputs, one PTCALLABLE output - for the pack's no-code model building. It's the older-generation sibling of Ptf Sigmoid, and it's what you want when you need bounded output that can go negative as well as positive.

    How it works

    The node returns torch.nn.functional.tanh. As a callable it plugs into Pt Apply Function (tensor + callable → transformed tensor) or any model closure socket, applying element-wise. The shape: tanh(0) = 0, large positives approach 1, large negatives approach -1. Compared to sigmoid, tanh is zero-centered - its outputs straddle zero instead of sitting in (0,1) - which historically made it a better hidden-layer activation, since the centered outputs let gradients flow in both directions rather than always pushing positive. In practice, modern stacks mostly moved on to ReLU and SiLU, but tanh still earns its keep for bounded intermediate representations and any output that must live in (-1, 1) - think normalized features, control signals, or encodings.

    The one output

    • PTCALLABLE - the tanh function. No inputs.

    The choice among the squash family: need (0,1) and probability-flavored? Ptf Sigmoid. Need (-1,1), possibly for a learned bounded representation? Tanh. Need a whole normalized distribution over classes? Ptf Softmax.

    Where people get burned

    • The callable trap: no tensor input here - apply it through Pt Apply Function or a closure.
    • Saturation: for large magnitudes the output pins at ±1 and the gradient vanishes. If your tanh-fed layer keeps saturating, scale your inputs down.
    • It's a function, not an nn.Module - when a layer node wants a module, use the pack's layer nodes instead.

    Installing it

    Part of ComfyUI-Pt-Wrapper:

    • ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → Install → restart.
    • Or cd ComfyUI/custom_nodes && git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper and restart.

    Heavy install - requirements include transformers, datasets, peft, accelerate, scikit-learn, scipy, gensim and sentencepiece. No model downloads needed. It's a niche educational pack by HowToSD with little community chatter; the repo's docs/reference/ is the authoritative doc, and the README invites issues but closes unsolicited PRs.

    CategoryData Analysis

    Inputs (0)

    No inputs

    Outputs (1)

    NameTypeDescription
    PTCALLABLEPTCALLABLE