ComfyUI Node

Ptf GELU

The transformer's favorite activation, served as a function

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

    If you're building a Transformer in ComfyUI-Pt-Wrapper, GELU is the activation you'll wire into the feed-forward blocks - and this node is how you get it. But here's the thing that trips everyone up on first contact: Ptf GELU doesn't take a tensor. It has no inputs at all. It emits a PTCALLABLE, which is the pack's fancy word for "a Python function you can plug into other nodes."

    ComfyUI-Pt-Wrapper is Hide Inada's (HowToSD.com) no-code PyTorch toolkit for the node graph - a spin-off of his ComfyUI-Data-Analysis with around 200 nodes for tensor math, model construction, and training. The pack's own April 2025 update added a walkthrough for building a Transformer encoder from scratch for IMDB classification. GELU (Gaussian Error Linear Unit) is the activation those transformer feed-forward layers use - it's what GPT, BERT, and most modern attention architectures pick over plain ReLU because it's smooth and lets a little gradient through around zero.

    What it actually does

    The Ptf prefix means "function." The node returns torch.nn.functional.gelu as a callable object - zero configuration, no knob to turn. The README's framing is that you're building models out of components, and an activation function is a component you slot in, not data you process.

    So where does the callable go? Three sockets in this pack eat PTCALLABLE:

    • Pt Apply Function - takes tens and closure, and applies the function to the tensor, outputting a TENSOR. This is your "apply GELU to this data" path.
    • Ptn Model With Closure - wraps an existing model so the callable runs after its forward pass, outputting a PTMODEL.
    • Ptn Chained Model - chains two models and optionally runs the closure at the end.

    Inputs and outputs

    From info_schema: no required inputs, no optional inputs. Output is a single PTCALLABLE. That's the whole node.

    Installing it

    It's a Data Analysis category node from ComfyUI-Pt-Wrapper. Install once via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
    # then restart ComfyUI
    

    For GELU itself you need nothing beyond torch, which ComfyUI already bundles. The pack's requirements.txt pulls heavier dependencies (transformers, datasets, gensim, peft, accelerate) for the training and tokenizer side - you'll notice a slower first import after install, but not from this node.

    Where people get burned

    The number one confusion is trying to connect a TENSOR output into the PTCALLABLE socket - the colors won't even match, and that's the point. This node is a function factory, not a processor. If you just want GELU applied to one tensor right now, pair it with Pt Apply Function; if you want it baked into a model you're assembling, it's the closure slot.

    One more thing worth knowing: there's no GELU variant selector here - no "tanh approximation" toggle, no approximate parameter. You get whatever torch.nn.functional.gelu defaults to, which for modern torch is the exact version. If your architecture needs the approximation for exact-weight matching, this node won't do it. Fine for building and training from scratch, which is what this pack is actually for.

    CategoryData Analysis

    Inputs (0)

    No inputs

    Outputs (1)

    NameTypeDescription
    PTCALLABLEPTCALLABLE