Skip to content
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

observe and assume #504

Closed
trappmartin opened this issue Sep 7, 2018 · 4 comments
Closed

observe and assume #504

trappmartin opened this issue Sep 7, 2018 · 4 comments

Comments

@trappmartin
Copy link
Member

trappmartin commented Sep 7, 2018

I think the following points regarding the current code might be problematic and changing them could improve our codebase.

  1. Assume and observe dispatch on the sampler type (which is fine) but also on Nothing. This forces us to pass nothing to the functions if no sampler is defined and have a Union{Nothing, Sampler} for the model functions. I think we can circumvent this by having different function signatures, one with and one without the sampler argument. Or do I miss something here?

  2. Currently assume and observe do in-place operations and not in-place operations at the same time More precisely, they change the VarInfo variable and also return values that are used later on. This is inconsistent and might lead to strange behaviour. I would prefer to make this consistent and ensure that all operations are either in-place or not. I feel the mixed behaviour is not very clean. See for example:

    vi.num_produce += 1
    and
    push!(vi, vn, r, dist, 0)

    Or is there a reason why cannot do all operations in-place?

cc: @yebai

@xukai92
Copy link
Member

xukai92 commented Sep 10, 2018

Assume and observe dispatch on the sampler type (which is fine) but also on Nothing. This forces us to pass nothing to the functions if no sampler is defined and have a Union{Nothing, Sampler} for the model functions. I think we can circumvent this by having different function signatures, one with and one without the sampler argument. Or do I miss something here?

I think this should work. Actually, when assume is used for initialisation, the spl is not used at all. Maybe we can have a signature where there is not spl in the argument, and call that function when spl is nothing.

Or is there a reason why cannot do all operations in-place?

This in-place + non in-place signature was introduced when we moved to ReverseDiff, for which initialising a _lp in the @model scope and accumulating that in the main loop instead of doing in-place accumulation in VarInfo gives huge performance gain, probably because of ReverseDiff's pre-compilation of the code (see discussion here JuliaDiff/ReverseDiff.jl#102)

@willtebbutt
Copy link
Member

Currently assume and observe do in-place operations and not in-place operations at the same time More precisely, they change the VarInfo variable and also return values that are used later on. This is inconsistent and might lead to strange behaviour. I would prefer to make this consistent and ensure that all operations are either in-place or not. I feel the mixed behaviour is not very clean. See for example:

I don't know how straightforward it will be to move towards immutability using the current VarInfo design, which is entirely formulated entirely around mutation. I do not believe that the current mutating design is a good choice for a number of reasons, however, it will be a substantial amount of work to move away from it. Consequently, the only viable resolution to your concern at the minute is to do everything via mutation. On the other hand, how much of an issue actually is this? I'm not aware of any conventions that advocate for avoiding it, although I do agree that it's not the most obvious design.

Also bear in mind that we're not getting the performance gains anymore as we're not using ReverseDiff (not that we should be relying on our AD to achieve good performance).

@yebai yebai mentioned this issue Feb 19, 2019
56 tasks
@yebai
Copy link
Member

yebai commented Jul 4, 2019

Assume and observe dispatch on the sampler type (which is fine) but also on Nothing. This forces us to pass nothing to the functions if no sampler is defined and have a Union{Nothing, Sampler} for the model functions. I think we can circumvent this by having different function signatures, one with and one without the sampler argument. Or do I miss something here?

This is fixed by #706

Currently assume and observe do in-place operations and not in-place operations at the same time More precisely, they change the VarInfo variable and also return values that are used later on. This is inconsistent and might lead to strange behaviour. I would prefer to make this consistent and ensure that all operations are either in-place or not. I feel mixed behaviour is not very clean. See for example:

This is still not fixed. Maybe we can address this after #750

@yebai
Copy link
Member

yebai commented Nov 25, 2019

Closed by #995

@yebai yebai closed this as completed Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants