-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ZygoteRules and ChainRulesCore weak dependencies (#564)
* Make ZygoteRules and ChainRulesCore weak dependencies * Fix format * Add another non-differentiable to CRC extension * Perform coverage analysis on all Julia versions
- Loading branch information
Showing
7 changed files
with
70 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module DynamicPPLChainRulesCoreExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using DynamicPPL: DynamicPPL, BangBang, Distributions | ||
using ChainRulesCore: ChainRulesCore | ||
else | ||
using ..DynamicPPL: DynamicPPL, BangBang, Distributions | ||
using ..ChainRulesCore: ChainRulesCore | ||
end | ||
|
||
# See https://github.com/TuringLang/Turing.jl/issues/1199 | ||
ChainRulesCore.@non_differentiable BangBang.push!!( | ||
vi::DynamicPPL.VarInfo, | ||
vn::DynamicPPL.VarName, | ||
r, | ||
dist::Distributions.Distribution, | ||
gidset::Set{DynamicPPL.Selector}, | ||
) | ||
|
||
ChainRulesCore.@non_differentiable DynamicPPL.updategid!( | ||
vi::DynamicPPL.AbstractVarInfo, vn::DynamicPPL.VarName, spl::DynamicPPL.Sampler | ||
) | ||
|
||
# No need + causes issues for some AD backends, e.g. Zygote. | ||
ChainRulesCore.@non_differentiable DynamicPPL.infer_nested_eltype(x) | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module DynamicPPLZygoteRulesExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using DynamicPPL: DynamicPPL, Distributions | ||
using ZygoteRules: ZygoteRules | ||
else | ||
using ..DynamicPPL: DynamicPPL, Distributions | ||
using ..ZygoteRules: ZygoteRules | ||
end | ||
|
||
# https://github.com/TuringLang/Turing.jl/issues/1595 | ||
ZygoteRules.@adjoint function DynamicPPL.dot_observe( | ||
spl::Union{DynamicPPL.SampleFromPrior,DynamicPPL.SampleFromUniform}, | ||
dists::AbstractArray{<:Distributions.Distribution}, | ||
value::AbstractArray, | ||
vi, | ||
) | ||
function dot_observe_fallback(spl, dists, value, vi) | ||
DynamicPPL.increment_num_produce!(vi) | ||
return sum(map(Distributions.loglikelihood, dists, value)), vi | ||
end | ||
return ZygoteRules.pullback(__context__, dot_observe_fallback, spl, dists, value, vi) | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fc6cae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
fc6cae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/95723
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: