-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nll_loss with weights: reduction 'mean' gives wrong result #31295
Comments
Seems bad if there is a correctness issue. I haven't checked the code, so we should first verify that the behavior is indeed correct. nll_loss is an important loss function. |
This isn't actually a bug -- @anjali411 is going to post why. |
This is not a bug. The loss in case of mean is calculated by the following formula mentioned in the documentation https://pytorch.org/docs/stable/nn.html#nllloss For GPU example: when reduction = mean, loss = Σ ln/(w1+w0+w4) for n=1 to 3 Clarification for documentation yn = nth element in the target tensor |
@anjali411 Thank you for the explanation |
…#31488) Summary: Reference: #31385 In the current documentation for NLLLoss, it's unclear what `y` refers to in the math section of the loss description. There was an issue(#31295) filed earlier where there was a confusion if the loss returned for reduction=mean is right or not, perhaps because of lack in clarity of formula symbol description in the current documentation. Pull Request resolved: #31488 Differential Revision: D19181391 Pulled By: anjali411 fbshipit-source-id: 8b75f97aef93c92c26ecbce55b3faf2cd01d3e74
…pytorch#31488) Summary: Reference: pytorch#31385 In the current documentation for NLLLoss, it's unclear what `y` refers to in the math section of the loss description. There was an issue(pytorch#31295) filed earlier where there was a confusion if the loss returned for reduction=mean is right or not, perhaps because of lack in clarity of formula symbol description in the current documentation. Pull Request resolved: pytorch#31488 Differential Revision: D19181391 Pulled By: anjali411 fbshipit-source-id: 8b75f97aef93c92c26ecbce55b3faf2cd01d3e74
🐛 Bug
To Reproduce
Steps to reproduce the behavior:
torch.manual_seed(42)
torch.cuda.manual_seed(42)
Expected behavior
>> loss = F.nll_loss(m, target, w, reduction='none')
>> loss.mean()
mean : tensor(0.8193, grad_fn=<MeanBackward0>)
Environment
PyTorch version: 1.3.1
Is debug build: No
CUDA used to build PyTorch: 10.1.243
OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.0.2
Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.1.243
GPU models and configuration:
GPU 0: TITAN X (Pascal)
GPU 1: TITAN X (Pascal)
Nvidia driver version: 430.50
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
Versions of relevant libraries:
[pip3] numpy==1.13.3
[conda] blas 1.0 mkl
[conda] mkl 2019.4 243
[conda] mkl-service 2.3.0 py36he904b0f_0
[conda] mkl_fft 1.0.14 py36ha843d7b_0
[conda] mkl_random 1.1.0 py36hd6b4f25_0
[conda] pytorch 1.3.1 py3.6_cuda10.1.243_cudnn7.6.3_0 pytorch
[conda] torchvision 0.4.2 py36_cu101 pytorch
cc @ezyang @gchanan @zou3519
The text was updated successfully, but these errors were encountered: