-
Notifications
You must be signed in to change notification settings - Fork 220
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
RFC: decouples Turing compiler and inference methods. #456
Comments
Thanks for opening this @yebai . Some of my comments at the end of the compiler note are a bit outdated in light of conversations we've had since. In particular the stuff relating to the variable naming / storage scheme, if we choose to enforce unique variable names at model scope. |
In the meeting last time, we generally agree to decouple Turing.jl into 3 modules, namely
Before starting working on the refactoring, we'd like to design & fix the API between three modules. For this purpose, we need to know what is needed for the models and inference methods we want to support (now and in the future). Below are two summary table which I start by what I can come up with now. Please feel free to update this list to reveal the latest discussion.
On internal typingAnother thing I forget to mention is that, some part of the complexity is from the difference of Turing.jl's internal variable type and Julia's native variable type. Comparing Stan's type design with Turing.jl and Julia:
I omitted Turing.jl's because they are currently stored as plain vector and transformed back to corresponding Julia type whenever necessary. Note that the design choice of flatting all variables is A closely related issue is here: #433 On possible ways to make use of modelling/inference assumptions
On adapting current code for better API as a starting pointI think it's possible to make current codes by wrapping internal functions/with minor changes to follow the decoupling idea. I feel it's a good start point - after we finish this, we can start to replace each isolated module with either refactored codes or a complete new implementation. |
I added useful information and thoughts on decoupling. Please let me know if there is anything unclear. |
Below is a list on API design on what we want each module to export, using the example code below. Please feel free to edit it. @model gdemo(x) = begin
s ~ InverseGamma(2,3)
m ~ Normal(0,sqrt(s))
x[1] ~ Normal(m, sqrt(s))
x[2] ~ Normal(m, sqrt(s))
return s, m
end
mf = gedemo([1.0, 1.5])
|
@xukai92 Thanks, Kai. I'm also working on a note - will post it soon. @willtebbutt We might be able to adapt most of your design. I'm re-thinking the BNP related requirement and realised that many issues are obsolete now due to recent refactoring. |
@yebai That's great. I feel it's hard to edit together / point to specific sentence using GitHub actually. E.g. filling the table together or questioning on some ideas others write. Do you think it might be better for us to switch this note on somewhere else? |
Some more notes which might be helpful Current
|
Response to @xukai92's stuff above. I broadly agree with what you've said, but have a few comments:
function can_be_unconstrained(model_type::Type{<:Composite})
for component_type in component_types(model_type)
can_be_unconstrained(component_type) || return false
end
return true
end
can_be_constrained(d::Type{<:Distributions.Normal}) = true
can_be_constrained(d::Type{SomethingNotUnconstrainable}) = false (I'm assuming that we already have something like this somewhere?)
|
Good idea!
In short SMC is a sequential version of IS and PG (or conditional SMC) is running MCMC in a way each step is a SMC + resampling.
Sorry I was not clear here. So given a probabilistic program whose random variables sampled in order About the |
Aha, I see. Both situations should be covered by providing wrappers for the proposed wrappers. Actually, it strikes me that we should actually be able to compile completely different
Good to know. What do we currently do about, for example, discrete RVs? My point was generally that there are various properties of a model that are required for different samplers, and I suspect that for any given model we should be able to automatically deduce whether or not any particular property holds. Consequently, there's not really a need for an
Ah, I see. I hadn't considered that that would be a thing, but it makes sense. |
Discussion - TBA.
Related issues:
Will's notes on syntax and compiler
The text was updated successfully, but these errors were encountered: