Hi,
I am trying to run samplers in parallel by using example code in Turing documentation (Parallel Sampling). When I run the following example, I am getting an error. The example is as follows:
using Distributed
addprocs(4)
@everywhere using Turing, Random
# Set the progress to false to avoid too many notifications.
@everywhere turnprogress(false)
# Set a different seed for each process.
for i in procs()
@fetch @spawnat i Random.seed!(rand(Int64))
end
# Define the model using @everywhere.
@everywhere @model gdemo(x) = begin
s ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s))
for i in eachindex(x)
x[i] ~ Normal(m, sqrt(s))
end
end
# Sampling setup.
num_chains = 4
sampler = NUTS(0.65)
model = gdemo([1.2, 3.5])
# Run all samples.
chns = reduce(chainscat, pmap(x->sample(model, sampler, 1000), 1:num_chains))
and the error as follows:
On worker 2:
UndefVarError: model not defined
#21 at D:\JULIA\TURING_LSPECT\test_parallel.jl:28
#108 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Distributed\src\process_messages.jl:294
run_work_thunk at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Distributed\src\process_messages.jl:79
macro expansion at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Distributed\src\process_messages.jl:294 [inlined]
#107 at .\task.jl:333
(::Base.var"#732#734")(::Task) at asyncmap.jl:178
foreach(::Base.var"#732#734", ::Array{Any,1}) at abstractarray.jl:1920
maptwice(::Function, ::Channel{Any}, ::Array{Any,1}, ::UnitRange{Int64}) at asyncmap.jl:178
wrap_n_exec_twice(::Channel{Any}, ::Array{Any,1}, ::Distributed.var"#208#211"{WorkerPool}, ::Function, ::UnitRange{Int64}) at asyncmap.jl:154
#async_usemap#717(::Function, ::Nothing, ::typeof(Base.async_usemap), ::Distributed.var"#192#194"{Distributed.var"#192#193#195"{WorkerPool,var"#21#22"}}, ::UnitRange{Int64}) at asyncmap.jl:103
(::Base.var"#kw##async_usemap")(::NamedTuple{(:ntasks, :batch_size),Tuple{Distributed.var"#208#211"{WorkerPool},Nothing}}, ::typeof(Base.async_usemap), ::Function, ::UnitRange{Int64}) at none:0
#asyncmap#716 at asyncmap.jl:81 [inlined]
#asyncmap at none:0 [inlined]
#pmap#207(::Bool, ::Int64, ::Nothing, ::Array{Any,1}, ::Nothing, ::typeof(pmap), ::Function, ::WorkerPool, ::UnitRange{Int64}) at pmap.jl:126
pmap(::Function, ::WorkerPool, ::UnitRange{Int64}) at pmap.jl:101
#pmap#217(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(pmap), ::Function, ::UnitRange{Int64}) at pmap.jl:156
pmap(::Function, ::UnitRange{Int64}) at pmap.jl:156
top-level scope at test_parallel.jl:28
How can I solve this error? My julia version is 1.3 and turing is Turing v0.8.3
Thanks in Advance !
Manu