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

Move the content of ad.jl from Turing.jl to here #571

Merged
merged 28 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/DynamicPPLReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function LogDensityProblemsAD.ADgradient(
ad::ADTypes.AutoReverseDiff, ℓ::DynamicPPL.LogDensityFunction
)
return LogDensityProblemsAD.ADgradient(
Val(:ReverseDiff), ℓ; compile=Val(ad.compile), x=DynamicPPL.getparams(ℓ)
Val(:ReverseDiff), ℓ; compile=Val(ad.compile), x=identity.(DynamicPPL.getparams(ℓ))
sunxd3 marked this conversation as resolved.
Show resolved Hide resolved
)
end

Expand Down
22 changes: 9 additions & 13 deletions test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
vns = DynamicPPL.TestUtils.varnames(m)
varinfos = DynamicPPL.TestUtils.setup_varinfos(m, rand_param_values, vns)

@testset "$varinfo" for varinfo in varinfos
@testset "$(short_varinfo_name(varinfo))" for varinfo in varinfos
f = DynamicPPL.LogDensityFunction(m, varinfo)

# use ForwardDiff result as reference
ad_forwarddiff_f = LogDensityProblemsAD.ADgradient(
ADTypes.AutoForwardDiff(; chunksize=0), f
)
θ = varinfo[:]
θ = identity.(varinfo[:])
sunxd3 marked this conversation as resolved.
Show resolved Hide resolved
logp, ref_grad = LogDensityProblems.logdensity_and_gradient(ad_forwarddiff_f, θ)

@testset "with ADType $adtype" for adtype in (
Expand All @@ -22,17 +22,13 @@
@test grad ≈ ref_grad
end

if m.f ∉ (
DynamicPPL.TestUtils.demo_dot_assume_dot_observe,
DynamicPPL.TestUtils.demo_assume_index_observe,
DynamicPPL.TestUtils.demo_dot_assume_observe_index,
DynamicPPL.TestUtils.demo_dot_assume_observe_index_literal,
DynamicPPL.TestUtils.demo_assume_submodel_observe_index_literal,
DynamicPPL.TestUtils.demo_dot_assume_observe_submodel,
DynamicPPL.TestUtils.demo_dot_assume_dot_observe_matrix,
DynamicPPL.TestUtils.demo_dot_assume_matrix_dot_observe_matrix,
DynamicPPL.TestUtils.demo_assume_matrix_dot_observe_matrix,
)
if m.f ∈ (
DynamicPPL.TestUtils.demo_assume_multivariate_observe,
DynamicPPL.TestUtils.demo_assume_dot_observe,
DynamicPPL.TestUtils.demo_assume_observe_literal,
DynamicPPL.TestUtils.demo_assume_literal_dot_observe,
) &&
varinfo isa Union{DynamicPPL.TypedVarInfo,DynamicPPL.SimpleVarInfo{<:NamedTuple}}
adtype = ADTypes.AutoZygote()
ad_f = LogDensityProblemsAD.ADgradient(adtype, f)
_, grad = LogDensityProblems.logdensity_and_gradient(ad_f, θ)
Expand Down
Loading