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. With normalize_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=True the 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. True computes a graph-balanced mean by dividing each graph’s force-error sum by its valid component count before averaging over graphs. False computes 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 are NaN or infinite are excluded from both loss value and gradient using torch.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.

compute_residual(pred, target, valid)[source]#

Return componentwise Huber force losses, zeroing invalid entries.

Parameters:
Return type:

Tensor

extra_repr()[source]#

Human-readable hyperparameter summary for nn.Module’s repr.

Return type:

str