Ptf Softmax
Turn raw scores into a proper probability distribution
- PTCALLABLE
Softmax is the activation that turns a vector of raw scores into a probability distribution: all positive, summing to 1, with the biggest score getting the biggest share. Ptf Softmax hands you that function as a callable component - no inputs, one PTCALLABLE output - for the pack's no-code model building. It's the standard final layer for multi-class classification, and it's what you want on the way out of a model whenever "which of k classes" is the question.
How it works
The node returns torch.nn.functional.softmax with dim pre-bound to -1 - the last axis. That binding is deliberate: for the tensor layouts this pack works with, the last dimension is normally the class/feature dimension, so softmax normalizes across the right axis without you having to think about it. (The author's own doc even points at PyTorch issue #1020 to explain what dim means.) The callable's job: exponentiates each element, then divides by the sum across that axis.
As with the other Ptf nodes, it's a function, not a tensor op. Wire the PTCALLABLE into Pt Apply Function (tensor + callable → transformed tensor) or a model closure. The sibling Ptf LogSoftmax returns the same thing in log space - numerically stabler, and the right choice when a loss like NLL expects log-probabilities.
The one output
- PTCALLABLE - softmax, last-axis-bound. No inputs.
The one decision is Softmax vs Log Softmax vs Ptf Sigmoid. Sigmoid is for binary (independent per-element probabilities); softmax is for multi-class (a normalized distribution). If the node downstream wants probabilities, use this; if it wants log-probabilities, use Ptf LogSoftmax.
Where people get burned
- dim = -1 is baked in. If your classes live on a different axis, you'll get quietly wrong probabilities. Permute or reshape before this node, not after.
- The callable trap: no tensor input here - apply it through Pt Apply Function or a closure.
- Confusing it with argmax: softmax is a smooth, differentiable version of "pick the biggest" - that's exactly why it's usable as a model layer.
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-Wrapperand 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 presence; the repo's docs/reference/ is the authoritative reference.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTCALLABLE | PTCALLABLE | — |