Got a fatal error saying "JVP does not exist. Differential-first differentiation APIs are experimental and should not be used."

Viewed 117

I installed the TensorFlow toolchain in Xcode and tried running an example snippet from the S4TF GitHub page. I got the following error:

JVP does not exist. Differential-first differentiation APIs are experimental and should not be used.

I then tried doing the same on Google Colab and got the same error. Here's the snippet of code I'm trying to run:

@differentiable
func f(_ x: Float) -> Float {
    x * x
}
let dfdx = derivative(of: f)
dfdx(3) // 6

I understand that this is my first time running S4TF and I'm not aware of many things, so it might turn out to be a stupid mistake on my part :)

1 Answers

You're seeing that error because you're attempting to take a forward-mode derivative, and support for that hasn't yet been implemented in the Swift automatic differentiation system. The current implementation supports reverse-mode differentiation, so you can use the gradient operator instead to obtain the result you want:

@differentiable
func f(_ x: Float) -> Float {
    x * x
}
let dfdx = gradient(of: f)
dfdx(3) // 6

Forward-mode differentiation support is in the works, but the focus is presently on upstreaming the reverse-mode implementation and refining that first. As a disclaimer, I work on the Swift for TensorFlow team.

Related