10/13
Part 7 of 7 · Follow-upsLearn
PyTorch's KLDivLoss reduction
The second follow-up is a PyTorch detail. PyTorch's documentation warns that the reduction named mean doesn't return the true KL divergence value, and to use batchmean, which aligns with the mathematical definition. mean divides by every element, the batch times the classes, instead of by the batch size.