-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
[AutoDiff] [stdlib] Derive conformances for 'EuclideanDifferentiable'. #26867
Conversation
* 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).
c541027
to
f4cf3d9
Compare
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
3 similar comments
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
…fferentiable-derived
…e.swift since the difference it has from derived_differentiable.swift is that it's a runtime test suite.
@swift-ci please test tensorflow |
1 similar comment
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
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.
LGTM! Fixing TF-783 in a follow-up sounds reasonable to me, to unblock progress.
`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.
`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.
Add derived conformances for the
EuclideanDifferentiable
protocol introduced in Disable property wrapper composition. #26287 when a conforming type satisfiesDifferentiable
conformance synthesis requirements.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.