Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for multi-class cross-entropy loss (fused log-softmax + NLL).
For a batch of samples with logits and hard integer targets the loss is
where counts samples that are not masked by ignore_index and
is the optional per-class weight vector. The backend computes the
softmax probabilities internally using the standard log-sum-exp
stabilisation and
returns them in saved_softmax_ for the backward pass, which emits
.
Math
with the leading factor present only for Reduction::Mean.
References
Goodfellow, Bengio, Courville, "Deep Learning" §6.2.2 (2016).
Attributes
schema_v1OpSchema"cross_entropy", AmpPolicy::ForceFP32.reduction_Reductioneps_doubleignore_index_int-100 (matches the public API).has_weight_booltrue when saved_weight_ holds a non-trivial per-class weight.orig_input_shape_Shape(N, C, ...) for backward reconstruction.saved_softmax_Storagesaved_target_Storagesaved_weight_Storagesaved_valid_count_StorageMean denominator.Notes
Only the input logits are wired as a saved autograd edge; the target,
weight and softmax tensors are stored in the dedicated Storage fields
because they are not differentiable inputs.
Static methods
1forward
→TensorImplPtrint forward(const int & input, const int & target, const int & weight_or_null, Reduction reduction, double eps, int ignore_index)Compute cross-entropy loss with autograd wiring.
Parameters
inputTensorImplPtr(N, C) or (N, C, d_1, ...).targetTensorImplPtr(N,) or (N, d_1, ...).weight_or_nullTensorImplPtrnullptr to disable class weighting.reductionReductionMean, Sum, or None.epsdoubleignore_indexintReturns
TensorImplPtrScalar (Mean / Sum) or per-sample (None) loss tensor.