-
Notifications
You must be signed in to change notification settings - Fork 146
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
Automatic ChainRules compatibility #579
Comments
+1 Is avoiding dependency on ChainRulesCore/ChainRules the issue preventing this? |
For future reference, @mohamed82008 is on the move again: JuliaNonconvex/NonconvexUtils.jl#6 |
One way to make this fully automatic would be to move the most basic definitions of This may not be very difficult to do, although I haven't tried. I don't know how other people feel about entangling these two packages. This one has slowly acquired quite a few dependencies (including CRC, indirectly); adding CRC directly may in fact make it lighter-weight, as those packages could (and probably already all do) define rules themselves using CRC. |
I am not keen on that particular solution. In general i want |
The solution from @mohamed82008 is a working macro now, and it is as easy as typing:
So you have ForwardDiff-dispatches for scalars, vectors and matrices for your function In my opinion this should definitely be added to ForwardDiff, would be a really nice thing. |
My implementation even works for structs if you pass in the constructor, see the tests. Struct support needs more infrastructure though compared to the simple vec/reshape needed for vector/matrix support. Even if the macro does not live in ForwardDiff, I would be happy if someone took it and put it in a separate light package and added a section in the ForwardDiff documentation pointing to the new package. |
I mentioned to @gdalle before, every feature of NonconvexUtils should probably be its own package :) |
I can seperate the function and put it in a dedicated package if you wish. Are there any suggestions for names? |
ForwardDiffChainRules? |
Ok, mini-package is coming. I will post it here! |
Find the repo here: ForwardDiffChainRules.jl I tried to keep it light-weight, e.g. the SparseArrays- and JuMP-dispatches are only added if the corresponding libraries are (with Requires.jl). The rest is basically copy-paste (with author attribution). CI-Test currently fails (I will check this soon or maybe @mohamed82008 has a clue). As soon this is fixed and @mohamed82008 gives his OK, I can register the version. Regards! |
I can take a look in a few days. Sorry, a bit busy the coming couple of days. |
@ThummeTo can I get an invite to the repo? I fixed it locally and used https://github.com/JuliaNonconvex/DifferentiableFlatten.jl. I can open a PR or push directly to master. |
Of course, you should have an invitation now. Much appreciated! |
So it's ready for a first release I guess @mohamed82008 ? |
Yes |
Since we have a sufficiently lightweight package that implements this feature now, should we close this issue @gdalle? |
Can we document this in the docs here (and also ChainRulesCore.jl) |
Let's close it once this is referenced in the FD and CRC docs? |
Both links were added, closing this |
In a recent Slack discussion, @mohamed82008 posted this useful code snippet that shouldn't go to waste.
With a little bit of work, this could be turned into a macro that automatically translates a
ChainRulesCore.frule
into itsForwardDiff.Dual
-compatible counterpart.Since ChainRulesCore is a very light dependency, would it make sense to include such a thing to ForwardDiff? Judging by the reactions on the Slack #autodiff channel, lots of people would find it useful.
The text was updated successfully, but these errors were encountered: