Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for negative log-likelihood loss.
Operates on log-probabilities (e.g. the output of log_softmax).
The per-sample loss is
and the final scalar is obtained by reducing according to
reduction_; samples whose target equals ignore_index_ are skipped.
The backward emits a sparse gradient that is nonzero only at the target
class:
Math
Attributes
schema_v1OpSchema"nll_loss", AmpPolicy::ForceFP32.reduction_ReductionReduction mode.
ignore_index_intTarget class to skip; default
-100.has_weight_boolWhether
saved_weight_ is populated.orig_input_shape_ShapeFull input shape
(N, C, ...) for backward reconstruction.saved_target_StorageInteger class labels.
saved_weight_StorageOptional per-class weight vector.
saved_valid_count_StorageScalar count of non-ignored samples for the
Mean denominator.Notes
Feeding raw logits or softmax probabilities produces incorrect results —
the input must already be in log-probability space. Prefer
CrossEntropyBackward when starting from logits.
Static methods
1static
forward
→TensorImplPtrint forward(const int & input, const int & target, const int & weight_or_null, Reduction reduction, int ignore_index)Compute NLL loss with autograd wiring.
Parameters
inputTensorImplPtrLog-probabilities of shape
(N, C) or (N, C, d_1, ...).targetTensorImplPtrInteger class labels of shape
(N,) or (N, d_1, ...).weight_or_nullTensorImplPtrOptional per-class weight vector of length ; may be null.
reductionReductionMean, Sum, or None.ignore_indexintClass index excluded from the loss / gradient.
Returns
TensorImplPtrReduced or per-sample loss tensor.