-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Add SIL differentiability witnesses. #27487
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] Add SIL differentiability witnesses. #27487
Conversation
- Printing compiles but may require changes to be parseable. Namely, if there is no suitable utility for parsing standalone generic signatures, changes are needed. - Parsing is a stub. - Note: it is difficult to test parsing/printing without generating SILDifferentiabilityWitness instances.
`parameters (0, 1, ...) results (0, 1, ...) where <...>`
57e9634
to
bac0181
Compare
…tiability-witness
Use mangling to support string key lookup.
bac0181
to
d2c6ab5
Compare
d2c6ab5
to
843b631
Compare
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.
-
Because type signatures are long and sparse, I'd suggest bringing the configuration to the front of the declaration and using square brackets for them, for example:
sil_differentiability_witness hidden [parameters 0 1] [results 0] [where τ_0_0 : _Differentiable] @foo : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 { jvp: @AD__foo__jvp_src_0_wrt_0 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) vjp: @AD__foo__vjp_src_0_wrt_0 : $@convention(thin) <τ_0_0 where τ_0_0 : _Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) }
-
Parts of what
SILDifferentiabilityWitnessKey
stores could have been made a more general concept:AutoDiffConfig
. How about defining aAutoDiffConfig
in AutoDiff.h to store parameter indices, result indices, and the derivative generic signature? ThenSILDifferentiabilityWitnessKey
can just be defined asstd::pair<StringRef, AutoDiffConfig>
. -
When the function name of a
sil_differentiability_witness
is demangleable, consider printing a descriptive comment above the witness declaration, for example:// differentiability witness for closure #1 in foo<A>(_:_:) sil_differentiability_witness hidden [parameters 0 1] [results 0] [where τ_0_0 : _Differentiable] @someDemangleableName : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0 {
Print original function name in comment. ``` // differentiability witness for foo sil_differentiability_witness hidden [parameters 0 1] [results 0] [where τ_0_0 : _Differentiable] @foo ```
The contents of `AutoDiffConfig` are all uniqued, so uniquing the product does not make sense.
Unserialized, to be used for diagnostics. Will revisit later when revamping the differentiation transform.
4ddcd3f
to
ad6b7aa
Compare
771143a
to
c3959ad
Compare
Manually verified parsing/printing. Chose not to add additional test for now to keep the test small.
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.
Are there serialization tests?
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 implementation LGTM, but I just wanted to make sure serialization is tested.
ef5f53c
to
7a070f0
Compare
7a070f0
to
69209be
Compare
Note: deserialization does not work when SIL differentiability witness references bodyless function declarations.
@swift-ci Please test tensorflow |
Verification assertion messages should appear on the differentiability witness.
@swift-ci Please test tensorflow |
SIL differentiability witnesses are a new top-level SIL construct mapping "original" SIL functions to derivatives. They will replace SIL function
[differentiable]
attributes, additionally enabling cross-module retroactive derivative registration.SIL differentiability witnesses have the following components:
SILFunction
.IndexSubset
).IndexSubset
).Example syntax:
This patch adds the
SILDifferentiabilityWitness
data structure, along with parsing, printing, verification, and serialization (including lookup by key).The master issue TF-866 tracks follow-up, including SILGen/IRGen/differentiation transform changes.
Early forum discussion.