I have a pymc
model that is quite heavy computationally speaking. Following this suggestion I tried to pickle it and unload it every time I need it without recomputing it.
This is my pickling code and it runs fine.
def save_model(features, train_age_scaler, train_cohort_age_scaler,
train_days_m_scaler, model, idata) -> None:
pickle_filepath = f'mypath.pkl'
dict_to_save = {'model': model,
'idata': idata,
'features': features,
'train_age_scaler': train_age_scaler,
'train_cohort_age_scaler': train_cohort_age_scaler,
'train_days_m_scaler': train_days_m_scaler
}
with open(pickle_filepath, 'wb') as buff:
cloudpickle.dump(dict_to_save, buff)
Now the strangest thing happen, if I calculate the whole model from scratch and then pickle it I am also able to unpickle it in the same execution like so
with open(pickle_filepath, 'rb') as buff:
model_dict = cloudpickle.load(buff)
But when I re-execute the program and I try simply to unpickle the file that was created in a previous iteration I get the following error
File "/opt/homebrew/Cellar/[email protected]/3.12.1_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/connection.py", line 518, in Client
c = SocketClient(address)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.1_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/connection.py", line 646, in SocketClient
s.connect(address)
ConnectionRefusedError: [Errno 61] Connection refused
How is this possible?