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
Mark all methods with DynamicPPL.Model as produceable (#2780)
This needs a Libtask release and version bump, which I'll handle once
JuliaRegistrator does its things.
This essentially implements the plan described in
TuringLang/Libtask.jl#217. A lot of the issues
stemming from Libtask not picking up model evaluators either with
keyword arguments, or in submodels, can be fixed by simply declaring
that **every** method that dispatches on `DynamicPPL.Model` is
produceable. The mechanism for this is implemented in
TuringLang/Libtask.jl#218, and this PR makes use
of that.
**For the end-user, this means that we guarantee correctness where
models either have submodels or where models have keyword arguments. The
user no longer has to mark models with keyword arguments as
`@might_produce`.**
I tested performance, and there is no regression — in fact there is a
small speedup (although that is probably benchmark noise):
## Submodel case
This was the issue #2772 where non-inlined submodels were not correctly
picked up.
#2778 fixed this with a strategy that was similar to that in this PR,
but was slightly more limited (this PR handles both submodels and
keyword arguments together).
```julia
using Turing, StableRNGs, Test
@model function inner(y, x)
@noinline
y ~ Normal(x)
end
@model function nested(y)
x ~ Normal()
a ~ to_submodel(inner(y, x))
end
m1 = nested(1.0)
@time sample(StableRNG(468), m1, PG(10), 2000; chain_type=Any, progress=false);
# 2.585299 seconds on #2778
# 2.523017 seconds on this PR
```
## Keyword argument case
This was the long-standing issue where models with keyword arguments
were originally not picked up by Libtask, and since v0.42.5, could be,
but relied on the user themselves manually declaring
`Libtask.@might_produce`.
```julia
@model function withkw(; y=0.0)
x ~ Normal()
y ~ Normal(x)
end
m1 = withkw(y=10.0);
# Turing.@might_produce(withkw)
@time sample(StableRNG(468), m1, PG(10), 2000; chain_type=Any, progress=false);
# withkw case
# 4.741234 seconds on main (requiring @might_produce)
# 4.441797 seconds on this PR (and not requiring @might_produce)
```
Copy file name to clipboardExpand all lines: HISTORY.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,11 @@
1
+
# 0.42.9
2
+
3
+
Improve handling of model evaluator functions with Libtask.
4
+
5
+
This means that when running SMC or PG on a model with keyword arguments, you no longer need to use `@might_produce` (see patch notes of v0.42.5 for more details on this).
6
+
7
+
It also means that submodels with observations inside will now be reliably handled by the SMC/PG samplers, which was not the case before (the observations were only picked up if the submodel was inlined by the Julia compiler, which could lead to correctness issues).
8
+
1
9
# 0.42.8
2
10
3
11
Add support for `TensorBoardLogger.jl` via `AbstractMCMC.mcmc_callback`.
0 commit comments