-
Couldn't load subscription status.
- 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. |
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
6e922a1 to
4c16894
Compare
| * People might really need IndexLenses in the middle of VarNames. The one place this comes up is submodels within a loop. I'm still inclined to keep designing without allowing for that, for now, but should keep in mind that that needs to be relaxed eventually. If it makes it easier, we can require that users explicitly tell us the size of any arrays for which this is done. | ||
| * When storing values for nested NamedTuples, the actual variable may be a struct. Do we need to be able to reconstruct the struct from the NamedTuple? If so, how do we do that? | ||
| * Do `Colon` indices cause any extra trouble for the leafnodes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
| * People might really need IndexLenses in the middle of VarNames. The one place this comes up is submodels within a loop. I'm still inclined to keep designing without allowing for that, for now, but should keep in mind that that needs to be relaxed eventually. If it makes it easier, we can require that users explicitly tell us the size of any arrays for which this is done. | |
| * When storing values for nested NamedTuples, the actual variable may be a struct. Do we need to be able to reconstruct the struct from the NamedTuple? If so, how do we do that? | |
| * Do `Colon` indices cause any extra trouble for the leafnodes? | |
| - People might really need IndexLenses in the middle of VarNames. The one place this comes up is submodels within a loop. I'm still inclined to keep designing without allowing for that, for now, but should keep in mind that that needs to be relaxed eventually. If it makes it easier, we can require that users explicitly tell us the size of any arrays for which this is done. | |
| - When storing values for nested NamedTuples, the actual variable may be a struct. Do we need to be able to reconstruct the struct from the NamedTuple? If so, how do we do that? | |
| - Do `Colon` indices cause any extra trouble for the leafnodes? |
|
#1097 prompted me to wonder, if I do vi = TupleVarInfo()
vi = setindex!!(vi, 1.0, @varname(x[1]))
getindex(vi, @varname(x))what should the last line return? I would like to say it should return |
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.