-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Fix MSELoss when target.requires_grad is True. #44437
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
MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True. This PR does the following: 1) adds derivative support for target via the normal derivatives.yaml route 2) kill the different (and incorrect) path for when target.requires_grad was True 3) modify the MSELoss CriterionTests to verify that the target derivative is checked. TODO: 1) do we still need check_criterion_jacobian when we run grad/gradgrad checks? 2) ensure the Module tests check when target.requires_grad 3) do we actually test when reduction='none' and reduction='mean'? [ghstack-poisoned]
MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True. This PR does the following: 1) adds derivative support for target via the normal derivatives.yaml route 2) kill the different (and incorrect) path for when target.requires_grad was True 3) modify the MSELoss CriterionTests to verify that the target derivative is checked. TODO: 1) do we still need check_criterion_jacobian when we run grad/gradgrad checks? 2) ensure the Module tests check when target.requires_grad 3) do we actually test when reduction='none' and reduction='mean'? ghstack-source-id: cbfba5f Pull Request resolved: #44437
💊 CI failures summary and remediationsAs of commit c472bb2 (more details on the Dr. CI page):
1 failure confirmed as flaky and can be ignored:
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 8 times. |
|
|
Codecov Report
@@ Coverage Diff @@
## gh/gchanan/322/base #44437 +/- ##
=======================================================
- Coverage 68.00% 67.99% -0.01%
=======================================================
Files 382 382
Lines 49379 49373 -6
=======================================================
- Hits 33578 33572 -6
Misses 15801 15801
Continue to review full report at Codecov.
|
MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True. This PR does the following: 1) adds derivative support for target via the normal derivatives.yaml route 2) kill the different (and incorrect) path for when target.requires_grad was True 3) modify the MSELoss CriterionTests to verify that the target derivative is checked. TODO: 1) do we still need check_criterion_jacobian when we run grad/gradgrad checks? 2) ensure the Module tests check when target.requires_grad 3) do we actually test when reduction='none' and reduction='mean'? Differential Revision: [D23612166](https://our.internmc.facebook.com/intern/diff/D23612166) [ghstack-poisoned]
MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True. This PR does the following: 1) adds derivative support for target via the normal derivatives.yaml route 2) kill the different (and incorrect) path for when target.requires_grad was True 3) modify the MSELoss CriterionTests to verify that the target derivative is checked. TODO: 1) do we still need check_criterion_jacobian when we run grad/gradgrad checks? 2) ensure the Module tests check when target.requires_grad 3) do we actually test when reduction='none' and reduction='mean'? ghstack-source-id: 88dab44 Pull Request resolved: #44437
albanD
left a comment
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.
lgtm
Not sure why we didn't do that before... :D
| # currently compute the gradient w.r.t. target for loss functions. | ||
| gradcheck(apply_fn, inputs) | ||
| if target.requires_grad: | ||
| inputs = inputs + (target,) |
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 this works but it is a bit fragile.
Your apply_fn above actually ignores the target that is given in *params. But it works because it captures the same target from the parent scope. And the gradcheck ensures that you can do that. But I think it would be clearer to just get the target from the apply_fn inputs properly no?
Summary: Pull Request resolved: #44437 MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True. This PR does the following: 1) adds derivative support for target via the normal derivatives.yaml route 2) kill the different (and incorrect) path for when target.requires_grad was True 3) modify the MSELoss CriterionTests to verify that the target derivative is checked. TODO: 1) do we still need check_criterion_jacobian when we run grad/gradgrad checks? 2) ensure the Module tests check when target.requires_grad 3) do we actually test when reduction='none' and reduction='mean'? Test Plan: Imported from OSS Reviewed By: albanD Differential Revision: D23612166 Pulled By: gchanan fbshipit-source-id: 4f74d38d8a81063c74e002e07fbb7837b2172a10
Stack from ghstack:
MSELoss had a completely different (and incorrect, see #43228) path when target.requires_grad was True.
This PR does the following:
TODO:
Differential Revision: D23612166