-
Notifications
You must be signed in to change notification settings - Fork 37
Closed
Description
I am actually quite stumped as to why @allocated behaves differently compared to Chairmarks.
module Foo
using DynamicPPL, Distributions, Chairmarks, LogDensityProblems
@model function f()
x ~ Normal()
1.0 ~ Normal(x)
end
@model function submodel_inner()
m ~ Normal(0, 1)
s ~ Exponential()
return (m=m, s=s)
end
@model function submodel_outer()
params ~ to_submodel(submodel_inner())
y ~ Normal(params.m, params.s)
1.0 ~ Normal(y)
end
for model in (f(), submodel_inner(), submodel_outer())
vi = VarInfo(model)
fldf = DynamicPPL.Experimental.FastLDF(model, DynamicPPL.getlogjoint_internal, vi)
x = vi[:]
LogDensityProblems.logdensity(fldf, x) # force compilation
println(median(@be LogDensityProblems.logdensity(fldf, x)).allocs)
println(@allocations LogDensityProblems.logdensity(fldf, x))
end
endprints 0.0, 2, 0.0, 2, 0.0, 2.
The 2 allocations come from not interpolating fldf and x (verifiable by running @allocations fldf and @allocations x, which each return 1). So far so good.
But then if you replace the module with @testset, it prints: 0.0, 2, 0.0, 2, 28.0, 29!
Not sure if this relates to #1127.
Metadata
Metadata
Assignees
Labels
No labels