Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.nn.MultiLabelMarginLoss has different performance on CPU and GPU. #89408

Open
triumph-wangyuyang opened this issue Nov 21, 2022 · 3 comments
Labels
module: loss Problem is related to loss function triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@triumph-wangyuyang
Copy link

馃悰 Describe the bug

Test on the CPU:

import torch
loss = torch.nn.MultiLabelMarginLoss()
x = torch.randn((1, 4))
y = torch.randint(4, 16, [1, 4])
out = loss(x, y)
print(out)

result: RuntimeError: argument #2 'target' is out of range

Test on the GPU:

import torch
loss = torch.nn.MultiLabelMarginLoss().cuda()
x = torch.randn((1, 4)).cuda()
y = torch.randint(4, 16, [1, 4]).cuda()
out = loss(x, y)
print(out)

result: tensor(5.7001, device='cuda:0')

torch.nn.MultiLabelMarginLoss has different performance on CPU and GPU.

Versions

pytorch: 1.12.1
Python version: 3.8
CUDA/cuDNN version: cuDNN 11.3
GPU models and configuration: RTX3060
Operating System锛歐indows

@samdow samdow added module: loss Problem is related to loss function triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 21, 2022
@triumph-wangyuyang
Copy link
Author

Is there any progress on this issue?

@akashdhamasia12
Copy link

According to the definition as given here:
https://pytorch.org/docs/stable/generated/torch.nn.MultiLabelMarginLoss.html

y has to be in the range as:
image

thats why you are getting the error.

@triumph-wangyuyang
Copy link
Author

According to the definition as given here: https://pytorch.org/docs/stable/generated/torch.nn.MultiLabelMarginLoss.html

y has to be in the range as: image

thats why you are getting the error.

I know that parameters have this limitation, but I tested with unreasonable parameters to test whether the operator has a check when inputting unreasonable parameters. On this operator, I found that when the operator is running, and It is unreasonable to let the program continue without first checking whether the parameters are reasonable. Therefore, I suggest adding a check on the parameter size at the program entry, so that when it is unreasonable, an exception is directly thrown or a warning message is given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: loss Problem is related to loss function triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Status: Done
Development

No branches or pull requests

3 participants