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

Support mutating functions #14

Open
mohamed82008 opened this issue Oct 4, 2021 · 4 comments
Open

Support mutating functions #14

mohamed82008 opened this issue Oct 4, 2021 · 4 comments
Labels
design Package structure and correctness

Comments

@mohamed82008
Copy link
Member

It was brought up on Slack that we may need to think about supporting a mutating API where buffers are stored in a more systematic abstract way. I am opening this issue to track the problem and discuss solutions.

@gdalle
Copy link
Member

gdalle commented May 24, 2023

Bumping this because at the moment it is the main performance limit for ImplicitDifferentiation.jl

@blegat
Copy link

blegat commented May 24, 2023

Maybe something like MutableArithmetics.operate_to!(::typeof(gradient), ::AbstractBackend, f, xs...)

@ChrisRackauckas
Copy link
Member

This also goes with the issue on pre-caching, #41, because if you use in-place but you aren't passing the shadow vectors or the config directly then you still don't get performance. This is the main reason why SciML hasn't been able to adopt AD.jl yet, even though SciMLSensitivity.jl would be a prime candidate it's just too much of a performance hit.

@mohamed82008
Copy link
Member Author

The problem is that most AD packages don't have any special support for mutation as far as I know. I think we need a few MWEs showcasing how mutation would work for each AD package and demonstrating the benefit of doing that. When working with AD, I am generally operating under the assumption that allocations are negligible compared to the cost of the AD. Most AD packages are not even type stable so they allocate a ton already when doing dynamic dispatch. Enzyme changed things a little and is the most greedy AD package in that it can really take advantage of mutation. ForwardDiff too if you know what you are doing and maybe ReverseDiff with a compiled tape. But I think we need a few examples showing the performance difference of pre-allocating a result vs allocating a new result every time.

@gdalle gdalle added performance Performance analysis or optimization design Package structure and correctness and removed performance Performance analysis or optimization labels Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Package structure and correctness
Projects
None yet
Development

No branches or pull requests

4 participants