From d176f19908e03cfdeabc85645a7f8839328c1003 Mon Sep 17 00:00:00 2001 From: FredericWantiez Date: Sat, 9 Mar 2024 00:30:29 +0000 Subject: [PATCH] Forward RNG argument in benchmark (#173) * Forward RNG argument * p2 --- perf/p0.jl | 6 ++++-- perf/p2.jl | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/perf/p0.jl b/perf/p0.jl index 81ce7fd2..757d8b3a 100644 --- a/perf/p0.jl +++ b/perf/p0.jl @@ -1,3 +1,4 @@ +using Random using Libtask using Turing, DynamicPPL, AdvancedPS using BenchmarkTools @@ -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]; @@ -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]; diff --git a/perf/p2.jl b/perf/p2.jl index a95b3d3c..bd904c33 100644 --- a/perf/p2.jl +++ b/perf/p2.jl @@ -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]