-
Notifications
You must be signed in to change notification settings - Fork 228
Remove AD backend loops in test suite #2564
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d8f6dfa
Remove AD backend loops
penelopeysm df85c6f
Add AD tests to sghmc.jl
penelopeysm 7369221
Remove AD loops from HMC and SGHMC
penelopeysm 62d414f
Handle Inference.jl
penelopeysm a4387a8
Remove AD loop in Gibbs
penelopeysm fd2359c
Fix broken test
penelopeysm f257f15
Mark testsets as verbose=true
penelopeysm 0975a91
Merge remote-tracking branch 'origin/main' into py/no-repeated-adtype
penelopeysm be08026
Separate AD tests into their own file
penelopeysm 0d2955f
Finish AD tests
penelopeysm 986d016
Merge remote-tracking branch 'origin/main' into py/no-repeated-adtype
penelopeysm 5d654c7
No I did not mean to comment out all other tests
penelopeysm f59a89c
Move ADTypeCheckContexts and optimisation tests to ad.jl as well
penelopeysm 0c8b28f
Remove stray test_utils file
penelopeysm 4210f12
Remove has_dot_assume check
penelopeysm e86938e
Remove TODO comment about Mooncake
penelopeysm 2b2f352
Test Gibbs sampling
penelopeysm 5e7ed7d
Fix test
penelopeysm c0be80c
Remove unnecessary DEFAULT_ADTYPEs
penelopeysm 3a43ef7
One more
penelopeysm f1263bf
Merge branch 'main' into py/no-repeated-adtype
penelopeysm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -7,7 +7,6 @@ using ..NumericalTests: | |
check_gdemo, | ||
check_numerical, | ||
two_sample_test | ||
import ..ADUtils | ||
import Combinatorics | ||
using AbstractMCMC: AbstractMCMC | ||
using Distributions: InverseGamma, Normal | ||
|
@@ -34,19 +33,7 @@ function check_transition_varnames(transition::Turing.Inference.Transition, pare | |
end | ||
end | ||
|
||
const DEMO_MODELS_WITHOUT_DOT_ASSUME = Union{ | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_index_observe)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_multivariate_observe)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_dot_observe)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_multivariate_observe_literal)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_observe_literal)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_dot_observe_literal)}, | ||
DynamicPPL.Model{typeof(DynamicPPL.TestUtils.demo_assume_matrix_observe_matrix_index)}, | ||
} | ||
has_dot_assume(::DEMO_MODELS_WITHOUT_DOT_ASSUME) = false | ||
has_dot_assume(::DynamicPPL.Model) = true | ||
|
||
@testset "GibbsContext" begin | ||
@testset verbose = true "GibbsContext" begin | ||
@testset "type stability" begin | ||
struct Wrapper{T<:Real} | ||
a::T | ||
|
@@ -384,8 +371,9 @@ end | |
@test wuc.non_warmup_count == (num_samples - 1) * num_reps | ||
end | ||
|
||
@testset "Testing gibbs.jl with $adbackend" for adbackend in ADUtils.adbackends | ||
@info "Starting Gibbs tests with $adbackend" | ||
@testset verbose = true "Testing gibbs.jl" begin | ||
@info "Starting Gibbs tests" | ||
adbackend = Turing.DEFAULT_ADTYPE | ||
|
||
@testset "Gibbs constructors" begin | ||
# Create Gibbs samplers with various configurations and ways of passing the | ||
|
@@ -597,41 +585,27 @@ end | |
@model function dynamic_model_with_dot_tilde( | ||
num_zs=10, ::Type{M}=Vector{Float64} | ||
) where {M} | ||
z = M(undef, num_zs) | ||
z = Vector{Int}(undef, num_zs) | ||
z .~ Poisson(1.0) | ||
num_ms = sum(z) | ||
m = M(undef, num_ms) | ||
return m .~ Normal(1.0, 1.0) | ||
end | ||
model = dynamic_model_with_dot_tilde() | ||
# TODO(mhauru) This is broken because of | ||
# https://github.com/TuringLang/DynamicPPL.jl/issues/700. | ||
@test_broken ( | ||
sample(model, Gibbs(:z => PG(10), :m => HMC(0.01, 4; adtype=adbackend)), 100); | ||
true | ||
) | ||
sample(model, Gibbs(:z => PG(10), :m => HMC(0.01, 4; adtype=adbackend)), 100) | ||
end | ||
|
||
@testset "Demo models" begin | ||
@testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS | ||
@testset "Demo model" begin | ||
@testset verbose = true "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS | ||
vns = DynamicPPL.TestUtils.varnames(model) | ||
samplers = [ | ||
Turing.Gibbs(@varname(s) => NUTS(), @varname(m) => NUTS()), | ||
Turing.Gibbs(@varname(s) => NUTS(), @varname(m) => HMC(0.01, 4)), | ||
Turing.Gibbs(@varname(s) => NUTS(), @varname(m) => ESS()), | ||
Turing.Gibbs(@varname(s) => HMC(0.01, 4), @varname(m) => MH()), | ||
Turing.Gibbs(@varname(s) => MH(), @varname(m) => HMC(0.01, 4)), | ||
] | ||
|
||
if !has_dot_assume(model) | ||
# Add in some MH samplers, which are not compatible with `.~`. | ||
append!( | ||
samplers, | ||
[ | ||
Turing.Gibbs(@varname(s) => HMC(0.01, 4), @varname(m) => MH()), | ||
Turing.Gibbs(@varname(s) => MH(), @varname(m) => HMC(0.01, 4)), | ||
], | ||
) | ||
end | ||
|
||
Comment on lines
+601
to
-634
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also removed this (outdated) check for dot assume so now it checks with every sampler combination |
||
@testset "$sampler" for sampler in samplers | ||
# Check that taking steps performs as expected. | ||
rng = Random.default_rng() | ||
|
@@ -846,7 +820,7 @@ end | |
check_MoGtest_default_z_vector(chain; atol=0.2) | ||
end | ||
|
||
@testset "externsalsampler" begin | ||
@testset "externalsampler" begin | ||
@model function demo_gibbs_external() | ||
m1 ~ Normal() | ||
m2 ~ Normal() | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.