-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] TF-1046: put gen sig in more places #28735
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
Conversation
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!
// same as the derivative generic signature, then the requirements are | ||
// satisfied. This check is necessary because the subsequent logic does not | ||
// correctly handle polymorphic original functions. | ||
// TODO(TF-1055): Can be removed after we have a robust solution for TF-1055. |
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 what's the specific symptom of TF-1055?
Referencing the example:
sil_differentiability_witness @foo <T: A> { ... }
sil_differentiability_witness @foo <T: B> { ... }
sil @foo : <T> (T) -> T
sil @example
bb0:
%1 = function_ref @foo : <T> (T) -> T
%2 = differentiable_function %1
%3 = differentiable_function_extract [vjp] %2
...
Currently, is the symptom that one differentiability witness is chosen at random during differentiable_function
canonicalization?
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.
You'd get an error that foo is not differentiable, even if the next instruction applies the vjp to something that conforms to A
. However, I don't know if any swift code will actually generate SIL like that.
With this check here, I know of no swift code that causes any symptoms.
A symptom that you can get from real swift, if you remove the check here, is:
protocol P {
@differentiable
func f(_ x: Float) -> Float
}
extension P {
@differentiable
func f(_ x: Float) -> Float
}
struct S: P {}
=>
error: function is not differentiable because `Self: P` is not satisfied
(error from memory, don't have a compiler to test it on right now)
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 reason that error happens is that the differentiability witness table for P.f
has a Self: P
constraint, and the substitution map that gets passed in to diagnoseUnsatisfiedRequirements
doesn't have anything satisfying those constraints.
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 see, thanks for the details! I wonder if this is a deficiency in the code around diagnoseUnsatisfiedRequirements
(e.g. logic for computing the substitution map). I'll try to reproduce the issue after this patch lands.
@swift-ci please test tensorflow |
All downstream repo tests passed, except swift-jupyter flaked. I'm rerunning that to make sure it's not a real failure. If that passes, then I'll merge this! |
This PR puts the generic signature of the original function in the
DifferentiableAttribute
, solving TF-1046.This exposed 3 latent bugs, which I had to deal with:
getNextOverriddenVTableEntry
was returning a result with the generic signature of the overriding derivative, but it should return a result with the generic signature of the overridden derivative.TODO(TF-1055)
in the code.