-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Create JVPEmitter #25954
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
[AutoDiff] Create JVPEmitter #25954
Conversation
) (swiftlang#25778) Xcode puts the bin/ and lib/ directories in a subdirectory based on configuration; account for this when copying over compiler-rt for non-host Apple platforms using one of the existing helpers in build-script-impl.
`PointwiseMultiplicative` represents a ring over multiplication with identity element "one" and a multiplicative inverse (reciprocal). Conform `Differentiable` synthesized struct types to `PointwiseMultiplicative` protocol if possible. Enables revamping optimizers, which requires division (i.e. multiplication with multiplicative inverse).
…swiftlang#25803) Partial fix for `@differentiable` function thunk with output opaque abstraction pattern. Avoid `AbstractionPattern` methods that crash for opaque patterns. Small step towards fixing TF-123. Reproducers no longer crash, SIL verification fails instead. Robust fix requires more work - see TF-123 for more details.
tensorflow/swift-apis@60f63e1 `Tensor` now conforms to `PointwiseMultiplicative`.
a56c4cc
to
349db72
Compare
f4067ea
to
b7343a2
Compare
…wiftlang#25967) In VJPEmitter, if the original function call has substitutions, we `partial_apply` it with no arguments to specialize it. This `partial_apply` is not being released. JVP and VJP are being specialized the same way, but they are not being released either. To fix this, we release the `@differentiable` function returned by `autodiff_function`, which will release the original and the associated functions tht are to be filled in later altogether. If the original function does not have substitutions, we retain the original function to balance out the release of the `@differentiable` function that comes later. As a result, `ADContext::promoteToDifferentiableFunction` no longer needs to retain the associated functions. Example where the original function has substitutions: ``` f' = partial_apply f<...>() f_diff = autodiff_function f' release_value f_diff ``` Example where the original function does not have substitutions: ``` retain_value f f_diff = autodiff_function f release_value f_diff ``` Note: This makes the `autodiff_function` folding optimization no longer able to detect the pattern, but it is necessary. We can rewrite the optimization later. This should fix [TF-621](https://bugs.swift.org/browse/TF-621).
@@ -5875,108 +6123,104 @@ ADContext::declareExternalAssociatedFunction( | |||
return assocFn; | |||
} | |||
|
|||
static SILFunction* createJVP( | |||
static SILFunction *createEmptyVJP( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git diff here is acting funny in the next several lines, may be hard to follow but I more so made a copy of createEmptyVJP
and named it createEmptyJVP
and removed the previous createJVP
to more closely resemble how VJPEmitter
looks like and JVPEmitter
will become.
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
This PR extends on the previous work here on the `JVPEmitter` (#25954) to make it be able to generate SIL code for the `differential` function, as well as more correctly implementing the body of the JVP.' generates a valid JVP and differential. I have yet to add support for control flow and generics. This PR also renames `PullbackInfo` to `LinearMap` info since it has a lot of tangent mapping helpers that `JVPEmitter` can use when creating the differential. This is still early, so the JVP/Differential emission only runs with the flag `-Xllvm -run-jvp-generation` when running Swift. With it, you can differentiate basic Float functions with `+ - / *` with no `var`s
Creates a very barebones
JVPEmitter
which copies the body of the original function returning(original, undef)
, and creates the differential function with a body that returns anundef
.Apologies for the weird commit history, there was something wrong with my
tensorflow
branch on the fork of this repo that caused this. However, I fixed it now so future PRs won't be this ugly.