Skip to content

Commit d3bce6e

Browse files
committed
Point to new Turing docs page
1 parent 0db391d commit d3bce6e

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

HISTORY.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ If you were previously relying on this behaviour, you will need to store a VarIn
1717

1818
#### Threadsafe evaluation
1919

20-
DynamicPPL models are by default no longer thread-safe.
21-
If you have threading in a model, you **must** now manually mark it as so, using:
20+
DynamicPPL models have traditionally supported running some probabilistic statements (e.g. tilde-statements, or `@addlogprob!`) in parallel.
21+
Prior to DynamicPPL 0.39, thread safety for such models used to be enabled by default if Julia was launched with more than one thread.
22+
23+
In DynamicPPL 0.39, **thread-safe evaluation is now disabled by default**.
24+
If you need it (see below for more discussion of when you _do_ need it), you **must** now manually mark it as so, using:
2225

2326
```julia
2427
@model f() = ...
2528
model = f()
2629
model = setthreadsafe(model, true)
2730
```
2831

29-
It used to be that DynamicPPL would 'automatically' enable thread-safe evaluation if Julia was launched with more than one thread (i.e., by checking `Threads.nthreads() > 1`).
30-
31-
The problem with this approach is that it sacrifices a huge amount of performance.
32+
The problem with the previous on-by-default is that it can sacrifice a huge amount of performance when thread safety is not needed.
33+
This is especially true when running Julia in a notebook, where multiple threads are often enabled by default.
3234
Furthermore, it is not actually the correct approach: just because Julia has multiple threads does not mean that a particular model actually requires threadsafe evaluation.
3335

3436
**A model requires threadsafe evaluation if, and only if, the VarInfo object used inside the model is manipulated in parallel.**
@@ -41,9 +43,11 @@ This can occur if any of the following are inside `Threads.@threads` or other co
4143
If you have none of these inside threaded blocks, then you do not need to mark your model as threadsafe.
4244
**Notably, the following do not require threadsafe evaluation:**
4345

44-
- Using threading for anything that does not involve VarInfo. For example, you can calculate a log-probability in parallel, and then add it using `@addlogprob!` outside of the threaded block. This does not require threadsafe evaluation.
46+
- Using threading for any computation that does not involve VarInfo. For example, you can calculate a log-probability in parallel, and then add it using `@addlogprob!` outside of the threaded block. This does not require threadsafe evaluation.
4547
- Sampling with `AbstractMCMC.MCMCThreads()`.
4648

49+
For more information about threadsafe evaluation, please see [the Turing docs](https://turinglang.org/docs/usage/threadsafe-evaluation/).
50+
4751
#### Parent and leaf contexts
4852

4953
The `DynamicPPL.NodeTrait` function has been removed.

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The context of a model can be set using [`contextualize`](@ref):
4242
contextualize
4343
```
4444

45-
Some models require threadsafe evaluation (see https://turinglang.org/docs/THIS_DOESNT_EXIST_YET for more information on when this is necessary).
45+
Some models require threadsafe evaluation (see [the Turing docs](https://turinglang.org/docs/usage/threadsafe-evaluation/) for more information on when this is necessary).
4646
If this is the case, one must enable threadsafe evaluation for a model:
4747

4848
```@docs

src/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function generate_mainbody!(mod, found, expr::Expr, warn, warn_threads)
384384
"It looks like you are using `Threads.@threads` in your model definition." *
385385
"\n\nNote that since version 0.39 of DynamicPPL, threadsafe evaluation of models is disabled by default." *
386386
" If you need it, you will need to explicitly enable it by creating the model, and then running `model = setthreadsafe(model, true)`." *
387-
"\n\nAvoiding threadsafe evaluation can often lead to significant performance improvements. Please see https://turinglang.org/docs/THIS_PAGE_DOESNT_EXIST_YET for more details of when threadsafe evaluation is actually required."
387+
"\n\nAvoiding threadsafe evaluation can often lead to significant performance improvements. Please see https://turinglang.org/docs/usage/threadsafe-evaluation/ for more details of when threadsafe evaluation is actually required."
388388
)
389389
end
390390
return generate_mainbody!(

src/model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ outside of the parallel region is safe without needing to set `threadsafe=true`.
136136
137137
It is also not needed for multithreaded sampling with AbstractMCMC's `MCMCThreads()`.
138138
139-
Setting `threadsafe` to `true` increases the overhead in evaluating the model. See
140-
(https://turinglang.org/docs/THIS_DOESNT_EXIST_YET)[https://turinglang.org/docs/THIS_DOESNT_EXIST_YET]
141-
for more details.
139+
Setting `threadsafe` to `true` increases the overhead in evaluating the model. Please see
140+
[the Turing.jl docs](https://turinglang.org/docs/usage/threadsafe-evaluation/) for more
141+
details.
142142
"""
143143
function setthreadsafe(model::Model{F,A,D,M}, threadsafe::Bool) where {F,A,D,M}
144144
return if _requires_threadsafe(model) == threadsafe

0 commit comments

Comments
 (0)