-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Migrates nll_loss_forward from TH to Aten (CUDA) #60097
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
Conversation
💊 CI failures summary and remediationsAs of commit e7877ec (more details on the Dr. CI page and at hud.pytorch.org/pr/60097):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
| const int64_t n_dims = input.dim(); | ||
| TORCH_CHECK(n_dims > 0 && n_dims <= 2, "input tensor should be 1D or 2D"); | ||
| TORCH_CHECK( | ||
| target.dim() == 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if target.dim() is 0? Previous code errored on this too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original implementation did not raise this specific error when target.dim() == 0:
pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu
Lines 14 to 16 in d5988c5
| if (THCIndexTensor_(nDimension)(state, target) > 1) { | |
| THError("multi-target not supported"); | |
| } |
I updated the check to TORCH_CHECK(target.dim() <= 1) to not change the original behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please beef up testing for supported/unsupported dims?
aten/src/ATen/native/cuda/Loss.cu
Outdated
| } | ||
| if (total_weight_acc != 0) { | ||
| *output = static_cast<scalar_t>(output_acc / total_weight_acc); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need else here, otherwise output won't be set for total_weight_acc = 0, and please add tests for all these cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I redid the implementation a little to only set *output once and added tests for the nan case and the size_average && total_weight_acc == 0 case.
|
Test errors are real |
|
@ngimel has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
@ngimel has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
While looking at a test error I saw that we already have test for zero weights and empty tensors: The rest of the public tests seems unrelated to this PR. |
|
@ngimel has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: Addresses a part of #59765 This PR adds byte support for nll_loss on the CPU for `input.dim() == 2`. CUDA support will be implemented when `nll_loss` migration to CUDA is completed in #60299 and #60097 Pull Request resolved: #60308 Reviewed By: VitalyFedyunin Differential Revision: D29329458 Pulled By: jbschlosser fbshipit-source-id: d3585c4966030bc61e451f8aa817406a8a3acf47
Fixes #24610
Aten Umbrella issue #24507
Related to #59765
The performance does not change between this PR and master with the following benchmark script:
Benchmark script
master
this PR