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
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,41 @@
9
9
This version provides a reimplementation of `LogDensityFunction` that provides performance improvements on the order of 2–10× for both model evaluation as well as automatic differentiation.
10
10
Exact speedups depend on the model size: larger models have less significant speedups because the bulk of the work is done in calls to `logpdf`.
11
11
12
-
For more information about how this is accomplished, please see https://github.com/TuringLang/DynamicPPL.jl/pull/1113 as well as the `src/fasteval.jl` file, which contains extensive comments.
12
+
For more information about how this is accomplished, please see https://github.com/TuringLang/DynamicPPL.jl/pull/1113 as well as the `src/logdensityfunction.jl` file, which contains extensive comments.
13
13
14
14
As a result of this change, `LogDensityFunction` no longer stores a VarInfo inside it.
15
15
In general, if `ldf` is a `LogDensityFunction`, it is now only valid to access `ldf.model` and `ldf.adtype`.
16
16
If you were previously relying on this behaviour, you will need to store a VarInfo separately.
17
17
18
+
#### Threadsafe evaluation
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:
22
+
23
+
```julia
24
+
@modelf() =...
25
+
model =f()
26
+
model =setthreadsafe(model, true)
27
+
```
28
+
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
+
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
+
34
+
**A model requires threadsafe evaluation if, and only if, the VarInfo object used inside the model is manipulated in parallel.**
35
+
This can occur if any of the following are inside `Threads.@threads` or other concurrency functions / macros:
36
+
37
+
- tilde-statements
38
+
- calls to `@addlogprob!`
39
+
- any direct manipulation of the special `__varinfo__` variable
40
+
41
+
If you have none of these inside threaded blocks, then you do not need to mark your model as threadsafe.
42
+
**Notably, the following do not require threadsafe evaluation:**
43
+
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.
45
+
- Sampling with `AbstractMCMC.MCMCThreads()`.
46
+
18
47
#### Parent and leaf contexts
19
48
20
49
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