-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] declaration-only SILDifferentiabilityWitness
#27854
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] declaration-only SILDifferentiabilityWitness
#27854
Conversation
@swift-ci please test tensorflow |
@swift-ci please test tensorflow macos |
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.
Nice!
For reference: the compiler doesn't yet generate differentiability witnesses, that will be done by the differentiation transform later.
|
||
sil @externalFn1 : $@convention(thin) (Float) -> Float | ||
|
||
sil @AD__externalFn1__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) { |
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.
I wonder if we want to support "differentiability witness definition (has body) referring to JVP/VJP declarations (bodiless)"?
I wonder if the test still passes if @AD__externalFn1__jvp_src_0_wrt_0
and @AD__externalFn1__vjp_src_0_wrt_0
are made bodiless?
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.
Yes it passes. I'll add a test that does that. (Bodiless original with defined jvp/vjp seems like the most common case that will happen in practice so I want to keep a test that does it this way rather than modifying this test to have bodiless jvp/vjp).
SILDifferentiabilityWitness
SILDifferentiabilityWitness
SILDifferentiabilityWitness
SILDifferentiabilityWitness
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.
Although isDeclaration
makes sense, it's a bit odd that it's not reflected in the syntax in any way. How about adding a [declaration]
attribute?
Is there precedent for an explicit Syntactically, I thought "no body" implies "declaration" and "has body" implies "definition" for other SIL constructs. If we add a I'd prefer no |
Of course, it is unprecedented. |
I see, touché: bodiless witness could be "declaration" or "empty definition, output of SILGen to be canonicalized by the differentiation transform". Adding a |
Alternatively, you can add something like |
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.
There is already a syntax difference between decl/defn:
sil_differentiability_witness ... {}
vs
sil_differentiability_witness ...
And this is precedented in protocol witness table. You can see the printer that omits the braces and does not print any attribute when it's a declaration: https://github.com/apple/swift/blob/6d178e81ce44b6be44fdd2d9ef7c5ce7e3046709/lib/SIL/SILPrinter.cpp#L2908
So I'll leave the printing and parsing as it is, unless you still have doubts about the current way.
|
||
sil @externalFn1 : $@convention(thin) (Float) -> Float | ||
|
||
sil @AD__externalFn1__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) { |
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.
Yes it passes. I'll add a test that does that. (Bodiless original with defined jvp/vjp seems like the most common case that will happen in practice so I want to keep a test that does it this way rather than modifying this test to have bodiless jvp/vjp).
Leaving printing and parsing as is (no explicit We discussed a potential phase-ordering problem where "a differentiability witness with no JVP/VJP could be interpreted as either a declaration or an empty definition", but I believe those two states actually have different syntax:
|
We need declaration-only
SILDifferentiabilityWitness
so that we can refer to differentiability witnesses defined in other modules.Therefore, this PR:
create
methods forSILDifferentiabilityWitness
. (credit to @dan-zheng's original work on this)test/AutoDiff/sil_differentiability_witness.sil
.fn = State.getGlobalNameForReference(name, fnType, fnNameLoc);
inParseSIL.cpp
is what fixes this.