-
Notifications
You must be signed in to change notification settings - Fork 6
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
Issue with second derivative #26
Comments
what's the error? |
for zygote:
for FoD:
it seems the second differential bypasses the machinery of |
Do you think it requires to implement the second differential in the implicit theorem or the algo should recursively call the first differential? |
I've been asking myself the same question for a project of mine. The problem is, ChainRulesCore only supports specification of first derivatives, so I'm not sure how to go about it in a way that's easy to use. |
That's definitely worth investigating. Maybe we should define a rule on the pushforward / pullback? |
I add the link to the discourse post |
An example is here https://github.com/JuliaNonconvex/NonconvexUtils.jl/blob/main/src/custom.jl |
Changing this line https://github.com/gdalle/ImplicitDifferentiation.jl/blob/1581d2e3b1b1ddf083f0d370c9f7b323aa98f610/src/implicit_function.jl#L64 to y = implicit(x; kwargs...) and using a linear solver that's compatible with ForwardDiff makes the FD case work: linear_solver(A, x) = (Matrix(A) \ x, (solved = true,))
implicit = ImplicitFunction(dumb_identity, zero_gradient, linear_solver); Zygote still fails but I suspect that's because |
Seems easy enough to fix in the source code, should we? |
Let's |
Random thought: the fact that we need a dual-compatible linear solver means we still autodiff through the iterations of the solver. Is it possible to avoid that altogether for second-order? |
In theory we could. That would require defining the linear solver as an implicit function and using ForwardDiffChainRules on that. We would need to think of a good way to make this work for direct and iterative linear solvers. |
Do you know if the Python package has higher order implicit derivates? If not, this could be an interesting conference paper. |
No it only focuses on first-order differentiation. But it outsources the actual autodiff to JAX, which may be better at second-order stuff than Zygote for example. |
My thought was actually to differentiate the implicit function theorem a second time, like this. |
I believe what the derivations in this link are doing is going to be computationally identical to making our linear solver an implicit function and letting ImplicitDifferentiation automate the rest for us. They just defined the higher order rule manually but then it gets ugly with multiple inputs and outputs, Hessian rules for functions, etc. We have a nice abstraction which can be nested, let's take advantage of that. |
I believe you're right. Although I think the SciML solvers from https://github.com/SciML/LinearSolve.jl are already differentiable with a similar implicit machinery, it can't hurt to roll out our own simpler version |
I recall you tried LinearSolve before but didn't end up using it because it was still not mature enough. Maybe we can revisit it or roll our own, shouldn't be too hard for simple solvers. |
I don't think we need that many solvers so direct and GMRES should be enough. |
It should definitely be more mature now but my main beef is that it has a truckload of dependencies, which cannot be made conditional until Julia 1.9 https://github.com/SciML/LinearSolve.jl/blob/main/Project.toml |
Now (in |
See #77 |
Closing in favor of #77 |
Hi,
I have been trying to use ImplicitDifferentiation.jl for higher order jvp but I was not lucky.
Basic example:
I also have this code with ForwardDiff. Not sure the problem is the same
The text was updated successfully, but these errors were encountered: