Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Hong Ge <[email protected]>
  • Loading branch information
sunxd3 and yebai authored Dec 13, 2023
1 parent 3f43809 commit 12a8680
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tutorials/docs-10-using-turing-autodiff/autodiff.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Turing currently supports four automatic differentiation (AD) backends for sampl
While `Tracker` is still available, its use is discouraged due to a lack of active maintenance.
`ForwardDiff` is automatically imported by Turing. To utilize `Zygote` or `ReverseDiff` for AD, users must explicitly import them with `using Zygote` or `using ReverseDiff`, alongside `using Turing`.

As of Turing version v0.30, [`AdTypes.jl`](https://github.com/SciML/ADTypes.jl) was introduced, allowing users to specify the AD backend for samplers.
Users can pass the `adtype` keyword argument to the sampler constructor to select the desired AD backend, with the default being `Turing.AutoForwardDiff(; chunksize=0)`.
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.
Users can pass the `adtype` keyword argument to the sampler constructor to select the desired AD backend, with the default being `AutoForwardDiff(; chunksize=0)`.

For `ForwardDiff`, pass `adtype=Turing.AutoForwardDiff(; chunksize)` to the sampler constructor. The `chunksize` keyword argument to `Turing.AutoForwardDiff` sets the chunk size for chunked AD. A `chunksize` of 0 permits the chunk size to be determined automatically.
For `ReverseDiff`, pass `adtype=Turing.AutoReverseDiff()` to the sampler constructor. An additional argument can be provided to `Turing.AutoReverseDiff` to specify whether to use caching (`false` by default, which means no caching tape). Be aware that using compiled cached tapes can sometimes result in incorrect results or errors.
For `ForwardDiff`, pass `adtype=AutoForwardDiff(; chunksize)` to the sampler constructor. The `chunksize` keyword argument to `Turing.AutoForwardDiff` sets the chunk size for chunked AD. A `chunksize` of 0 permits the chunk size to be determined automatically.
For `ReverseDiff`, pass `adtype=AutoReverseDiff()` to the sampler constructor. An additional argument can be provided to `Turing.AutoReverseDiff` to specify whether to use caching (`false` by default, which means no caching tape). Be aware that using compiled cached tapes can sometimes result in incorrect results or errors.

Compiled tapes should only be used if you are absolutely certain that the computation doesn't change between different executions of your model.
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.
Expand Down

0 comments on commit 12a8680

Please sign in to comment.