Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

better message

chenmoneygithub5682a53072e7
diff --git a/dspy/predict/predict.py b/dspy/predict/predict.py
index aa4f2c368..bfe778b74 100644
--- a/dspy/predict/predict.py
+++ b/dspy/predict/predict.py
@@ -68,6 +68,13 @@ class Predict(Module, Parameter):
if use_legacy_loading:
self._load_state_legacy(state)
return
+ if "signature" not in state and ("signature_instructions" in state or "signature_prefix" in state):
+ # Check if the state is from a version of DSPy prior to v2.5.3.
+ raise ValueError(
+ "The saved state is from a version of DSPy prior to v2.5.3. Please use `use_legacy_loading=True` to "
+ "load the state."
+ )
+
excluded_keys = ["signature", "extended_signature"]
for name, value in state.items():
# `excluded_keys` are fields that go through special handling.
diff --git a/dspy/primitives/module.py b/dspy/primitives/module.py
index 5df2b308d..1dee9cbb1 100644
--- a/dspy/primitives/module.py
+++ b/dspy/primitives/module.py
@@ -152,17 +152,17 @@ class BaseModule:
print(self.named_parameters())
return {name: param.dump_state(save_verbose) for name, param in self.named_parameters()}
- def load_state(self, state):
+ def load_state(self, state, use_legacy_loading=False):
for name, param in self.named_parameters():
- param.load_state(state[name])
+ param.load_state(state[name], use_legacy_loading=use_legacy_loading)
def save(self, path, save_field_meta=False):
with open(path, "w") as f:
f.write(ujson.dumps(self.dump_state(save_field_meta), indent=2))
- def load(self, path):
+ def load(self, path, use_legacy_loading=False):
with open(path) as f:
- self.load_state(ujson.loads(f.read()))
+ self.load_state(ujson.loads(f.read()), use_legacy_loading=use_legacy_loading)
def postprocess_parameter_name(name, value):