Skip to content
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] Deprecate @differentiable(jvp:vjp:) arguments. #28932

Merged

Conversation

dan-zheng
Copy link
Collaborator

Deprecate @differentiable attribute jvp: vjp: arguments for derivative
registration. @derivative attribute is the canonical way to register
derivatives.

Update tests.

TF-1001 tracks removing @differentiable attribute jvp: and vjp: arguments.
TF-1085 tracks removing @differentiable(jvp:vjp:) usages in the stdlib.

Todo: upstream this PR to master.


Example:

@differentiable(vjp: vjpFoo)
func foo(_ x: Float) -> Float { x }

func vjpFoo(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
  (x, { $0 })
}
test.swift:1:22: warning: 'jvp:' and 'vjp:' arguments in '@differentiable' attribute are deprecated; use '@derivative' attribute for derivative registration instead
@differentiable(vjp: vjpFoo)
                     ^~~~~~

I decided not to invest time writing fully-fledged fix-its for rewriting @differentiable(jvp:vjp:) usages to @derivative attribute, as it's slightly non-trivial. We can focus on retrodiff progress and manually rewriting @differentiable(jvp:vjp:) usages instead.

Deprecate `@differentiable` attribute `jvp:` and `vjp:` arguments for derivative
registration. `@derivative` attribute is the canonical way to register
derivatives.

Update tests.

TF-1001 tracks removing `@differentiable` attribute `jvp:` and `vjp:` arguments.
TF-1085 tracks removing `@differentiable(jvp:vjp:)` usages in the stdlib.
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Dec 23, 2019
@@ -1021,6 +1021,13 @@ bool Parser::parseDifferentiableAttributeArguments(
{ label });
result.Name = parseDeclNameRef(result.Loc, funcDiag,
DeclNameFlag::AllowZeroArgCompoundNames | DeclNameFlag::AllowOperators);
// Emit warning for deprecated `jvp:` and `vjp:` arguments.
// TODO(TF-1001): Remove deprecated `jvp:` and `vjp:` arguments.
if (result.Loc.isValid()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: result.Loc may not be valid if parseDeclNameRef produces an error.
This can happen when jvp:vjp: specifies a non-func declaration, e.g. an init or subscript.

@dan-zheng
Copy link
Collaborator Author

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Collaborator Author

There'll be stdlib compilation warnings until @differentiable(jvp:vjp:) usages are removed: TF-1085. Fuel for the fire!

@dan-zheng dan-zheng merged commit 2df5fc4 into apple:tensorflow Dec 23, 2019
@dan-zheng dan-zheng deleted the deprecate-differentiable-jvp-vjp branch December 23, 2019 03:30
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Jan 7, 2020
Upstream changes from `tensorflow` branch:

- apple#28932:
  deprecate `@differentiable(jvp:vjp)` arguments.

- apple#29038: gardening.

Additional gardening included.
dan-zheng added a commit that referenced this pull request Jan 8, 2020
Upstream changes from `tensorflow` branch:
- #28932: deprecate `@differentiable(jvp:vjp)` arguments.
- #29038: gardening.

Additional gardening included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants