-
Notifications
You must be signed in to change notification settings - Fork 246
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
Ability to start MCMC sampling from the same warmup state #469
Conversation
@fehiepsi - let me know if you have other suggestions on how to achieve this. |
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.
This however requires much more refactoring
I think it is valuable and I prefer doing so. With that, we don't need to have reuse_warmup
, so the way to achieve a similar result will be
mcmc = MCMC(NUTS(model), num_warmup, 0)
mcmc.run()
mcmc.num_samples = 1000
mcmc.run()
In addition, I prefer to name it current_state
than init_state
.
I think you'll need to also set I tried doing this, but this adds unneeded complexity to |
@neerajprad To bypass the restriction
and in MCMC._single_chain_mcmc
I tested that this works with funnel example. |
Thanks for your suggestion, @fehiepsi. I'm also noticing another issue. I'll address these, and ping you again for a review. 😄 |
Re setting num_warmup=0: I believe we can use |
This isn't too important though; I think |
I meant we don't need to set
To achieve that, we can change the lower/upper of fori_collect in MCMC to be (modulo multi-chains)
This way, we can set num_samples = 1000; then later we can set num_samples = 10000 to run the remaining 9000 steps. (of course after collecting the new 9000 states, we concatenate with the current 1000 samples (instead of replacing it). |
Okay, let me refactor based on your suggestions first, and post an update. |
@fehiepsi - Regarding your last point, I think we still need the |
Yeah, that's tricky. With that, May I suggest another name for the flag: |
I suppose
You mean change |
Yeah, this is a better name for me. Please forget about Btw, I think you need to deal with multi-chains ;). |
Yes, I do realize that it might be important for certain use cases. And as you mention, we would rather have some users request it first before adding it in.
I'll take a look. 😅 |
@fehiepsi - I didn't see anything immediately wrong with multiple chains, and I enabled this in the smoke test, which should pass. Let me know if I missed something. |
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.
Looks great! :D multi-chain should work with the current implementation (I thought that init_state = init_state[0] selects the first chain of multi-chain...).
@neerajprad Can I merge this now? |
Yes, lets merge this. If there are any follow-up issues, I'll put up a separate PR. |
Addresses #467.
This introduces a
return_init_state
argument tofori_collect
, which ifTrue
returns thelower-1
state. This is used by thereuse_warmup
argument toMCMC.run
as follows:This pattern can probably be improved - in particular
num_samples=1
seems a bit odd. Ideally, we should makenum_samples=0
by default in which case running mcmc without num_samples argument will simply compile the model and store the initial state from warmup. This however requires much more refactoring, whose value is questionable at the moment. If this turns out to be a useful pattern, we can make this prettier.