I am getting two different loss values in the following situations, although I expect them to be same.


ce = torch.nn.CrossEntropyLoss(classWeights, reduction=‘none’)
loss = ce(input, targets).mean()


ce = torch.nn.CrossEntropyLoss(classWeights, reduction=‘mean’)
loss = ce(input, targets)


What could be the reason for that?