Turing: problem using MCMCthreads()

From the AbstractMCMC docs:

  • init_params (default: nothing): if set to init_params !== nothing, then the ith element of init_params is used as initial parameters of the ith chain. If one wants to use the same initial parameters x for every chain, one can specify e.g. init_params = Iterators.repeated(x) or init_params = FillArrays.Fill(x, N).

So when sampling a single chain, you pass a single set of initial parameters. When sampling multiple chains, you pass an iterator of initial parameters. e.g.

julia> using Turing

julia> @model function mod()
           x ~ filldist(Normal(), 10)
       end;

julia> x0 = randn(10);

julia> sample(mod(), NUTS(), 1_000; init_params=x0);
┌ Info: Found initial step size
└   ϵ = 1.6
Sampling 100%|█████████████████████████████████████████████████████████████████████████| Time: 0:00:00

julia> sample(mod(), NUTS(), MCMCThreads(), 1_000, 4; init_params=Iterators.repeated(x0));
┌ Warning: Only a single thread available: MCMC chains are not sampled in parallel
└ @ AbstractMCMC ~/.julia/packages/AbstractMCMC/0eT8o/src/sample.jl:291
┌ Info: Found initial step size
└   ϵ = 1.6
┌ Info: Found initial step size
└   ϵ = 1.6
┌ Info: Found initial step size
└   ϵ = 1.6
┌ Info: Found initial step size
└   ϵ = 1.6
Sampling (1 threads) 100%|█████████████████████████████████████████████████████████████| Time: 0:00:00
3 Likes