colossalai.nn.loss.loss_2d
- class colossalai.nn.loss.loss_2d.CrossEntropyLoss2D(reduction=True, *args, **kwargs)[source]
Cross entropy loss for 2D parallelism
- Parameters
reduction (bool, optional) – whether to average the loss, defaults to True.
The
argsandkwargsshould include parameters below:weight (Tensor, optional) size_average (bool, optional) ignore_index (int, optional) reduce (bool, optional) label_smoothing (float, optional)
More details about
args,kwargsandtorch.nn.functional.cross_entropycould be found in Cross_entropy.- forward(logits, targets)[source]
Calculate loss between logits and targets.
- Parameters
logits (
torch.tensor) – Predicted unnormalized scores (often referred to as logits).targets (
torch.tensor) – Ground truth class indices or class probabilities.
- Returns
the loss between logits and targets.
- Return type
float