nvalchemi.training.ForceHuberLoss#
- class nvalchemi.training.ForceHuberLoss(*, target_key='forces', prediction_key='predicted_forces', normalize_by_atom_count=False, delta=0.01, ignore_nonfinite=True, dtype_policy='strict')[source]#
Huber loss on per-component force residuals.
Applies the Huber function \(H_\delta\) to each force-component residual \(r_{ia\alpha} = \hat{F}_{ia\alpha} - F_{ia\alpha}\), reusing the masking and batch reduction of
ForceMSELoss. Withnormalize_by_atom_count=False(default) this is a global mean over every valid component:\[L = \frac{1}{3V} \sum_{i=1}^{B} \sum_{a=1}^{N_i} \sum_{\alpha=1}^{3} H_\delta\!\left(r_{ia\alpha}\right).\]With
normalize_by_atom_count=Truethe per-graph mean is averaged over graphs instead, \(L = \tfrac{1}{B} \sum_{i} \tfrac{1}{3 N_i} \sum_{a, \alpha} H_\delta(r_{ia\alpha})\).- Parameters:
target_key (str, default "forces") – Target container key for the target tensor.
prediction_key (str, default "predicted_forces") – Prediction container key for the model output.
normalize_by_atom_count (bool, default False) – Control the batch reduction for already-per-atom force residuals.
Truecomputes a graph-balanced mean by dividing each graph’s force-error sum by its valid component count before averaging over graphs.Falsecomputes one global elementwise mean over all valid force components.delta (float, default 0.01) – Positive transition point between quadratic and linear Huber regimes.
ignore_nonfinite (bool, default True) – When
True, target force components that areNaNor infinite are excluded from both loss value and gradient usingtorch.isfinite().dtype_policy ({"strict", "prediction_to_target", "target_to_prediction"}, default "strict") – How to handle prediction/target dtype mismatches before validation.
"strict"raises; the other policies cast one tensor to match the other.