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

Allow user to disable unnecessary model evaluations after #2202

Open torfjelde opened this issue 1 year ago • 5 comments

After #2202 we will perform one additional evaluation per MCMC iteration than before.

In most use-cases we and users encounter in practice, this is negligible compared to the inference itself, e.g. when using NUTS, but in some cases it can be a significant increase in computational cost.

Unfortunately this is necessary to support "all" possible models and stealthy bugs causing incorrect results in some cases, e.g. see referenced issues in #2202. But IMO we should also provide the user a way to turn this off, as it is not required for most models encountered in practice.

One simple way of doing this is to let the user tell Turing.jl that "hey, this model is 'static' (in some sense), so perform optimizations where you can". At the moment, this would have to be done by the user manually, e.g. by setting a variable attached to the Model itself telling us that it has static support, etc., which is not ideal, but I don't really see a way around it in the near future (long-term we can definitely do better, e.g. analyze the IR in the model).

I'm of the opinion that adding something like this now is worth it, because I know I would personally be annoyed if I'm forced to perform redundant operations when my model does not require it, without an easy way to turn it off. But I know there are other opinions floating around regarding this.

Thoughts? @devmotion @yebai @sunxd3

torfjelde avatar May 06 '24 13:05 torfjelde

Can we simply pass an additional argument to the sample function, e.g. sample(;is_static=true)?

yebai avatar May 06 '24 13:05 yebai

For HMC, this is per MCMC proposal instead of per leapfrog iteration, right?

yebai avatar May 06 '24 13:05 yebai

Can we simply pass an additional argument to the sample function, e.g. sample(;is_static=true)?

Technically possible, but this will be very invasive as it requires propagating kwargs through sooo much of the Turing.jl code base. I started out doing this in an attempt to add this and then just gave up because it got so unwieldy.

torfjelde avatar May 06 '24 13:05 torfjelde

I am checking out the has_static_support stuff, but it's removed. Tor are you suggesting some similar mechanism?

sunxd3 avatar May 06 '24 15:05 sunxd3

Exactly:)

torfjelde avatar May 06 '24 16:05 torfjelde