Ptf Log Softmax
Softmax in log space, ready to plug in
- PTCALLABLE
Ptf Log Softmax is one of the pack's "callable" nodes: instead of operating on a tensor directly, it hands you a function - here, the log-softmax activation from PyTorch - that you then wire into something that applies it. No inputs, one output. It exists because in the no-code model-building workflow, activations are components you assemble, not things you apply by hand. And log-softmax is the version you want when you're about to feed probabilities into a loss: it's numerically stable where taking log(softmax(x)) naively would blow up.
How it works
The node returns torch.nn.functional.log_softmax with dim pre-bound to -1 - the last axis. That last detail is the whole story: softmax normalizes across a dimension, and choosing the last axis is the standard assumption for "the feature/class dimension" in the tensor layouts this pack works with. So the callable turns an input tensor of raw scores into log-probabilities that sum (in log space) to a sensible distribution, all along the final dimension.
You don't call it yourself. The output type is PTCALLABLE, and the natural consumer is Pt Apply Function, which takes a tensor plus a callable and applies it. It also slots into model nodes and closures that accept callables - for instance building a chained model whose final layer is a log-softmax before the loss node. Pair it with Ptdm LogProb-style scoring or a Pt NLL Loss node and you've reconstructed the classic classification setup: log-softmax out, negative log-likelihood loss.
The one output
- PTCALLABLE - the log-softmax function, last-axis-bound.
That's it - there are no inputs at all, so the only real decision is whether you want Ptf Softmax (probabilities out) or this (log-probabilities out). Rule of thumb: if a loss or downstream node wants probabilities, use Softmax; if it wants log-probabilities, use Log Softmax. Using the wrong one is the most common mistake, and the symptom is usually NaN or baffling loss values.
Where people get burned
- dim = -1 is baked in. If your tensor's class dimension isn't last, you'll silently get wrong results. Reshape/permute before this point, don't fight it after.
- Forgetting it's a callable, not a tensor op - wire it into Pt Apply Function or a model closure, or nothing happens.
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.
Expect a slow first install - requirements pull in transformers, datasets, peft, accelerate, scikit-learn, scipy, gensim and sentencepiece. No model downloads needed. It's a niche educational pack by HowToSD with minimal community chatter; the repo's docs/reference/ is your reference.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTCALLABLE | PTCALLABLE | — |