Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

remove history and callbacks from module saving (#8599)

arnavsinghvi11880d63b5a8d3
diff --git a/dspy/primitives/module.py b/dspy/primitives/module.py
index edf83a8b5..a3cb0e49c 100644
--- a/dspy/primitives/module.py
+++ b/dspy/primitives/module.py
@@ -48,6 +48,19 @@ class Module(BaseModule, metaclass=ProgramMeta):
# LM calling history of the module.
self.history = []
+ def __getstate__(self):
+ state = self.__dict__.copy()
+ state.pop("history", None)
+ state.pop("callbacks", None)
+ return state
+
+ def __setstate__(self, state):
+ self.__dict__.update(state)
+ if not hasattr(self, "history"):
+ self.history = []
+ if not hasattr(self, "callbacks"):
+ self.callbacks = []
+
@with_callbacks
def __call__(self, *args, **kwargs):
caller_modules = settings.caller_modules or []