Turing.jl icon indicating copy to clipboard operation
Turing.jl copied to clipboard

rdcache not cleared while using MLE,MAP estimation

Open BlackWingedKing opened this issue 5 years ago • 3 comments

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

BlackWingedKing avatar Sep 28 '20 04:09 BlackWingedKing

@mohamed82008 @devmotion

BlackWingedKing avatar Sep 28 '20 04:09 BlackWingedKing

Hmm I think we can empty the cache automatically after sampling.

mohdibntarek avatar Sep 28 '20 04:09 mohdibntarek

It would be interesting to understand why this is happening, it is definitely not intended.

devmotion avatar Sep 28 '20 08:09 devmotion

Fixed by https://github.com/TuringLang/Turing.jl/pull/1877

yebai avatar Nov 12 '22 20:11 yebai