Skip to content

[AutoDiff] Add builtin differentiable/linear function consturctors. #28467

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

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Nov 24, 2019

Add builtin functions that construct a @differentiable or @differentiable(linear) function from component functons.

  • Builtin.differentiableFunction_*

    Takes an original function, a JVP function and a VJP function and returns a @differentiable function.

    Pseudo-declaration:

    func differentiableFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>(
        _ original: __owned @escaping (T...{arity}) {throws}? -> U,
        _ jvp: __owned @escaping (T...{arity}) {throws}? -> (value: U, differential: (T.TangentVector...{arity}) -> U.TangentVector),
        _ vjp: __owned @escaping (T...{arity}) {throws}? -> (value: U, pullback: (U.TangentVector) -> (T.TangentVector...{arity}))
    ) -> @differentiable (T...{arity}) {throws}? -> U
        where T...{arity} : Differentiable, U : Differentiable
  • Builtin.linearFunction_*

    Takes an original function and a transpose function and returns a @differentiable function.

    Pseudo-declaration:

    func linearFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>(
        _ original: __owned @escaping (T...{arity}) {throws}? -> U,
        _ transpose: __owned @escaping (U.TangentVector) {throws}? -> (T.TangentVector...{arity})
    ) -> @differentiable (T...{arity}) {throws}? -> U
        where T...{arity} : Differentiable & AdditiveArithmetic, U : Differentiable & AdditiveArithmetic

These builtins will be used to write unit tests for @differentiable and @differentiable(linear) function types that do not necessarily depend on the differentiation transform.

TODO:

  • SR-11848: For robustness, we need SIL FileCheck tests for all AD builtins. These have not been added for Builtin.autodiffApply*, so I'm leaving this as a future task.
  • SR-11847: Update differentiableFunction(from:) to use Builtin.differentiableFunction* in its implementation.
  • SR-11849: Disallow non-top-level derivative registration.

Resolves SR-11846.

Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Nice!

@rxwei
Copy link
Contributor Author

rxwei commented Nov 24, 2019

@swift-ci please test tensorflow

…ntiable(linear)` function from component functons.

* `Builtin.differentiableFunction_*`

  Takes an original function, a JVP function and a VJP function and returns a `@differentiable` function.

  Pseudo-declaration:
  ```swift
  func differentiableFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>(
      _ original: __owned @escaping (T...{arity}) {throws}? -> U,
      _ jvp: __owned @escaping (T...{arity}) {throws}? -> (value: U, differential: (T.TangentVector...{arity}) -> U.TangentVector),
      _ vjp: __owned @escaping (T...{arity}) {throws}? -> (value: U, pullback: (U.TangentVector) -> (T.TangentVector...{arity}))
  ) -> @differentiable (T...{arity}) {throws}? -> U
      where T...{arity} : Differentiable, U : Differentiable
  ```

* `Builtin.linearFunction_*`

  Takes an original function and a transpose function and returns a `@differentiable` function.

  Pseudo-declaration:
  ```swift
  func linearFunction_arity{arity}[_throws]?{throws}<T...{arity}, U>(
      _ original: __owned @escaping (T...{arity}) {throws}? -> U,
      _ transpose: __owned @escaping (U.TangentVector) {throws}? -> (T.TangentVector...{arity})
  ) -> @differentiable (T...{arity}) {throws}? -> U
      where T...{arity} : Differentiable & AdditiveArithmetic, U : Differentiable & AdditiveArithmetic
  ```

These builtins will be used to write unit tests for `@differentiable` and `@differentiable(linear)` function types that do not necessarily depend on the differentiation transform.

TODO:
- SR-11848: For robustness, we need SIL FileCheck tests for all AD builtins. These have not been added for `Builtin.autodiffApply*`, so I'm leaving this as a future task.
- SR-11847: Update `differentiableFunction(from:)` to use `Builtin.differentiableFunction*` in its implementation.
- SR-11849: Disallow non-top-level derivative registration.

Resolves SR-11846.
@rxwei
Copy link
Contributor Author

rxwei commented Nov 25, 2019

@swift-ci please test tensorflow

2 similar comments
@rxwei
Copy link
Contributor Author

rxwei commented Nov 25, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Nov 25, 2019

@swift-ci please test tensorflow

@rxwei rxwei merged commit e0789da into swiftlang:tensorflow Nov 25, 2019
rxwei added a commit to rxwei/swift that referenced this pull request Nov 25, 2019
…le function constructor builtins.

This PR updates `differentiableFunction(from:)` to use differentiable function constructor builtins added in swiftlang#28467. The standard library no longer has non-top-level derivative registration.

Resolves SR-11847. Unblocks SR-11849.
rxwei added a commit that referenced this pull request Nov 25, 2019
…le function constructor builtins. (#28470)

This PR updates `differentiableFunction(from:)` to use differentiable function constructor builtins added in #28467. The standard library no longer has non-top-level derivative registration.

Resolves SR-11847. Unblocks SR-11849.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants