-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Remove 'differentiableFunction(from:)' and 'linearFunction(from:)' #35366
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 'differentiableFunction(from:)' and 'linearFunction(from:)' #35366
Conversation
@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.
LGTM! I'm not familiar with existing use cases or reasons not to remove - my memory is that you added them as a cute idea.
Build failed |
Build failed |
…(from:)'. Remove unused APIs `differentiableFunction(from:)` and `linearFunction(from:)`. They were never official APIs, are not included in the [initial proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md#make-a-function-differentiable-using-derivative), and are unused by existing supported client libraries (SwiftFusion and S4TF). Most importantly, they block crucial optimizations on linear map closures (swiftlang#34935) and would need nontrivial work in SILGen to support.
ee21618
to
f79391b
Compare
@swift-ci please test |
@rxwei @dan-zheng I was making use of |
Would something like this do it? @differentiable
func makeRecomputedInGradient<T: Differentiable, U: Differentiable>(
_ original: @escaping @differentiable(T) -> U
) -> @differentiable(T) -> U {
var gradientHolder: U.TangentVector? = nil
@differentiable
func newFunc(_ t: T) -> U {
var t = t
t = t.withDerivative { $0 = pullback(at: t, in: original)(gradientHolder!) }
var result = withoutDerivative(at: original(t))
result = result.withDerivative{ gradientHolder = $0 }
return result
}
return newFunc
} Huh. That crashes the compiler... |
func _original<T, R>(_ x: T, _ f: @differentiable (T) -> R) -> R {
f(x)
}
@derivative(of: _original, wrt: x)
func _vjp<T, R>(
_ x: T, _ f: @differentiable (T) -> R
) -> (value: R, pullback: (R.TangentVector) -> T.TangentVector) {
(value: f(x), pullback: pullback(at: x, in: f))
}
func makeRecomputed<T, R>(
_ f: @escaping @differentiable (T) -> R
) -> @differentiable (T) -> R {
{ x in _original(x, f) }
} |
Thanks Richard! |
Remove unused APIs
differentiableFunction(from:)
andlinearFunction(from:)
. They were never official APIs, are not included in the initial proposal, and are unused by existing supported client libraries (SwiftFusion and S4TF). Most importantly, they block crucial optimizations on linear map closures (#34935) and would need nontrivial work in SILGen to support.