Skip to content

Skip extra re-evaluation with Prior #2641

@penelopeysm

Description

@penelopeysm

On each MCMC iteration, Prior executes the model twice: once to get the varinfo, and once when later constructing the Transition from the varinfo.

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions