How is reduction performed in `F.cross_entropy` when `weight` parameter is provided?

nn.CrossEntropyLoss normalizes with the used weights, so you would have to change the loss2 calculation to:

loss2 = F.cross_entropy(pred, label, reduction='none', weight=weight).sum() / weight[label].sum()
loss2
> tensor(1.5594)

This post also describes it using another example.