Making Turing Fast with large numbers of parameters?

Good question, as an aside:

Turing.setrdcache(true)
Turing.setadbackend(:reversediff)

you might want to do these in the opposite order, I’m not sure if it really matters, but the rdcache only exists if you’re using reversediff I assume? so you’d want to be using it before you turn on the cache? Or maybe it doesn’t matter, but I don’t think it could hurt.

When it comes to your model, I’m not at all clear why Model takes a whole vector of ns ?

You might get away with something like

Turing.@addlogprob! sum(logpdf(Model(ns,r[i],g[i]),data[i]) for i in 1:n)

in which case, the autodiff might realize it’s differentiating a sum rather than something more complicated?

It’s also possible the syntax

data ~ [Model(ns,r[i],g[i]) for i in 1:n]

would work as described Advanced Usage

1 Like