-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff upstream] Upstream @derivative
attribute type-checking.
#28738
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 upstream] Upstream @derivative
attribute type-checking.
#28738
Conversation
The `@derivative` attribute registers a function as a derivative of another function-like declaration: a 'func', 'init', 'subscript', or 'var' computed property declaration. The `@derivative` attribute also has an optional `wrt:` clause specifying the parameters that are differentiated "with respect to", i.e. the differentiation parameters. The differentiation parameters must conform to the `Differentiable` protocol. If the `wrt:` clause is unspecified, the differentiation parameters are inferred to be all parameters that conform to `Differentiable`. `@derivative` attribute type-checking verifies that the type of the derivative function declaration is consistent with the type of the referenced original declaration and the differentiation parameters. Resolves TF-829.
@swift-ci Please test |
Build failed |
Gate `@derivative` attribute by `-enable-experimental-differentiable-programming` flag.
@swift-ci Please test |
Build failed |
Build failed |
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, I love the testcase, great job.
02515c9
to
2ce6b05
Compare
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test macOS |
Merging to unblock progress on upstreaming AutoDiff. Happy to address additional feedback later! |
The
@derivative
attribute registers a function as a derivative of anotherfunction-like declaration: a
func
,init
,subscript
, orvar
computedproperty declaration.
The
@derivative
attribute also has an optionalwrt:
clause specifying theparameters that are differentiated "with respect to", i.e. the differentiation
parameters. The differentiation parameters must conform to the
Differentiable
protocol.
If the
wrt:
clause is unspecified, the differentiation parameters are inferredto be all parameters that conform to
Differentiable
.@derivative
attribute type-checking verifies that the type of the derivativefunction declaration is consistent with the type of the referenced original
declaration and the differentiation parameters.
Resolves TF-829.
Examples:
The differentiable programming manifesto has more information and examples.
Note: this code is upstreamed from
tensorflow
branch. Some functions are intentionally notstatic
(fileprivate) because they have users in other files ontensorflow
branch.Known issues are referenced in comments:
DerivativeAttrs
cache fromASTContext
.We would like to upstream code and continue development on
master
, if that's acceptable!cc @rxwei @marcrasi @bgogul