-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reusing function in pymc.compute_log_likelihood
#7073
Comments
|
All PyMC Model functions are recompiled everytime, including when you call pm.sample (or sample_posterior_predictive) multiple times with the same model. It's not trivial to know whether a model has changed of if the function we are requesting is equivalent to another that was requested in the past. The compiled function itself is pretty simple to obtain: pymc/pymc/stats/log_likelihood.py Lines 83 to 87 in 118be0f
What's a bit tricky is that transformed variables are not available in the trace. from pymc.model.conditioning import remove_value_transforms
model_wo_transforms = remove_value_transforms(model)
fn = model_wo_transforms.compile_fn(...)
# Reuse fn... Then there's a bit of boilerplate to map a function over a trace that we could provide to users |
pymc.compute_log_likelihood
calls compile_fn
every timepymc.compute_log_likelihood
@ricardoV94 That would be a very useful addition in the case where the model has not changed! Maybe a way could be even to pass the compiled function to the |
Closing this is favor of #7177 Thanks for bringing this up! |
Describe the issue:
Calling
pymc.compute_log_likelihood
multiple times on the same model leads to multiple compilations viacompile_fn
. This is a time sink (in some applications) that could easily be solved by storing the compiled function.Reproduceable code example:
Error message:
No response
PyMC version information:
pymc==5.10.1
Context for the issue:
In a research application I am writing, I need to call
pymc.compute_log_likelihood
many times (sometimes refitting the model in between). The calls tocompile_fn
take up to 60% of my computation time. If this could be easily fixed, it would be extremely helpful for me. Thank you very much in advance!The text was updated successfully, but these errors were encountered: