Skip to content

Model can keep track of whether or not there are := statements #1349

Description

@penelopeysm

When parsing the model, if we encounter any := statements we could store a flag on the model. This is because, in general, if you need to calculate the value of some := statement, the only reliable way is to re-execute the model. In contrast, if you only need parameters in ~ statements, you could sometimes get away with not evaluating the model (e.g. if the values are already stored in some other format).

In particular, I'm thinking of this case:

DynamicPPL.jl/src/chains.jl

Lines 175 to 186 in 157e5f6

# Specialisation for when the LDF is known to have all fixed transforms
function ParamsWithStats(
param_vector::AbstractVector,
ldf::LogDensityFunction{M,A,L,F,V,D,X,C,true},
stats::NamedTuple=NamedTuple();
include_colon_eq::Bool=true,
include_log_probs::Bool=true,
) where {M,A,L,F,V,D,X,C}
if include_log_probs || include_colon_eq
return pws_with_eval(param_vector, ldf, stats; include_colon_eq, include_log_probs)
end
# Fast path: extract raw values directly from the parameter vector using the fixed

If include_colon_eq is true, then we conservatively rerun the model. However, if the model has no := statements, then we technically don't need to.

This is a bit of a minor optimisation though and probably not very urgent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions