Closed1
nn.KLDivLossのreductionについて

reduction == "mean"の場合だと警告が出る。
/usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:2943: UserWarning: reduction: 'mean' divides the total loss by both the batch size and the support size.'batchmean' divides only by the batch size, and aligns with the KL div math definition.'mean' will be changed to behave the same as 'batchmean' in the next major release.
ドキュメント[1]によると、reduction="batchmean"
の場合は集計結果をBatch数で割る。この指定だとKL divergenceの数学的な定義と一致するらしい。将来的にreduction="mean"
もreduction="batchmean"
と同じ振る舞いに変更されるとのこと。
Reference
このスクラップは2023/11/16にクローズされました