Add make_jvp and make_ggnvp convenience wrappers #237
Merged
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.
This PR adds the
make_jvp
andmake_ggnvp
convenience wrappers we developed in the thread for #175, plus tests. (It also adjusts the names inside make_vjp to be more consistent with vjp usage elsewhere.)There are some wasted FLOPs in these implementations where we propagate zero vectors through vjp's just to trace them; I think we could get rid of these wasteful computations by adding a new function to core.py that essentially transposes the matrix-free linear map represented by calling
backward_pass
on a trace. However, there would still be graph munging overhead compared to a proper forward-mode implementation.