-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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] Remove '_Differentiable.zeroTangentVectorInitializer'. #35329
Conversation
@swift-ci please test |
Remove `_Differentiable.zeroTangentVectorInitializer` to address the feedback on the [proposal thread](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147). The corresponding change has already been made in the [proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md). Removed components: - `zeroTangentVectorInitializer` and `zeroTangentVector` in `Differentiable`, `Array`, `Optional`, `Float`, `Double`, and `Float80`. - `zeroTangentVectorInitializer` synthesis logic in `Differentiable` derived conformances.
a2627ce
to
c8a6f01
Compare
@swift-ci please test |
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 simplification!
Regarding API removal: I think there exists usages of Differentiable.zeroTangentVectorInitializer
or Differentiable.zeroTangentVector
computed property in projects using differentiable programming like tensorflow/swift-models
and SwiftFusion. I believe the usages can be fixed, so proceeding with removal sounds good.
The existing usage seems very light and can be fixed by adding a declaration of Existing occurrences of ➜ SwiftFusion git:(main) grep -nrwi "zeroTangentVectorInitializer" .
./Sources/SwiftFusion/Core/Tuple+Vector.swift:46: public var zeroTangentVectorInitializer: () -> TangentVector {
./Sources/SwiftFusion/Core/Tuple+Vector.swift:58: public var zeroTangentVectorInitializer: () -> TangentVector {
./Sources/SwiftFusion/Core/Dictionary+Differentiable.swift:19: public var zeroTangentVectorInitializer: () -> TangentVector {
./Sources/SwiftFusion/Inference/ArrayBuffer+Differentiable.swift:33: public var zeroTangentVectorInitializer: () -> TangentVector {
./Sources/SwiftFusion/Inference/ArrayBuffer+Differentiable.swift:39: // DWA TODO: replace this with the use of zeroTangentVectorInitializer
./Sources/SwiftFusion/Inference/AnyArrayBuffer+Differentiable.swift:25: public var zeroTangentVectorInitializer: () -> TangentVector {
➜ swift-apis git:(main) grep -nrwi "zeroTangentVectorInitializer" .
./Sources/TensorFlow/Core/Tensor.swift:708: public var zeroTangentVectorInitializer: () -> TangentVector {
➜ swift-models git:(main) grep -nrwi "zeroTangentVectorInitializer" .
./Models/Text/WordSeg/Model.swift:343: // (`Differentiable.zeroTangentVectorInitializer`) instead of static zeros
➜ SwiftFusion git:(main) grep -nrwi "zeroTangentVector" .
./Tests/SwiftFusionTests/Core/Dictionary+DifferentiableTests.swift:72: /// Test the `Differentiable` `zeroTangentVector` requirement.
./Tests/SwiftFusionTests/Core/Dictionary+DifferentiableTests.swift:75: ([:] as [String: Double]).zeroTangentVector,
./Tests/SwiftFusionTests/Core/Dictionary+DifferentiableTests.swift:79: (["a": 1] as [String: Double]).zeroTangentVector,
./Tests/SwiftFusionTests/Geometry/PinholeCameraTests.swift:82: calibration: K.zeroTangentVector),
./Tests/SwiftFusionTests/Geometry/PinholeCameraTests.swift:87: calibration: K.zeroTangentVector),
./Sources/SwiftFusion/Core/LieGroup.swift:170: return pullback(at: v.zeroTangentVector, in: { self.Adjoint($0) })(v)
./Sources/SwiftFusion/Core/Tuple+Vector.swift:59: { .init(head: head.zeroTangentVector, tail: tail.zeroTangentVector) }
./Sources/SwiftFusion/Core/Dictionary+Differentiable.swift:20: { mapValues { v in v.zeroTangentVector } }
./Sources/SwiftFusion/Core/Manifold.swift:103: pullback(at: zeroTangentVector) { self.coordinateStorage.retract($0) }
./Sources/SwiftFusion/Image/Patch.swift:50: var dBox = region.zeroTangentVector
./Sources/SwiftFusion/Inference/ArrayBuffer+Differentiable.swift:43: .init(vs.lazy.map { $0.zeroTangentVector })
./Sources/SwiftFusion/Inference/AnyArrayBuffer+Vector.swift:107: (lhs - rhs, { x in (x, x.zeroTangentVector - x) })
./Sources/SwiftFusion/Inference/AnyArrayBuffer+Vector.swift:125: return ((), { x in x.zeroTangentVector - x })
./Sources/SwiftFusion/Inference/ArrayBuffer+Tensor.swift:139: (lhs - rhs, { x in (x, x.zeroTangentVector - x) })
./Sources/SwiftFusion/Inference/ArrayBuffer+Tensor.swift:179: return ((), { x in x.zeroTangentVector - x })
./Sources/SwiftFusion/Geometry/PinholeCamera.swift:81: TangentVector(wTc: dpose, calibration: calibration.zeroTangentVector),
➜ swift-apis git:(main) grep -nrwi "zeroTangentVector" .
./Tests/TensorFlowTests/TensorTests.swift:126: XCTAssertEqual(tensor.zeroTangentVector, Tensor(zeros: shape))
./Tests/TensorFlowTests/TensorTests.swift:132: XCTAssertEqual(model.zeroTangentVector, .init(tensor: Tensor(zeros: shape)))
➜ swift-models git:(main) grep -nrwi "zeroTangentVector" .
./Tests/SupportTests/AnyLayerTests.swift:128: // XCTAssertEqual(erased.zeroTangentVector, AnyLayerTangentVector(original.zeroTangentVector))
./Tests/SupportTests/AnyLayerTests.swift:129: // XCTAssertEqual(AnyLayerTangentVector(original.zeroTangentVector), erased.zeroTangentVector)
./Models/Text/WordSeg/Lattice.swift:167: let elementZero = positions[index].zeroTangentVector |
Thanks a lot for investigating!
I wonder if this is actually doable?
I think in the most general/inconvenient case, we can define a protocol refining Do you have any thoughts? |
What are the problems you are trying to solve? Is it really the right thing to keep the "elementwise per-instance zero" semantics in your libraries given that the AD transform has never supported |
I'm not sure, since I haven't looked into specific use sites of |
Hmm it's not really about "avoiding the 'elementwise per-instance zero' semantics" -- the semantics was never there in the first place because AD is only using |
That makes sense. Maybe we're talking past each other a bit: I think use cases of |
@marcrasi Let me know when you are ready for me to merge this. |
@rxwei We'll look across Swift for TensorFlow repositories and users to check whether removing |
Sounds good. Thank you. |
@dan-zheng Any update on this? I am hoping to merge this soon in order to get the implementation closer to the proposal. |
I'll look into it today, thanks. Here's the tracking issue: borglab/SwiftFusion#261. I think no one working on SwiftFusion has had a chance to investigate yet. Edit: @acoadmarmon volunteered to look into updating SwiftFusion tomorrow, hope that's okay! |
Any update on this? |
@rxwei Thanks for your patience and your ample announcement & exploration of this API removal! I think it would be fine to merge this PR anytime, users who are broken can keep using their older development snapshot toolchains. I'll communicate to the autodiff users that I'm in touch with (SwiftFusion folks) to follow the differentiable programming pitch thread more closely, so they can be responsible for handling potential API changes in the future. @acoadmarmon @ProfFan @dellaert Thanks all! 😄 |
Thanks for confirming. Let me know if you have any additional issues in the migration. |
Remove
_Differentiable.zeroTangentVectorInitializer
to address the feedback on the proposal thread. The corresponding change has already been made in the proposal.Removed components:
zeroTangentVectorInitializer
andzeroTangentVector
inDifferentiable
,Array
,Optional
,Float
,Double
,Float80
, and SIMD types.zeroTangentVectorInitializer
synthesis logic inDifferentiable
derived conformances.