Pt Compute Loss
The node the author told you not to use (mostly)
- input_tens
- target_tens
- loss
- TENSOR
Here's a first for a node guide: the node's own source code says you probably shouldn't use it. Pt Compute Loss exists to compute a loss value from a model's output, the ground-truth target, and a loss object - and the author's comment is blunt: "The user does not normally need to use this node. Instead the user should use training nodes that accept a loss object."
Why the disclaimer? Because the pack's training nodes (PtTrainModel and friends) take a loss object directly and handle the loss computation internally. If you're running the standard train-a-classifier flow, you'll pick a PtnCrossEntropyLoss or PtnMSELoss node, wire it into the training node, and never touch this one. Pt Compute Loss is for the edge case where you're building a custom training loop or a validation step yourself and you want the loss value handed to you as a tensor.
Inputs
input_tens- the model output (y_hat), aTENSOR.target_tens- the ground truth / labels, aTENSOR.loss- aPTLOSSobject from one of the pack'sPtn*Lossnodes (MSE, cross-entropy, L1, KL-div, etc.).
Output: a TENSOR holding the computed loss - a scalar (0-d) tensor for most loss objects with default reduction.
Where people get burned
The classic beginner trap: feeding in input_tens and target_tens with incompatible shapes. Loss functions are picky. Cross-entropy wants class-index targets (or logits), MSE wants matching shapes - a misaligned batch or a target tensor that's one-hot when the loss expects class indices will error or, worse, silently produce a wrong-looking number. Check shapes with PtShowSize before you blame the node.
Also note this is a forward pass only - it computes the loss, it doesn't backprop. In this pack, gradients are the training nodes' job. If you find yourself wiring this into a custom loop and nothing trains, that's the missing piece.
Installing it
Ships in ComfyUI-Pt-Wrapper by Hide Inada (HowToSD). ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
The pack installs a heavyweight requirements.txt - transformers, datasets, scikit-learn, scipy, gensim, pandas, peft, accelerate, and more. If Manager's install fails partway, pip install -r requirements.txt inside the clone. No model downloads for this node itself; the example training workflows auto-fetch datasets like CIFAR-10 and Fashion-MNIST.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_tens | TENSOR | — | |
| target_tens | TENSOR | — | |
| loss | PTLOSS | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |