Turing.jl
Turing.jl copied to clipboard
rdcache not cleared while using MLE,MAP estimation
I was using MLE, MAP estimation with :reversediff backend and rdcache
The following is the MWE
using Turing,Distributions, Random
using ReverseDiff, Memoization, Optim
println("loaded modules")
Turing.setadbackend(:reversediff)
Turing.setrdcache(true)
@model function mwe(x)
n = length(x)
sigma ~ filldist(Uniform(0.5,1.5), n)
TT = eltype(sigma)
u ~ arraydist(truncated.(Normal.(0, sigma), TT(-4), TT(4)))
x ~ MvNormal(u,1)
end
# generate some fake data
a = rand(2000)
model = mwe(a)
niter = 10
println("starting estimation.....")
for i in 1:niter
optimize(model, MLE())
# Turing.emptyrdcache()
println("estimation done for $(i)")
end
wait()
I could see a significant rise in ram usage of my system per iteration (> 0.5GB)
I'm not sure if this is expected behavior. I have done serial sampling with rdcache enabled and I didn't notice any growth per every iteration.
An easy fix for RAM increase is to clear the rdcache every time using Turing.emptyrdcache
@mohamed82008 @devmotion
Hmm I think we can empty the cache automatically after sampling.
It would be interesting to understand why this is happening, it is definitely not intended.
Fixed by https://github.com/TuringLang/Turing.jl/pull/1877