Skip to content

Commit bb22aee

Browse files
committed
Merge remote-tracking branch 'origin/master' into py/v0.35
2 parents 02c24ef + ba5e408 commit bb22aee

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

Manifest.toml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.10.6"
44
manifest_format = "2.0"
5-
project_hash = "46b1a3e94b0848456d070eb24006f64ff234812a"
5+
project_hash = "53e97ef537fe2e98eecbe367cd36c4bc6a201e3e"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "72af59f5b8f09faee36b4ec48e014a79210f2f4f"
@@ -142,9 +142,9 @@ uuid = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"
142142
version = "1.1.3"
143143

144144
[[deps.ArgCheck]]
145-
git-tree-sha1 = "a3a402a35a2f7e0b87828ccabbd5ebfbebe356b4"
145+
git-tree-sha1 = "680b3b8759bd4c54052ada14e52355ab69e07876"
146146
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
147-
version = "2.3.0"
147+
version = "2.4.0"
148148

149149
[[deps.ArgTools]]
150150
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
@@ -271,6 +271,12 @@ git-tree-sha1 = "aebf55e6d7795e02ca500a689d326ac979aaf89e"
271271
uuid = "9718e550-a3fa-408a-8086-8db961cd8217"
272272
version = "0.1.1"
273273

274+
[[deps.BenchmarkTools]]
275+
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
276+
git-tree-sha1 = "f1dff6729bc61f4d49e140da1af55dcd1ac97b2f"
277+
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
278+
version = "1.5.0"
279+
274280
[[deps.Bijectors]]
275281
deps = ["ArgCheck", "ChainRules", "ChainRulesCore", "ChangesOfVariables", "Compat", "Distributions", "DocStringExtensions", "Functors", "InverseFunctions", "IrrationalConstants", "LinearAlgebra", "LogExpFunctions", "MappedArrays", "Random", "Reexport", "Requires", "Roots", "SparseArrays", "Statistics"]
276282
git-tree-sha1 = "6e686c360af8375162531708acb824ae1182b1d5"
@@ -2196,9 +2202,9 @@ version = "4.5.1"
21962202

21972203
[[deps.NNlib]]
21982204
deps = ["Adapt", "Atomix", "ChainRulesCore", "GPUArraysCore", "KernelAbstractions", "LinearAlgebra", "Random", "Statistics"]
2199-
git-tree-sha1 = "da09a1e112fd75f9af2a5229323f01b56ec96a4c"
2205+
git-tree-sha1 = "1177f161cda2083543b9967d7ca2a3e24e721e13"
22002206
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
2201-
version = "0.9.24"
2207+
version = "0.9.26"
22022208

22032209
[deps.NNlib.extensions]
22042210
NNlibAMDGPUExt = "AMDGPU"
@@ -2797,6 +2803,10 @@ version = "2.4.0"
27972803
deps = ["Unicode"]
27982804
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
27992805

2806+
[[deps.Profile]]
2807+
deps = ["Printf"]
2808+
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
2809+
28002810
[[deps.ProgressLogging]]
28012811
deps = ["Logging", "SHA", "UUIDs"]
28022812
git-tree-sha1 = "80d919dee55b9c50e8d9e2da5eeafff3fe58b539"
@@ -3043,9 +3053,9 @@ version = "0.1.1"
30433053

30443054
[[deps.SciMLBase]]
30453055
deps = ["ADTypes", "Accessors", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "Expronicon", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "SciMLStructures", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface"]
3046-
git-tree-sha1 = "6a5fac56e8084323fec06daf2877c6b4781e593a"
3056+
git-tree-sha1 = "6f156f48d3603e8023e59917547b141218f2656d"
30473057
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
3048-
version = "2.63.1"
3058+
version = "2.64.0"
30493059

30503060
[deps.SciMLBase.extensions]
30513061
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
@@ -3589,6 +3599,18 @@ weakdeps = ["DynamicHMC", "Optim"]
35893599
TuringDynamicHMCExt = "DynamicHMC"
35903600
TuringOptimExt = "Optim"
35913601

3602+
[[deps.TuringBenchmarking]]
3603+
deps = ["ADTypes", "AbstractMCMC", "BenchmarkTools", "DynamicPPL", "ForwardDiff", "LinearAlgebra", "LogDensityProblems", "LogDensityProblemsAD", "PrettyTables", "Requires", "ReverseDiff", "Zygote"]
3604+
git-tree-sha1 = "b512c8ab665cb6396f19533b6960cc3e0fc4d556"
3605+
uuid = "0db1332d-5c25-4deb-809f-459bc696f94f"
3606+
version = "0.5.5"
3607+
3608+
[deps.TuringBenchmarking.extensions]
3609+
TuringBenchmarkingBridgeStanExt = "BridgeStan"
3610+
3611+
[deps.TuringBenchmarking.weakdeps]
3612+
BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a"
3613+
35923614
[[deps.URIs]]
35933615
git-tree-sha1 = "67db6cc7b3821e19ebe75791a9dd19c9b1188f2b"
35943616
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
@@ -3728,9 +3750,9 @@ version = "2.13.5+0"
37283750

37293751
[[deps.XSLT_jll]]
37303752
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "XML2_jll", "Zlib_jll"]
3731-
git-tree-sha1 = "a54ee957f4c86b526460a720dbc882fa5edcbefc"
3753+
git-tree-sha1 = "7d1671acbe47ac88e981868a078bd6b4e27c5191"
37323754
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
3733-
version = "1.1.41+0"
3755+
version = "1.1.42+0"
37343756

