-
Notifications
You must be signed in to change notification settings - Fork 230
Actually perform iteration with DynamicHMC #1186
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
Conversation
| if Int === Int64 && Pkg.installed()["DynamicHMC"].major == 2 | ||
| include("contrib/inference/dynamichmc.jl") | ||
| end | ||
| include("contrib/inference/dynamichmc.jl") |
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.
Pkg.installed is deprecated on Julia 1.4. I assume that it is unlikely that anyone will run the tests with DynamicHMC < 2 and according to the comment the bug (?) was observed on 32bit with DynamicHMC < 2, so I guess it should be safe to remove the check completely.
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.
Happy to remove this check.
I just noticed that it won't be possible even with these changes since we deliberately only save the samples and their log probability (the full transition is only kept until the next step is performed). However, that means that the resulting Chains object is not sufficient for resuming sampling (the same is true for Gibbs sampling BTW). In general, I think to base resuming on a |
|
Maybe we could just |
Maybe |
|
We could do that but I'm a bit worried that I guess we would have to silently remove the transition if the last sample of the chain is modified or removed. Maybe it should be more explicit, maybe we need an alternative to |
|
Perhaps it could be added to |
|
I like that! But still it wouldn't resolve the issue that you might lose the ability to resume sampling at some point without noticing, would it? |
|
Maybe the only time would be chain saving/loading, but that needs to be overhauled to use JLD2 or something better than what we have now. Chain subsetting would just carry over One "pie in the sky" way to solve this, which is a very big way to solve this, is to just remove the entire axis array setup, and just store all the raw |
Sure, that's something one could do, similar to just specifying Maybe that shouldn't be included in the transitions at all but rather we should have something like |
|
Did you want to park this until #31 goes through, or merge it over an revisit it if the tooling there makes it into AbstractMCMC? I'm fine with this code as-is. |
|
Also do you have any idea what the performance drop is due to not running all the samples at once? |
2661769 to
701f5d2
Compare
|
Shall we give this PR another try? |
|
I'd say it's more reasonable to open a new PR that upgrades the DynamicHMC sampler (and probably the other samplers at the same time?) to the proposed interface in TuringLang/AbstractMCMC.jl#42, if we agree on it. I wanted to update the AbstractMCMC integration in DynamicPPL and Turing first before merging that PR, to see if it causes any problems (shouldn't be the case but I assumed it would be better to check it first). I kept this PR open mainly as a reminder to fix the integration. |
|
Closed in favour of #1497. |
So far, sampling with DynamicHMC just calls DynamicHMC and obtains all samples before any sampling step in Turing is performed. In each sampling step in Turing, we then just pop one sample and save it in a Transition.
This approach has some clear disadvantages, such as being memory inefficient, invalidating any progress logging in Turing, not being able to resume sampling, and also not being able to perform sampling until a convergence criterion is met (not supported in Turing yet but supported in AbstractMCMC).
The disadvantage of making use of the iteration interface in DynamicHMC is that the interface is not part of the official API and hence allowed to break at any time.
In principle, it would be trivial to update the log density function (which is now implemented more clearly as a callable struct that wraps the model and the sampler instead of wrapping a closure) in the sampling step to support (some kind of) Gibbs sampling. It is not included yet since I'm not sure how reasonable it would be to that without adapting the step size and/or the metric of the HMC algorithm (or how they could be updated using DynamicHMC).