Limit grad recursion depth by not recursing through non-grad inputs#1764
Merged
Limit grad recursion depth by not recursing through non-grad inputs#1764
Conversation
Member
Author
|
@davidkoski this limits the stack-overflow issue with VJP that we were discussing offline. It does require a change in how VJP is called from Python -> C++. I'm not sure how it's done in Swift (if you enclosed the non-grad inputs or not). But it may also require a change there to pass in the non-grad inputs to |
angeloskath
approved these changes
Jan 14, 2025
Member
angeloskath
left a comment
There was a problem hiding this comment.
A bit of mind-bender but it makes perfect sense afterwards. Nice!
| l[i] = recurse(l[i]); | ||
| } | ||
| return nb::cast<nb::object>(subtree); | ||
| return nb::cast<nb::object>(nb::tuple(l)); |
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.
Previously we enclose non-gradient inputs in a lambda which then get recursed through when we build the VJP graph.
This change to allow an internal VJP to take a
argnumslist so that the VJP can have access to all the inputs including the ones for which no gradient is requested.An example case which would previously recurse to 10k+ and now just recurses a couple of times: