Reuse intermediate results over multiple backwards grad_inputs#3526
Merged
Conversation
Collaborator
apaszke
reviewed
Nov 7, 2017
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Contributor
Author
|
I also pushed a fairly hefty piece of documentation on the top of |
colesbury
approved these changes
Nov 7, 2017
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
…atives.yaml Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
e4316fe to
4131990
Compare
Contributor
Author
|
Pushed some PR comment fixes, and squashed some lint commits. I'll merge this when CI passes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first two commits are just a little bit of refactoring.
The next two support defining gradient for multiple inputs simultaneously in
derivatives.yaml, and then an example of how to use it viaatan2. The basic model is, instead of sayingoutput1: returns a tensorandoutput2: returns a tensor, you just sayoutput1, output2: returns a tuple of tensorsI am not entirely sure I have done the
output_maskhandling idiomatically. This definitely seems like an opportunity for some compiler-y techniques. For example, one way to implement this assuming you have a working compiler is to define the computation once assuming every output is needed, and then for every output_mask permutation, DCE the unneeded outputs. (This is, of course, assuming that there isn't a totally different algorithm that is applicable when you can remove required grads; in the case of atan2, this is definitely not the case.) In any case I don't plan to do this on this PR.Looking at derivatives.yaml, here are some more opportunities for reusing intermediate computations with addbmm and dist (which already have gradients.) I'll do these once I confirm the pattern looks good.