-
Notifications
You must be signed in to change notification settings - Fork 18
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
Expectations for implementations of the interface #13
Comments
I prefer 1 because it's simple and it works. But yes if 2 is faster, then by all means, define methods to your heart's content. |
While working on PRs such as #93 and #95 I started to dislike the Instead of the macro which might result in a sub-optimal implementation of |
The macro is a feature but it is not compulsory. We should document how to define the interface without the macro though. |
Sure but if such helper functions would exist, I don't think there's a completely convincing argument for keeping the macro anymore since arguably derivative(...) = ...
gradient(...) = gradient_via_pullback_function(...)
function pullback_function(...)
...
end
function jacobian(...)
return jacobian_via_pullback_function(...)
end is clearer than derivative(...) = ...
gradient(...) = pullback_function(...)(1)
@primitive function pullback_function(...)
...
end and not significantly less concise. To summarize, I think such utilities are clearer and more powerful than a macro. |
Some of the existing functionality of the macro is a bit useless anyway: #95 (And even less general than just defining the respective functions since the macro eg. does not support arguments without name) |
I think both can co-exist for now. Then we can deprecate the macro if it's not needed anymore. Although it's a shame because I like the idea of defining one primitive in a macro from which all AD functionality comes to life. |
I think the macro obscures the package code quite a bit, and would be in favor of removing it. At least that way the expectations on AD backends would be clear, with no hidden performance footguns |
I feel like AbstractDifferentiation.jl won't get widespread adoption if there are substantial differences in performance compared to using individual backends directly.
@gdalle suggested to me that AbstractDifferentiation could just define an empty interface. Individual AD backends could then define package extensions on AbstractDifferentiation (or add it as a light-weight dependency). The current approach of having all package extensions in AbstractDifferentiation surprised me, as it must put a lot of burden on the maintainers of AbstractDifferentiation to keep up with changes in a growing amount of backends. |
Many performance issues have been fixed, e.g. #97, but if there are more problems, feel free to open an issue or PR.
AFAIK the idea was from the start that these concrete implementations should live in the respective AD packages. But they wanted to add code for an interface that is still in flux and not used (much) in the ecosystem, hence currently the extensions are part of AbstractDifferentations. |
I think this issue is largely fixed now. Currently, Currently, one can simply define a pullback or pushforward as a function and make the backed type a subtype of I am closing this issue now, but please open it again or open another one if you think an action needs to be taken. |
Is it expected that all packages that implement the interface use
AD.@primitive
? e.g., ForwardDiff can use DiffResults to enable returning a value and a gradient and/or hessian. In cases like this, what is advised?I can see a few possibilities:
@primitive pushforward_function(...)
only to keep things simple@primitive pushforward_function(...)
but then overload methods likevalue_and_gradient
for which the AD package has a more efficient approach.Edit: I'm guessing (2) is the preferred option? For many (most? all?) AD engines, the fallback to working in terms of jacobians will be much less efficient than overloading the corresponding methods.
The text was updated successfully, but these errors were encountered: