Skip to content
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

[Need fix] after generator went through optimization update, the pickle state does not work any more #192

Open
liyin2015 opened this issue Sep 1, 2024 · 1 comment

Comments

@liyin2015
Copy link
Collaborator

# pickle file

# save the serialized states to a file
from adalflow.utils.file_io import save_pickle
states = doc.to_dict()
# save_json(states, "doc.json")
save_pickle(states, "doc.pkl")

# load the serialized states from a file
from adalflow.utils.file_io import load_pickle
states_loaded = load_pickle("doc.pkl")

print(states_loaded == states)

doc_pickle = DocQA.from_dict(states_loaded)

AttributeError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/adalflow/utils/file_io.py in save_pickle(obj, f)
64 with open(f, "wb") as file:
---> 65 pickle.dump(obj, file)
66 except Exception as e:

AttributeError: Can't pickle local object 'Generator.set_data_map_func..default_map_func'

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)
1 frames
/usr/local/lib/python3.10/dist-packages/adalflow/utils/file_io.py in save_pickle(obj, f)
65 pickle.dump(obj, file)
66 except Exception as e:
---> 67 raise Exception(f"Error saving object to pickle file {f}: {e}")
68
69

Exception: Error saving object to pickle file doc.pkl: Can't pickle local object 'Generator.set_data_map_func..default_map_func'

Will need to have a customized to_dict and 'from_dict` so that we can exclude unpicklable object and restore it at from_dict loading

@sameeramin
Copy link

@liyin2015 Does this issue persist? I'm unable to reproduce it. Could you please add a bit more steps to reproduce this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants