-
Notifications
You must be signed in to change notification settings - Fork 36
Sketch of VarNamedTuple #1074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: breaking
Are you sure you want to change the base?
Sketch of VarNamedTuple #1074
Conversation
|
I like what I've read so far. There is a tricky thing with There are probably about 5 different ways this approach could also go awry, so I'm not quite sure. |
|
I need to give more thought to the idea of passing the value of the variable to pushes all of |
|
I've been fixing my sketch implementation and adding some workaround hacks to Metadata, to see if I can get reasonable performance out of this approach. Here's a snippet I've been using to benchmark module TmpTest
using Random
using DynamicPPL
using Distributions
using BenchmarkTools
using LinearAlgebra
@model function f(dim)
x ~ Normal(0, 1)
y ~ Normal(x, 1)
z = Vector{Float64}(undef, dim)
for i in 1:dim
z[i] ~ Normal(y, 1)
end
data ~ MvNormal(z, I)
return nothing
end
dim = 300
m = f(dim) | (; data=randn(dim))
Random.seed!(23)
vi_tuple = DynamicPPL.tuple_varinfo(m)
Random.seed!(23)
vi_typed = DynamicPPL.typed_varinfo(m)
# svi_nt = DynamicPPL.SimpleVarInfo(vi_typed, NamedTuple)
svi_od = DynamicPPL.SimpleVarInfo(vi_typed, OrderedDict)
vi_tuple = link(vi_tuple, m)
vi_typed = link(vi_typed, m)
# svi_nt = link(svi_nt, m)
svi_od = link(svi_od, m)
logp = getlogjoint(last(DynamicPPL.evaluate!!(m, vi_tuple)))
@show logp
logp = getlogjoint(last(DynamicPPL.evaluate!!(m, vi_typed)))
@show logp
# logp = getlogjoint(last(DynamicPPL.evaluate!!(m, svi_nt)))
# @show logp
logp = getlogjoint(last(DynamicPPL.evaluate!!(m, svi_od)))
@show logp
# println("Link times")
# @btime link(vi_tuple, m)
# @btime link(vi_typed, m)
# # @btime link(svi_nt, m)
# @btime link(svi_od, m)
println("Evaluate times")
@btime DynamicPPL.evaluate!!(m, vi_tuple)
@btime DynamicPPL.evaluate!!(m, vi_typed)
# @btime DynamicPPL.evaluate!!(m, svi_nt)
@btime DynamicPPL.evaluate!!(m, svi_od)
endThe summary is that, with these hacks, I can take a model with varnames like Number of Symbols seems to not be an issue. I just made a model with 42 distinct variables all with their own lead Symbols, resulting in a NamedTuple with 42 keys, and all seems fine with it, including type inference. As long as we don't start turning IndexLenses into Symbols we are good. |
6e922a1 to
4c16894
Compare
This PR is unlikely ever to be merged. I presume once the features here are done, they will need to be split into smaller PRs, and some of it may go into AbstractPPL. I'm putting this up just do the development in public and be able to talk about it.