Skip to content

computation time of returned scales with number of model parameters #1019

@tiemvanderdeure

Description

@tiemvanderdeure

MWE:

using Turing
@model function mymodel(n)
    x ~ filldist(Normal(), n)
    return x[1]
end

for n in [10, 100, 1000, 10_000]
    mod = mymodel(n)
    chn = sample(mod, Prior(), 10)
    @time returned(mod, chn)
end

gives

  0.000808 seconds (2.95 k allocations: 129.688 KiB)
  0.003559 seconds (14.14 k allocations: 1.431 MiB)
  0.114613 seconds (146.33 k allocations: 81.974 MiB)
  3.866223 seconds (1.66 M allocations: 7.510 GiB, 28.82% gc time)

For models with many parameters returned is basically unusable because of this.

Profview shows that all the computation time is happening in call to DynamicPPL.setval_and_resample! inside the loop that has a TODO

# TODO: Use `fix` once we've addressed https://github.com/TuringLang/DynamicPPL.jl/issues/702.
# Update the varinfo with the current sample and make variables not present in `chain`
# to be sampled.
DynamicPPL.setval_and_resample!(varinfo, chain, sample_idx, chain_idx)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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