Skip to content

Commit

Permalink
Forward RNG argument in benchmark (#173)
Browse files Browse the repository at this point in the history
* Forward RNG argument

* p2
  • Loading branch information
FredericWantiez authored Mar 9, 2024
1 parent fb66279 commit d176f19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions perf/p0.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Random
using Libtask
using Turing, DynamicPPL, AdvancedPS
using BenchmarkTools
Expand All @@ -13,7 +14,8 @@ end


# Case 1: Sample from the prior.
m = Turing.Core.TracedModel(gdemo(1.5, 2.), SampleFromPrior(), VarInfo())
rng = MersenneTwister()
m = Turing.Core.TracedModel(gdemo(1.5, 2.), SampleFromPrior(), VarInfo(), rng)
f = m.evaluator[1];
args = m.evaluator[2:end];

Expand All @@ -26,7 +28,7 @@ println("Run a tape...")
@btime t.tf(args...)

# Case 2: SMC sampler
m = Turing.Core.TracedModel(gdemo(1.5, 2.), Sampler(SMC(50)), VarInfo());
m = Turing.Core.TracedModel(gdemo(1.5, 2.), Sampler(SMC(50)), VarInfo(), rng)
f = m.evaluator[1];
args = m.evaluator[2:end];

Expand Down
8 changes: 4 additions & 4 deletions perf/p2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ using Turing, Test, AbstractMCMC, DynamicPPL, Random, Turing.RandomMeasures, Lib
end

# Generate some test data.
Random.seed!(1)
rng = Random.seed!(1)

data = vcat(randn(10), randn(10) .- 5, randn(10) .+ 10)
data = vcat(randn(rng, 10), randn(rng, 10) .- 5, randn(rng, 10) .+ 10)
data .-= mean(data)
data /= std(data)

# MCMC sampling
Random.seed!(2)
Random.seed!(rng, 2)
iterations = 500
model_fun = infiniteGMM(data)

m = Turing.Core.TracedModel(model_fun, Sampler(SMC(50)), VarInfo())
m = Turing.Core.TracedModel(model_fun, Sampler(SMC(50)), VarInfo(), rng)
f = m.evaluator[1]
args = m.evaluator[2:end]

Expand Down

0 comments on commit d176f19

Please sign in to comment.