Ptn Smooth L1 Loss
Ptn Smooth L1 Loss sits between L1 and L2
- PTLOSS
PtnSmoothL1Loss gives you PyTorch's nn.SmoothL1Loss as a node - a loss function that's mathematically wedged between mean absolute error and mean squared error. For regression training in ComfyUI-Pt-Wrapper, it's the sensible default whenever your data has the occasional wild outlier that would otherwise yank your whole model around. It's one of several loss nodes the pack exposes (BCE, cross-entropy, and friends), and it outputs the pack's PTLOSS type that plugs into Pt Compute Loss or the training nodes.
Why you'd reach for it
Plain L1 loss treats every error equally, which means one bad data point can drag training. Plain L2 (MSE) punishes big errors quadratically, which makes training very sensitive to outliers - a single crazy value can dominate the gradient. Smooth L1 splits the difference: small errors are penalized like L1 (robust, linear), large errors also like L1 (so they don't blow up), and there's a smooth quadratic transition in between. That's why it's the default choice in a lot of object-detection heads - it's the pragmatic middle child. Reach for it when your regression data has noise spikes; reach for plain MSE when your errors are well-behaved and you want stronger gradient pressure near the minimum.
How it works
Two inputs, both from PyTorch's own recipe:
- reduction -
mean,sum, ornone.meanis the standard for training (a per-batch average, so the loss doesn't scale with batch size);sumadds everything up;nonereturns a per-element tensor, which you'd only want if you're doing your own post-processing of the loss. - beta - the threshold that defines "small error." Errors below
betaare treated with the smooth quadratic behavior; errors above it get the linear L1 treatment. Default1.0is fine in most cases. A largerbetamakes more of the error range behave like L2 (more sensitivity); a smaller one makes the function more purely L1.
The output is a PTLOSS object, not a number. You wire it into Pt Compute Loss (which pairs it with the model's output and the target tensors) or directly into a training node that accepts a loss. That's the pack's pattern: model nodes output PTMODEL, optimizers output PTOPTIMIZER, losses output PTLOSS, and the trainer ties the whole bundle together.
The one thing worth knowing
The reduction choice is the only setting you'll revisit. If your training loss numbers jump around between runs and you're comparing against another pipeline, make sure both use the same reduction - mean vs sum gives different scales entirely. Also note beta has a huge allowed range in the node (up to 1e9), which is just PyTorch's own bounds surfacing; you'll practically never leave 0.1–10.
Installing it
Ships in ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). Install via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI - the first start is slow while requirements.txt installs pandas, scikit-learn, transformers, sentencepiece, peft and the rest. No model files to fetch for this node.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| reduction | COMBO | 3 options: mean, sum, none | |
| beta | FLOAT | 10–1000000000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTLOSS | PTLOSS | — |