in Pymc3 I happily saved the trace and the gaussian process object as a pickle file and used it later for predictive checks, predictions, charts etc, e.g.:
with pm.model() as model:
gp = pm.gp.Marginal(cov_func=cov_tot)
y_ = gp.marginal_likelihood('y_', X=X_a, y=y_a, noise=sigma_n)
trace = pm.sample(**bayes_kws)
pickle.dump(obj={'gp': gp, 'trace': trace}, file=out_file)
When I try this now I get the following error:
AttributeError: Can't pickle local object '_make_nice_attr_error.<locals>.fn'
Is this a bug? Or do I have to make the model fresh each time I want to use it? I know I can just load the trace and avoid sampling - that’s not a problem.
I’m using pymc ‘4.0.0b6’, python 3.9 on a mac OS 12.1, in a jupyter notebook.
You can try to use cloudpickle. It’s a drop-in replacement for pickle that’s much more capable. It’s what we use internally in PyMC for multiprocessing at the moment.
Sounds like it could be a library issue. Do you mind opening an issue on our GitHub repository with a minimal fully reproducible example for developers to investigate more easily?
Update here: In the issue, another issue kindly provided the advice to not use pickle from cloudpickle, but rather cloudpickle's own dump` function. This solves the problem for me.