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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nll_loss crash on cpu where ignore_index is out of bounds #17328

Closed
wants to merge 3 commits into from

Conversation

soumith
Copy link
Member

@soumith soumith commented Feb 21, 2019

Fixes #15508

@@ -39,7 +39,7 @@ void THNN_(ClassNLLCriterion_updateOutput)(
for (i = 0; i < batch_size; i++) {
int cur_target = THLongTensor_fastGetLegacy1dNoScalars(target, i) - TH_INDEX_BASE;

if (cur_target >= 0 && cur_target < n_classes) {
if ((cur_target >= 0 && cur_target < n_classes) || (cur_target == ignore_index)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be better if you move the inner if (cur_target == ignore_index) { block outside this?

@soumith
Copy link
Member Author

soumith commented Feb 21, 2019

@pytorchbot rebase this please

@pytorchbot
Copy link
Collaborator

Sorry, I can't rebase this because the author of this PR didn't grant maintainers permission to modify the branch.

Hey @soumith! If you click the Allow edits from maintainers checkbox on the right sidebar, I can rebase PRs automatically from you. Please consider letting me help you out ;)

(To learn more about this bot, see Bot commands.)

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Mar 5, 2019
Summary:
Fixes pytorch/pytorch#15508
Pull Request resolved: pytorch/pytorch#17328

Differential Revision: D14322629

Pulled By: soumith

fbshipit-source-id: 7d02f372be78794782c18affcfc109ce30b1e91c
@soumith soumith deleted the nll_bug branch April 7, 2019 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

target out of bounds error in cross entropy
5 participants