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
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,35 @@
4
4
5
5
### Breaking changes
6
6
7
+
#### Threadsafe evaluation
8
+
9
+
DynamicPPL models are by default no longer thread-safe.
10
+
If you have threading in a model, you **must** now manually mark it as so, using:
11
+
12
+
```julia
13
+
@modelf() =...
14
+
model =f()
15
+
model =setthreadsafe(model, true)
16
+
```
17
+
18
+
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`).
19
+
20
+
The problem with this approach is that it sacrifices a huge amount of performance.
21
+
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.
22
+
23
+
**A model requires threadsafe evaluation if, and only if, the VarInfo object used inside the model is manipulated in parallel.**
24
+
This can occur if any of the following are inside `Threads.@threads` or other concurrency functions / macros:
25
+
26
+
- tilde-statements
27
+
- calls to `@addlogprob!`
28
+
- any direct manipulation of the special `__varinfo__` variable
29
+
30
+
If you have none of these inside threaded blocks, then you do not need to mark your model as threadsafe.
31
+
**Notably, the following do not require threadsafe evaluation:**
32
+
33
+
- 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.
34
+
- Sampling with `AbstractMCMC.MCMCThreads()`.
35
+
7
36
#### Parent and leaf contexts
8
37
9
38
The `DynamicPPL.NodeTrait` function has been removed.
if expr.args[1] ==Expr(:., :Threads, QuoteNode(Symbol("@threads"))) &&
379
+
!warned_about_threads_threads
380
+
warned_about_threads_threads =true
381
+
@warn (
382
+
"It looks like you are using `Threads.@threads` in your model definition."*
383
+
"\n\nNote that since version 0.39 of DynamicPPL, threadsafe evaluation of models is disabled by default."*
384
+
" If you need it, you will need to explicitly enable it by creating the model, and then running `model = setthreadsafe(model, true)`."*
385
+
"\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."
0 commit comments