37353757
[[deps.XZ_jll]]
37363758
deps = ["Artifacts", "JLLWrappers", "Libdl"]

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
5050
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
5151
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
5252
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
53+
TuringBenchmarking = "0db1332d-5c25-4deb-809f-459bc696f94f"
5354
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
5455
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
5556

tutorials/docs-10-using-turing-autodiff/index.qmd

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ Turing currently supports four automatic differentiation (AD) backends for sampl
1818
As of Turing version v0.30, the global configuration flag for the AD backend has been removed in favour of [`AdTypes.jl`](https://github.com/SciML/ADTypes.jl), allowing users to specify the AD backend for individual samplers independently.
1919
Users can pass the `adtype` keyword argument to the sampler constructor to select the desired AD backend, with the default being `AutoForwardDiff(; chunksize=0)`.
2020

21-
For `ForwardDiff`, pass `adtype=AutoForwardDiff(; chunksize)` to the sampler constructor. A `chunksize` of 0 permits the chunk size to be automatically determined. For more information regarding the selection of `chunksize`, please refer to [related section of `ForwardDiff`'s documentation](https://juliadiff.org/ForwardDiff.jl/dev/user/advanced/#Configuring-Chunk-Size).
22-
For `ReverseDiff`, pass `adtype=AutoReverseDiff()` to the sampler constructor. An additional argument can be provided to `AutoReverseDiff` to specify whether to to compile the tape only once and cache it for later use (`false` by default, which means no caching tape). Be aware that the use of caching in certain types of models can lead to incorrect results and/or errors.
21+
For `ForwardDiff`, pass `adtype=AutoForwardDiff(; chunksize)` to the sampler constructor. A `chunksize` of `nothing` permits the chunk size to be automatically determined. For more information regarding the selection of `chunksize`, please refer to [related section of `ForwardDiff`'s documentation](https://juliadiff.org/ForwardDiff.jl/dev/user/advanced/#Configuring-Chunk-Size).
2322

24-
Compiled tapes should only be used if you are absolutely certain that the computation doesn't change between different executions of your model.
25-
Thus, e.g., in the model definition and all im- and explicitly called functions in the model all loops should be of fixed size, and `if`-statements should consistently execute the same branches.
26-
For instance, `if`-statements with conditions that can be determined at compile time or conditions that depend only on the data will always execute the same branches during sampling (if the data is constant throughout sampling and, e.g., no mini-batching is used).
23+
For `ReverseDiff`, pass `adtype=AutoReverseDiff()` to the sampler constructor. An additional keyword argument called `compile` can be provided to `AutoReverseDiff`. It specifies whether to pre-record the tape only once and reuse it later (`compile` is set to `false` by default, which means no pre-recording). This can substantially improve performance, but risks silently incorrect results if not used with care.
24+
25+
26+
27+
Pre-recorded tapes should only be used if you are absolutely certain that the sequence of operations performed in your code does not change between different executions of your model.
28+
29+
Thus, e.g., in the model definition and all implicitly and explicitly called functions in the model, all loops should be of fixed size, and `if`-statements should consistently execute the same branches.
30+
For instance, `if`-statements with conditions that can be determined at compile time or conditions that depend only on fixed properties of the model, e.g. fixed data.
2731
However, `if`-statements that depend on the model parameters can take different branches during sampling; hence, the compiled tape might be incorrect.
2832
Thus you must not use compiled tapes when your model makes decisions based on the model parameters, and you should be careful if you compute functions of parameters that those functions do not have branching which might cause them to execute different code for different values of the parameter.
2933

@@ -61,4 +65,12 @@ c = sample(
6165

6266
Generally, reverse-mode AD, for instance `ReverseDiff`, is faster when sampling from variables of high dimensionality (greater than 20), while forward-mode AD, for instance `ForwardDiff`, is more efficient for lower-dimension variables. This functionality allows those who are performance sensitive to fine tune their automatic differentiation for their specific models.
6367

64-
If the differentiation method is not specified in this way, Turing will default to using whatever the global AD backend is. Currently, this defaults to `ForwardDiff`.
68+
If the differentiation method is not specified in this way, Turing will default to using whatever the global AD backend is.
69+
Currently, this defaults to `ForwardDiff`.
70+
71+
The most reliable way to ensure you are using the fastest AD that works for your problem is to benchmark them using [`TuringBenchmarking`](https://github.com/TuringLang/TuringBenchmarking.jl):
72+
73+
```{julia}
74+
using TuringBenchmarking
75+
benchmark_model(gdemo(1.5, 2), adbackends=[AutoForwardDiff(), AutoReverseDiff()])
76+
```

0 commit comments

Comments
 (0)