Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

This fixes #28575.

It seems poisson_nll_loss was implemented with the incorrect assumption about masked_select, which actually doesn't return tensor with the same storage, so in-place operation used there didn't work as intended.
Here I used masked_fill instead.

Also, the existing test didn't have reference_fn, so I added it (although it's not fundamentally useful since current cpp poisson_nll_loss itself does exactly same algorithm as reference_fn).

Thanks in advance for reviewing this PR.

target_fn=lambda: torch.randn(2, 3, 4, 5).floor_().abs_(),
reference_fn=lambda i, t, _: (i.exp() - t.mul(i)).mean(),
desc='no_full_loss',
check_forward_only=False,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that criterion_tests doesn't test backward by default. So, I added check_forward_only=False explicitly here for easier code review.
But, I suppose, such default is intended for faster test execution time, so I'll remove this if it's desired so.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mruberry do you know what is our take on this? Should we set this back to the default before merging?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like PyTorch tests backwards in module_tests and not criterion_tests (per @hi-ogawa's comment). Without a compelling reason I wouldn't change this behavior. NLLLoss is also tested by the module tests. (Unfortunately our test suite is a confusing mess of redundancy.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the point here is that since the function itself is autodiffed, there is no point to check the gradient computations.
@hi-ogawa could you set this flag back to the default value (remove the line).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mruberry @albanD Thanks a lot for the review. Right, poissonnllloss_no_reduce_test (Line 280) is included in new_module_tests instead of new_criterion_tests and that one actually checks backward. Okay, I removed check_forward_only=False to align with other tests here and I hope it's ready to merge now.

@soumith soumith requested a review from gchanan October 25, 2019 17:50
@soumith soumith added this to the 1.3.1 milestone Oct 25, 2019
@soumith soumith requested review from albanD and removed request for gchanan November 1, 2019 05:34
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

This looks good, thanks for the PR !
Let's wait for @mruberry's answer for the tests and then we can merge.

target_fn=lambda: torch.randn(2, 3, 4, 5).floor_().abs_(),
reference_fn=lambda i, t, _: (i.exp() - t.mul(i)).mean(),
desc='no_full_loss',
check_forward_only=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@mruberry do you know what is our take on this? Should we set this back to the default before merging?

@albanD
Copy link
Collaborator

albanD commented Nov 1, 2019

@hi-ogawa The python linter complains that you should put 2 spaces before the inline comments in the test file. Could you add that quickly please?

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Nov 1, 2019

@albanD thanks a lot for the comment. I just fixed lint failures and flake CI looks okay now.

@albanD
Copy link
Collaborator

albanD commented Nov 1, 2019

Looks good. Thanks for the quick update.

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.

@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@albanD
Copy link
Collaborator

albanD commented Nov 4, 2019

Thanks for updating.
Merging now.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Nov 5, 2019
Summary:
This fixes pytorch/pytorch#28575.

It seems `poisson_nll_loss` was implemented with the incorrect assumption about `masked_select`, which actually doesn't return tensor with the same storage, so in-place operation used there didn't work as intended.
Here I used `masked_fill` instead.

Also, the existing test didn't have `reference_fn`, so I added it (although it's not fundamentally useful since current cpp `poisson_nll_loss` itself does exactly same algorithm as `reference_fn`).

Thanks in advance for reviewing this PR.
Pull Request resolved: pytorch/pytorch#28637

Differential Revision: D18299724

Pulled By: albanD

fbshipit-source-id: 1aac5b20e77bf54874b79018207ba8f743766232
@facebook-github-bot
Copy link
Contributor

@albanD merged this pull request in 2c3c702.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PoissonNLLLoss does not compute the value documented

5 participants