Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for binary cross-entropy on probability inputs.
Computes the element-wise loss
where is a probability (e.g. the output of a sigmoid)
and is a binary target. The clamp eps_ is added inside
the logarithm to protect against . Both input, target and
the (optional) per-element weight are saved so that the backward can
emit (for Mean; analogous for the other modes).
Math
Attributes
schema_v1OpSchema"bce_loss", AmpPolicy::ForceFP32.reduction_ReductionReduction mode.
eps_doubleNumerical clamp added to
log arguments. Default 1e-7.orig_shape_ShapeElement-wise shape before reduction.
Notes
Inputs must be valid probabilities; values outside produce
NaN / inf losses. For raw logits use BCEWithLogitsBackward,
which is numerically more stable.
Static methods
1static
forward
→TensorImplPtrint forward(const int & input, const int & target, const int & weight, Reduction reduction, double eps)Compute BCE loss with autograd wiring.
Parameters
inputTensorImplPtrProbabilities in ; arbitrary shape.
targetTensorImplPtrBinary labels in ; same shape as
input.weightTensorImplPtrPer-element weighting tensor broadcastable to
input.shape(). Pass a ones tensor if no weighting is required.reductionReductionMean, Sum, or None.epsdoubleClamp inside the logarithm; values around
1e-7 recommended.Returns
TensorImplPtrReduced or per-element loss tensor.