-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when transposing a jaxpr, do a constant eval pass
Before this change, the jaxpr ``` { lambda ; ; a. let b = add 2. 3. c = mul b a in [c] } ``` was not transposable, even though it is linear. The issue was that our transposition machinery assumed that in effect there were no constant subexpressions, and that constants appeared only as literals or as constvars. So this jaxpr would work: ``` { lambda ; ; a. let b = mul 5. a in [b] } ``` However, as in #1715, using `tie_in` to control the parts of the computation that get staged out to jaxprs and hence xla (e.g. to avoid materializing large constants) could create jaxprs with constant subexpressions (indeed that's the point!). This commit resolves the issue by adding a constant evaluation pass to `backward_pass` in ad.py. In the grad-of-jit case, this evaluation is staged out to XLA. We thought about having `tie_in` not appear in jaxprs (as in #1647), but that would remove our ability to stage computations out to the backward pass (e.g. to avoid materializing a large constant in the backward pass). The solution here is a stop-gap that we hope to be cleaned up a bit with #1677, which aims to provide an explicit embedding API to replace the use of `tie_in`. Co-authored-by: Dougal Maclaurin <dougalm@google.com>
- Loading branch information
Showing
5 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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