fn
l1_loss
→Tensorl1_loss(x: Tensor, target: Tensor, reduction: str = 'mean')Mean-absolute-error (L1) loss between input and target.
Robust regression loss whose gradient is constant in magnitude
() and therefore insensitive to outliers —
extreme residuals do not dominate the update direction as they
do under mse_loss. The trade-off is a non-smooth
optimisation surface at (sub-gradient at zero),
which can produce slightly slower convergence for small errors.
Often paired with smooth_l1_loss to recover smoothness
while keeping outlier robustness.
Parameters
xTensorPredicted values, any shape.
targetTensorTarget values; broadcast-compatible with
x.reductionstr= 'mean'"mean" (default), "sum", or "none".Returns
TensorScalar loss for "mean" / "sum", or a per-element
tensor with x's shape for "none".
Notes
Per-element loss:
Gradient w.r.t. x is
(zero at the origin). Used heavily in image-to-image regression
(super-resolution, denoising) where outlier-robustness matters.
Examples
>>> import lucid
>>> from lucid.nn.functional import l1_loss
>>> pred = lucid.tensor([1.0, 2.0, 3.0])
>>> target = lucid.tensor([1.5, 2.5, 2.5])
>>> l1_loss(pred, target)
Tensor(0.5)