Skip to content
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

Type instabilities? #36

Closed
gdalle opened this issue Apr 13, 2023 · 11 comments · Fixed by #52
Closed

Type instabilities? #36

gdalle opened this issue Apr 13, 2023 · 11 comments · Fixed by #52
Labels
bug Something isn't working

Comments

@gdalle
Copy link
Member

gdalle commented Apr 13, 2023

See this Discourse thread: https://discourse.julialang.org/t/custom-rule-for-differentiating-through-newton-solver-using-forwarddiff-works-for-gradient-fails-for-hessian/93002/20

@thorek1
Copy link
Contributor

thorek1 commented May 9, 2023

I think I encountered something related. the ForwardDiff extension flattens arrays to a vector on output (line 42 in ImplicitDifferentiationForwardDiffExt.jl) having the dimensions preserved should fix it in my case at least

@gdalle
Copy link
Member Author

gdalle commented May 10, 2023

Unfortunately this seems required for the linear solvers to work: Krylov.jl doesn't work with arbitrary arrays. I tried to use KrylovKit.jl instead a while back and it ended up being type-unstable for different reasons, but I'm willing to try again

@gdalle
Copy link
Member Author

gdalle commented May 10, 2023

Note that the type stability tests which used to be performed by ChainRules were removed temporarily because I bumped into JuliaDiff/ChainRulesTestUtils.jl#232

@thorek1
Copy link
Contributor

thorek1 commented May 10, 2023

I see, but can't you just reshape after the solve?

@gdalle
Copy link
Member Author

gdalle commented May 10, 2023

@gdalle gdalle added the bug Something isn't working label May 23, 2023
@gdalle
Copy link
Member Author

gdalle commented May 24, 2023

@thorek1 I think your issue might have been solved by @YingboMa in #41

@gdalle
Copy link
Member Author

gdalle commented May 24, 2023

And the issue from the Discourse thread will be taken care of by #47

@thorek1
Copy link
Contributor

thorek1 commented May 24, 2023

Thanks, I will have a look and let you know.

@thorek1
Copy link
Contributor

thorek1 commented May 24, 2023

it didn't resolve my issue. the MWE is a bit involved (the error occurs at line 94). maybe a high level hint: Zygote works, ForwardDiff doesn't. ForwardDiff breaks when I try to use the result returned from implicit diff in computations because the dimension info is lost and he returns a vector instead of a matrix. the function I try to diff has 1 arg and 2 kwargs and returns a matrix and a bool. the conditions accepts three args, the same kwargs and returns a matrix of the same dimension as the first output form the forward function. in principle it should work and it does for Zygote

@gdalle
Copy link
Member Author

gdalle commented May 24, 2023

OK I think I know where this is coming from.

@gdalle gdalle linked a pull request May 24, 2023 that will close this issue
@gdalle gdalle closed this as completed May 24, 2023
@thorek1
Copy link
Contributor

thorek1 commented May 24, 2023

That fixed it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants