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

Use Base.Fix1 instead of _logdensity_closure #86

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

devmotion
Copy link
Collaborator

@devmotion devmotion commented Aug 17, 2022

The motivation for this PR is that I don't know how to allow custom ForwardDiff tags with ForwardDiff.checktag (such as in https://github.com/TuringLang/Turing.jl/blob/c0c8bc2af0fa32621ded96afcd3ba1cfabd686aa/src/Turing.jl#L45) with the current _logdensity_closure setup as I don't know how to get the supertype of the result of _logdensity_closure(::MyParameterizedStruct) without evaluating _logdensity_closure. With Base.Fix1, however, I can easily define ForwardDiff.checktag(::Type{MyTag{V}}, ::Base.Fix1{typeof(logdensity),<:MyParameterizedStruct}, ::AbstractVector{V}) and thereby limit the custom tags to the intended use case.

An additional "fix" in this PR: Currently the Zygote backend uses _logdensity_closure as well which is only defined in the optionally loaded ForwardDiff backend. That works because Zygote depends on and loads ForwardDiff but probably it is safer to not having to rely on such internals.

Copy link
Owner

@tpapp tpapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@tpapp tpapp merged commit 0d9f976 into tpapp:master Aug 19, 2022
@devmotion devmotion deleted the dw/base_fix1 branch August 19, 2022 14:03
@devmotion
Copy link
Collaborator Author

Thanks! Could you tag a new release such that I can use the changes in the Turing PR?

tpapp added a commit that referenced this pull request Aug 19, 2022
@tpapp
Copy link
Owner

tpapp commented Aug 19, 2022

Sure, cf JuliaRegistries/General#66559 . Made it a minor version bump, technically it is not exposed API but should make dependency management easier.

@devmotion
Copy link
Collaborator Author

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants