Skip to content

[AutoDiff] [stdlib] Derive conformances for 'EuclideanDifferentiable'. #26867

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

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Aug 27, 2019

  • Add derived conformances for the EuclideanDifferentiable protocol introduced in Disable property wrapper composition. #26287 when a conforming type satisfies Differentiable conformance synthesis requirements.

    struct Foo<T>: EuclideanDifferentiable where T.TangentVector == T {
      var x: T
      var y: T
      @noDerivative var z: Bool
      // The compiler synthesizes the following `EuclideanDifferentiable` requirement:
      //   var vectorView: TangentVector {
      //     return TangentVector(x: x, y: y)
      //   }
    }
  • Remove vectorView's setter. This should not have been added to the protocol, for the same reason as TF-208. A projection (vectorView) of a subset of properties should reflect these properties joint mutability, which is impossible to express at the moment.

Resolves TF-777.

@rxwei rxwei added the tensorflow This is for "tensorflow" branch PRs. label Aug 27, 2019
@rxwei rxwei requested a review from dan-zheng August 27, 2019 08:29
* Add derived conformances for the `EuclideanDifferentiable` protocol introduced in swiftlang#26287 when a conforming type satisfies `Differentiable` conformance synthesis requirements.

    ```swift
    struct Foo<T>: EuclideanDifferentiable where T.TangentVector == T {
      var x: T
      var y: T
      @noDerivative var z: Bool
      // The compiler synthesizes the following `EuclideanDifferentiable` requirement:
      //   var vectorView: TangentVector {
      //     return TangentVector(x: x, y: y)
      //   }
    }
    ```

* Remove `vectorView`'s setter. This should not have been added to the protocol, for the same reason as [TF-208](https://bugs.swift.org/browse/TF-208). A projection (`vectorView`) of a subset of properties should reflect these properties joint mutability, which is impossible to express at the moment.

Resolves [TF-777](https://bugs.swift.org/browse/TF-777).
@rxwei rxwei force-pushed the euclidean-differentiable-derived branch from c541027 to f4cf3d9 Compare August 27, 2019 08:33
@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

3 similar comments
@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

1 similar comment
@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

Exposed TF-783, which is commented out here.

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

2 similar comments
@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Aug 27, 2019

@swift-ci please test tensorflow

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.

LGTM! Fixing TF-783 in a follow-up sounds reasonable to me, to unblock progress.

@dan-zheng dan-zheng merged commit fc4c701 into swiftlang:tensorflow Aug 27, 2019
rxwei added a commit to rxwei/swift-apis that referenced this pull request Aug 28, 2019
`EuclideanDifferentiable`, introduced in swiftlang/swift#26827 and swiftlang/swift#26867, provides a property, `differentiableVectorView`, to project the vector space component of a differentiable struct as a value of  `TangentVector` type. This allows us to express optimization techniques that require the parameter space to be a vector space, e.g. weight decay.

```swift
let 𝛁L: Model.TangentVector = ...
model.move(along: -η * 𝛁L - η * λ * model.vectorView))
```

Resolves tensorflow#456.
rxwei added a commit to tensorflow/swift-apis that referenced this pull request Aug 28, 2019
`EuclideanDifferentiable`, introduced in swiftlang/swift#26827 and swiftlang/swift#26867, provides a property, `differentiableVectorView`, to project the vector space component of a differentiable struct as a value of  `TangentVector` type. This allows us to express optimization techniques that require the parameter space to be a vector space, e.g. weight decay:
```swift
let 𝛁L: Model.TangentVector = ...
model.move(along: -η * 𝛁L - η * λ * model.differentiableVectorView))
```

This patch makes `Module` refine `EuclideanDifferentiable` and makes all layer combinators (e.g. `Sequential`, `RNN`) be `EuclideanDifferentiable`. All `Module`s and `Layers`s will now have property `differentiableVectorView`.

Resolves #456.
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.

2 participants