Skip to content

Commit 5682a53

Browse files
better message
1 parent 691ab10 commit 5682a53

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dspy/predict/predict.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def load_state(self, state, use_legacy_loading=False):
6868
if use_legacy_loading:
6969
self._load_state_legacy(state)
7070
return
71+
if "signature" not in state and ("signature_instructions" in state or "signature_prefix" in state):
72+
# Check if the state is from a version of DSPy prior to v2.5.3.
73+
raise ValueError(
74+
"The saved state is from a version of DSPy prior to v2.5.3. Please use `use_legacy_loading=True` to "
75+
"load the state."
76+
)
77+
7178
excluded_keys = ["signature", "extended_signature"]
7279
for name, value in state.items():
7380
# `excluded_keys` are fields that go through special handling.

dspy/primitives/module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,17 @@ def dump_state(self, save_verbose):
152152
print(self.named_parameters())
153153
return {name: param.dump_state(save_verbose) for name, param in self.named_parameters()}
154154

155-
def load_state(self, state):
155+
def load_state(self, state, use_legacy_loading=False):
156156
for name, param in self.named_parameters():
157-
param.load_state(state[name])
157+
param.load_state(state[name], use_legacy_loading=use_legacy_loading)
158158

159159
def save(self, path, save_field_meta=False):
160160
with open(path, "w") as f:
161161
f.write(ujson.dumps(self.dump_state(save_field_meta), indent=2))
162162

163-
def load(self, path):
163+
def load(self, path, use_legacy_loading=False):
164164
with open(path) as f:
165-
self.load_state(ujson.loads(f.read()))
165+
self.load_state(ujson.loads(f.read()), use_legacy_loading=use_legacy_loading)
166166

167167

168168
def postprocess_parameter_name(name, value):

0 commit comments

Comments
 (0)