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

[dispatcher] avoid autograd fixup step on non-backend keys #46135

Closed
wants to merge 3 commits into from

Conversation

bhosmer
Copy link
Contributor

@bhosmer bhosmer commented Oct 10, 2020

Stack from ghstack:

Previously we were unconditionally running the autograd fixup post-processing step in updateDispatchTable_(), even when the key being updated wasn't a backend key. This wasn't failing because getAutogradKeyFromBackend() would default to AutogradOther for non-backend keys. (So the extra call wasn't doing any damage, just resynching AutogradOther a bit more than necessary :P).

Reviewer notes: here's everything in the diff:

  1. Main change is just the isBackendDispatchKey() guard on the fixup step
  2. ...along with that new helper function.
  3. The rest is some minor code movement to get things in the right header files for the new predicate functions, and autofixing some whitespace errors from the comments PR.

Differential Revision: D24235974

bhosmer added a commit that referenced this pull request Oct 10, 2020
ghstack-source-id: c0139a203e9684dea35c9dd22487d06f641a325a
Pull Request resolved: #46135
@bhosmer bhosmer requested a review from ailzhang October 10, 2020 04:00
@dr-ci
Copy link

dr-ci bot commented Oct 10, 2020

💊 CI failures summary and remediations

As of commit cb02402 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)---
This 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.

See how this bot performed.

This comment has been revised 16 times.

Copy link
Contributor

@ailzhang ailzhang left a comment

Choose a reason for hiding this comment

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

Thanks!!

Previously we were unconditionally running the autograd fixup post-processing step in `updateDispatchTable_()`, even when the key being updated wasn't a backend key. This wasn't failing because `getAutogradKeyFromBackend()` would default to `AutogradOther` for non-backend keys. (So the extra call wasn't doing any damage, just resynching AutogradOther a bit more than necessary :P). 

Reviewer notes: here's everything in the diff:
1. Main change is just the `isBackendDispatchKey()` guard on the fixup step
2. ...along with that new helper function.
3. With this change I was able to tighten the definition of `getAutogradKeyFromBackend()` to avoid leaking `AutogradOther`.
4. This actually led me to another such leak: `UndefinedTensorImpl` was adding `AutogradOther` to its `key_set_` as a result of calling `getAutogradKeyFromBackend(DispatchKey::Undefined)`. Avoided this with a guard in `TensorImpl`'s constructor. The new overhead seems tolerable; I think the only hygienic alternative would be to refactor the key_set initialization so TensorImpl and UndefinedTensorImpl have different paths. Didn't seem worth it?
5. The rest is some minor code movement to get things in the right header files for the new predicate functions, and autofixing some whitespace errors from the comments PR.

Differential Revision: [D24235974](https://our.internmc.facebook.com/intern/diff/D24235974)

[ghstack-poisoned]
Previously we were unconditionally running the autograd fixup post-processing step in `updateDispatchTable_()`, even when the key being updated wasn't a backend key. This wasn't failing because `getAutogradKeyFromBackend()` would default to `AutogradOther` for non-backend keys. (So the extra call wasn't doing any damage, just resynching AutogradOther a bit more than necessary :P). 

Reviewer notes: here's everything in the diff:
1. Main change is just the `isBackendDispatchKey()` guard on the fixup step
2. ...along with that new helper function.
3. With this change I was able to tighten the definition of `getAutogradKeyFromBackend()` to avoid leaking `AutogradOther`.
4. This actually led me to another such leak: `UndefinedTensorImpl` was adding `AutogradOther` to its `key_set_` as a result of calling `getAutogradKeyFromBackend(DispatchKey::Undefined)`. Avoided this with a guard in `TensorImpl`'s constructor. The new overhead seems tolerable; I think the only hygienic alternative would be to refactor the key_set initialization so TensorImpl and UndefinedTensorImpl have different paths. Didn't seem worth it?
5. The rest is some minor code movement to get things in the right header files for the new predicate functions, and autofixing some whitespace errors from the comments PR.

Differential Revision: [D24235974](https://our.internmc.facebook.com/intern/diff/D24235974)

[ghstack-poisoned]
bhosmer added a commit that referenced this pull request Oct 13, 2020
ghstack-source-id: e5ba3f793a9f885b0df82c7d8259eb2dc089a269
Pull Request resolved: #46135
@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

❗ No coverage uploaded for pull request base (gh/bhosmer/53/base@806fc87). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                  Coverage Diff                  @@
##             gh/bhosmer/53/base   #46135   +/-   ##
=====================================================
  Coverage                      ?   68.26%           
=====================================================
  Files                         ?      410           
  Lines                         ?    53608           
  Branches                      ?        0           
=====================================================
  Hits                          ?    36593           
  Misses                        ?    17015           
  Partials                      ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 806fc87...cb02402. Read the comment docs.

@facebook-github-bot
Copy link
Contributor

@bhosmer merged this pull request in d224551.

@facebook-github-bot facebook-github-bot deleted the gh/bhosmer/53/head branch October 17, 2020 14:15
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.

None yet

3 participants