- 
                Notifications
    You must be signed in to change notification settings 
- Fork 230
Description
On each MCMC iteration, Prior executes the model twice: once to get the varinfo, and once when later constructing the Transition from the varinfo.
Lines 8 to 21 in 937ea9c
| function AbstractMCMC.step( | |
| rng::Random.AbstractRNG, | |
| model::DynamicPPL.Model, | |
| sampler::DynamicPPL.Sampler{<:Prior}, | |
| state=nothing; | |
| kwargs..., | |
| ) | |
| # TODO(DPPL0.37/penelopeysm): replace with init!! | |
| sampling_model = DynamicPPL.contextualize( | |
| model, DynamicPPL.SamplingContext(rng, DynamicPPL.SampleFromPrior(), model.context) | |
| ) | |
| _, vi = DynamicPPL.evaluate!!(sampling_model, VarInfo()) | |
| return Transition(model, vi, nothing), nothing | |
| end | 
The second re-evaluation is not necessary because the first one should be able to obtain all the necessary info already as long as it has all the right accumulators.
This should definitely be fixed. I'm not entirely sure how: maybe Transition needs an opt-in flag to indicate "do not re-evaluate" (feels safer to me because then you can enable it if and only if you're dead certain that you don't need to re-evaluate), or maybe it should not re-evaluate if the varinfo already has the right accumulators (feels a bit dangerous because maybe the accumulators have the wrong value).