Skip to content

Docs on sub-model workflow for generated quantities, predictions, and performance optimisationsΒ #810

@yebai

Description

@yebai

@torfjelde raised in TuringLang/Turing.jl#2485 (comment) in certain cases, we might want to skip certain variables during inference time, e.g. these variables are for forecasting:

@model function demo_used_for_prediction()
    x ~ Normal()
    # Let's sample some predictions!
    y_predict ~ Normal(x, 1)
end

chain = sample(demo(), sampler, num_samples)
generated_quantities(demo_used_for_prediction(), chain)

I have previously suggested a workflow of (a similar idea is re-suggested by @penelopeysm TuringLang/Turing.jl#2485 (comment))

@model function demo()
    x ~ Normal()
end

chain = sample(demo(), sampler, num_samples)


@model function demo_used_for_prediction()
    x ~ to_submodel(demo())
    # Let's sample some predictions!
    y_predict ~ Normal(x, 1)
end

generated_quantities(demo_used_for_prediction(), chain)

The above works well for forecasting and generated quantities. Is there any extra reason why a functionality like #589 or #510 is needed?

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