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

README example #256

Closed
willtebbutt opened this issue May 13, 2024 · 6 comments · Fixed by #266
Closed

README example #256

willtebbutt opened this issue May 13, 2024 · 6 comments · Fixed by #266
Labels
documentation Improvements or additions to documentation

Comments

@willtebbutt
Copy link
Member

At present the main example in the README is:

using DifferentiationInterface
import ForwardDiff, Enzyme, Zygote  # AD backends you want to use 

f(x) = sum(abs2, x)

x = [1.0, 2.0]

value_and_gradient(f, AutoForwardDiff(), x) # returns (5.0, [2.0, 4.0]) with ForwardDiff.jl
value_and_gradient(f, AutoEnzyme(),      x) # returns (5.0, [2.0, 4.0]) with Enzyme.jl
value_and_gradient(f, AutoZygote(),      x) # returns (5.0, [2.0, 4.0]) with Zygote.jl

Would it be better to make this example one which includes the extras = prepare_gradient(f, backend, x) etc stuff?

I'm just thinking about the issue we had on Tapir.jl the other day, where a user didn't realise that you should really be using prepare_gradient in general. My general point is: if a user sees one example, maybe they should see one which we think is likely to give best performance across all backends?

@gdalle
Copy link
Member

gdalle commented May 13, 2024

Good point. Then again many people use ForwardDiff without even knowing about config and chunks, and it's still decently fast. Preparation features prominently in the tutorial and overview pages of the docs, so I am torn as to whether it belongs in the README. @adrhill thoughts?

@adrhill
Copy link
Collaborator

adrhill commented May 13, 2024

The point of the current README is to demonstrate to the average, time-deprived developer that DI is an easy to use, unified interface for Julia's many AD backends. I personally wouldn't want to complicate this example too much.

We follow it up by the disclaimer "For more performance, take a look at the DifferentiationInterface tutorial", which implies sub-optimal performance in the code example. I guess we could further emphasize this disclaimer and possibly add a short second code block demonstrating preparation?

maybe [users] should see one [example] which we think is likely to give best performance across all backends?

PR #255 introduces additional preparation functions for static points of linearization, so the optimal operator preparation is about to be problem dependent.

@adrhill
Copy link
Collaborator

adrhill commented May 13, 2024

I guess we could further emphasize this disclaimer and possibly add a short second code block demonstrating preparation?

I should stress that my preferred approach would be to direct users to the documentation, which they should definitely read.
Maybe something like this could be the solution?

To improve your performance by up to an order of magnitude compared to this example, take a look at the DifferentiationInterface tutorial.

@willtebbutt
Copy link
Member Author

I should stress that my preferred approach would be to direct users to the documentation, which they should definitely read. Maybe something like this could be the solution?

I really like this. Perhaps you could strengthen then statement even more though? In the case of Tapir, not preparing can yield many orders of magnitude worse performance.

@gdalle gdalle added the documentation Improvements or additions to documentation label May 14, 2024
@gdalle
Copy link
Member

gdalle commented May 14, 2024

By the way I also really liked it when the README was tested @adrhill, we could reintroduce that as well

@willtebbutt
Copy link
Member Author

For the record -- I think basically any of the solutions proposed here are great, so I will not be offended if you close this issue without further consulting me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants