-
Notifications
You must be signed in to change notification settings - Fork 32
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
Should we have a context to indicate that we're not performing inference? #510
Comments
Bumping this in the context of prediction. |
It was attempted in #589 but got downvoted for now, as it was deemed undesirable to add more macros (see discussion in that PR) |
A thing to note is that if you want to do within chain parallel then this is a handy feature. A reason is that its much easier to use |
Not sure I understand this. Can you clarify what you mean by "sacrifice the generative quality of the Turing PPL"? @SamuelBrand1 |
I believe @SamuelBrand1 means that you can drop the usage of |
Just saw this, but yes exactly! |
@torfjelde and I have some further discussion today. While I agree this is a useful feature, I am not yet convinced there is a safe and robust design. I suggest that we use something more specific than Suggestions on a better design are welcome! |
I think we could use something like See, also, TuringLang/Turing.jl#2239 Cc @devmotion @sunxd3 @mhauru for more comments. |
Cc @seabbs |
Tried to summarize some of my thoughts on the topic. There are two issues here:
Modes of operation
This makes it so that it's difficult to answer the question "are we doing some post-inference analysis or are we inferring?" But for most of the applications we have in mind, I think it's sufficient to only determine that we're, say, performing parameter extraction, i.e. evaluating with Similarly for methods such as In such a case, we could have # NOTE: `has_context_type` is not implemented but is easy enough to do
is_post_inference(context::AbstractContext) = has_context_type(context, ValuesAsInModelContext) But doing something completely general like Best syntaxGenerally two categories of approaches:
Macro-basedMacro-based methods have the benefit that we can defer the resolution of varnames, etc. to the Buuut it's a) ugly, and b) means that Wrapper-basedThis a bit more annoying to implement, but if done right it will be a) nicer syntactically, and b) allow better composition with the rest of the code-base. Hence, this is probably the way to go. Further issues / questions
|
I buy @torfjelde's reasoning here. I also agree that the former of the two conditioning syntax is better. For one, |
Of the two proposals the wrapper based approach seems like it would work better for our use case. However I am a little bit confused why it is needed at all for things that in theory already return idd components (i.e filldist, .~). Couldn't these instead be modified to internally check the context and change behaviour accordingly (i.e automate using a idd wrapper?)
This seems like it would be very limiting? |
ATM there's no "context" to indicate this. As in, if you write
in your model, Turing.jl / DynamicPPL.jl doesn't know whether this is a) 10 iid variables, or b) a 10-dim multivariate variable implemented in an efficient manner. Nor is there realistically a way for us to check this, unfortunately 😕 Hence we need something explcit, e.g. |
Ah I guess I was confused by this: https://turinglang.org/docs/tutorials/docs-13-using-turing-performance-tips/index.html#special-care-for-zygote-and-tracker
My expectation was that internally |
Sometimes we know that we're not performing inference in a model, in which case it can be useful to have the model perform some additional computations.
For example, people often end up using
Dirac
to save quantities that are deterministic when conditioned on the variables in aChains
(e.g. TuringLang/Turing.jl#2059), but this can then cause issues since samplers will also consider these as random variables to be sampled.generated_quantities
provides a partial solution to this, but~
, which people often want.Addressing (2) is non-trivial as it requires changing both the internals of varinfos in addition to how transitions are constructed in Turing.jl.
But addressing (1) could be done by adding a simple
NotInferringContext
+ a macro@isinferring
, which simply translates into a callisinferring(__context__, __varinfo__)
or something. We could then either provide an alternative togenerated_quantities
which makes use of this, or we could include this ingenerated_quantities
somehow (I'm leaning towards the former).An alternative way of addressing (1) is to just provide a convenient way to convert a
Matrix{<:NamedTuple}
into aChains
, which I have existing code to do, but the annoying bit with this is that it's "asking a lot" of the user (they need to explicitly filter out the variables inreturn
they don't want in the chain, and then also make sure to return aNamedTuple
, etc.). Hence I think I'm leaning towards supporting both approaches 🤷The text was updated successfully, but these errors were encountered: