Turing 0.12.0 is out, and it comes with a lovely set of changes and updates. There are some deprecations and API changes, so please read carefully if 1) you use custom distributions or 2) you use the parallel sampling
See all the changes in our HISTORY.md file, but for now here’s the main changes from the user side.
The interface for defining new distributions with a constrained support and making them compatible with
Turing has changed. To make a custom distribution type
CustomDistribution compatible with
Turing , the user needs to define the method
bijector(d::CustomDistribution) that returns an instance of type
Bijector implementing the
You can read more about Bijectors.jl here. Please reach out to the team on Discourse in the probabilistic programming category, or on Slack/Zulip.
Upstream changes in AbstractMCMC.jl have deprecated the
psample function, which previously sampled multiple chains with thread parallelism.
psample was initially a test to see if we could make it work, but it’s been time to make it more in line with the design patterns we use.
To that end,
sample now has additional signatures which allow you to specify a type of parallelism (threaded or process-based) to use on each chain. Here’s some examples:
# Sample n_chains using one process per chain sample(model, sampler, MCMCDistributed(), n_samples, n_chains) # Sample n_chains using one thread per chain sample(model, sampler, MCMCThreads(), n_samples, n_chains)
I hope everyone will try this out – the distributed process sampling is a new feature that I’m fond of.
In other parallelism news,
observe statements are threadsafe. As an example, the following code is now thread-safe:
@model function example(data) Threads.@threads for i in eachindex(data) data[i] ~ Normal(0,1) end end
This should help if you observe a large amount of data and want to parallelize
@logpdf , and
@sampler are removed. Instead one can access the internal variables
_sampler , and
_context in the
This was to remove macros from inside the model definition, which was kind of an antipattern. Since
@logpdf was removed, it’s worth noting that you can access the current log density using
Particle sampler methods
PG now have new methods that make it far easier to set the sampler threshold and resampler method.
For example, if you want to sample with a threshold of 0.4, you can do so with
PG, this is
That’s all for now folks. Thanks for reading, and please give us whatever feedback you have.