Nodes/ComfyUI-Pt-Wrapper/Ptn Huber Loss
ComfyUI Node

Ptn Huber Loss

Huber loss as a node — MSE and L1, and you pick the boundary

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn Huber Loss
    • PTLOSS
    reduction
    delta1

    Huber loss is the regression loss that refuses to pick sides: below a threshold it behaves like MSE, above it like L1. PtnHuberLoss wraps nn.HuberLoss and gives you both behaviors in one node, with a delta slider deciding where the switch happens. If you're doing regression and find plain MSE too twitchy about outliers - or plain L1 too sluggish around the minimum - this is the compromise you actually want, and it's the only regression loss in the pack with a real tuning parameter.

    How it works

    For errors smaller than delta, it's quadratic: 0.5 * error². Beyond delta, it's linear: delta * (|error| − 0.5 * delta). The two pieces join smoothly, so you get MSE's precise gradient near the target and L1's outlier-resistance further away. That single delta is the whole point - it's the distance from the target where you stop punishing errors quadratically and start punishing them linearly.

    The inputs that matter

    • reduction - mean, sum, or none, combining the per-element losses. mean is the sensible default.
    • delta (default 1) - the switch threshold. Smaller delta means the loss goes linear sooner, making it more outlier-resistant but less smooth near zero. Larger delta makes it behave more like pure MSE. 1.0 is a solid default; for very noisy targets, lower it; for clean data, you can raise it.

    Output is a single PTLOSS, wired into a trainer's loss_function input (Pt Train Model, etc.) or a compute-loss node. Like the other regression losses, this expects predictions and targets in the same units and shape - no built-in activation.

    Installing

    Same as every node in the pack. ComfyUI Manager → search "Pt-Wrapper", or:

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

    Restart ComfyUI; the pack's requirements install on first launch.

    Where people get burned

    The most common confusion is treating delta like a learning rate - it's not; it's a geometric boundary in the error space. And while Huber's smooth transition beats L1's kink, it can still stall on extreme outliers because the linear part's gradient is constant, not zero. If your loss flatlines, check that predictions and targets are shape-matched and roughly in the same numeric range before blaming the threshold.

    CategoryTraining

    Inputs (2)

    NameTypeDefaultDescription
    reductionCOMBO3 options: mean, sum, none
    deltaFLOAT10–1000000000

    Outputs (1)

    NameTypeDescription
    PTLOSSPTLOSS