Skip to content

Commit 7638c01

Browse files
authored
Fix performance of getparams on untyped vi (#2605)
1 parent 97c3bc7 commit 7638c01

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Release 0.39.3
2+
3+
Improved the performance of `Turing.Inference.getparams` when called with an untyped VarInfo as the second argument, by first converting to a typed VarInfo.
4+
This makes, for example, the post-sampling Chains construction for `Prior()` run much faster.
5+
16
# Release 0.39.2
27

38
Fixed a bug in the support of `OrderedLogistic` (by changing the minimum from 0 to 1).

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Turing"
22
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
3-
version = "0.39.2"
3+
version = "0.39.3"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/mcmc/Inference.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
184184
# Materialize the iterators and concatenate.
185185
return mapreduce(collect, vcat, iters)
186186
end
187+
function getparams(
188+
model::DynamicPPL.Model, untyped_vi::DynamicPPL.VarInfo{<:DynamicPPL.Metadata}
189+
)
190+
# values_as_in_model is unconscionably slow for untyped VarInfo. It's
191+
# much faster to convert it to a typed varinfo before calling getparams.
192+
# https://github.com/TuringLang/Turing.jl/issues/2604
193+
return getparams(model, DynamicPPL.typed_varinfo(untyped_vi))
194+
end
187195
function getparams(::DynamicPPL.Model, ::DynamicPPL.VarInfo{NamedTuple{(),Tuple{}}})
188196
return float(Real)[]
189197
end

0 commit comments

Comments
 (0)