You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: HISTORY.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,18 +17,20 @@ If you were previously relying on this behaviour, you will need to store a VarIn
17
17
18
18
#### Threadsafe evaluation
19
19
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:
22
25
23
26
```julia
24
27
@modelf() =...
25
28
model =f()
26
29
model =setthreadsafe(model, true)
27
30
```
28
31
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.
32
34
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.
33
35
34
36
**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
41
43
If you have none of these inside threaded blocks, then you do not need to mark your model as threadsafe.
42
44
**Notably, the following do not require threadsafe evaluation:**
43
45
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.
45
47
- Sampling with `AbstractMCMC.MCMCThreads()`.
46
48
49
+
For more information about threadsafe evaluation, please see [the Turing docs](https://turinglang.org/docs/usage/threadsafe-evaluation/).
50
+
47
51
#### Parent and leaf contexts
48
52
49
53
The `DynamicPPL.NodeTrait` function has been removed.
Copy file name to clipboardExpand all lines: docs/src/api.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ The context of a model can be set using [`contextualize`](@ref):
42
42
contextualize
43
43
```
44
44
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).
46
46
If this is the case, one must enable threadsafe evaluation for a model:
Copy file name to clipboardExpand all lines: src/compiler.jl
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -384,7 +384,7 @@ function generate_mainbody!(mod, found, expr::Expr, warn, warn_threads)
384
384
"It looks like you are using `Threads.@threads` in your model definition."*
385
385
"\n\nNote that since version 0.39 of DynamicPPL, threadsafe evaluation of models is disabled by default."*
386
386
" 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."
0 commit comments