DSPy: The framework for programming—not prompting—language models
Python
Update module structural equivalency check to use named_predictors
dilara87e837092114
diff --git a/dspy/predict/predict.py b/dspy/predict/predict.pyindex bbe0ea943..bc37b7cb5 100644--- a/dspy/predict/predict.py+++ b/dspy/predict/predict.py@@ -31,6 +31,7 @@ class Predict(Module, Parameter):return False# Check if the predictors have matching signatures+ # TODO: Can we ensure that all the signatures implement the equals method?err_msg = f"Signatures of the two predictors do not match. {type(self.signature)} != {type(other.signature)}"if hasattr(self.signature, "equals"):return self.signature.equals(other.signature), err_msgdiff --git a/dspy/primitives/program.py b/dspy/primitives/program.pyindex b2bcd82f6..8446c75a3 100644--- a/dspy/primitives/program.py+++ b/dspy/primitives/program.py@@ -19,6 +19,7 @@ class ProgramMeta(type):# return obj+# TODO: Replace print statements with loggingclass Module(BaseModule, metaclass=ProgramMeta):def _base_init(self):self._compiled = False@@ -47,8 +48,8 @@ class Module(BaseModule, metaclass=ProgramMeta):return False# Check if the two modules have structurally equivalent predictors- for (name1, pred1), (name2, pred2) in zip(self.named_parameters(), other.named_parameters()):- if name1 != name2 or not pred1.is_structurally_equivalent(pred2):+ for (name1, pred1), (name2, pred2) in zip(self.named_predictors(), other.named_predictors()):+ if name1 != name2 or not pred1._is_structurally_equivalent(pred2):return Falsereturn True@@ -115,12 +116,12 @@ class Module(BaseModule, metaclass=ProgramMeta):"""if dspy.settings.lm is not None:err_msg = "LM consistency property violated: LM is set in a module predictor when dspy.settings.lm is set."- if not self.is_all_predictor_lms_unset():+ if not self._is_all_predictor_lms_unset():self._print_lm_information()raise AssertionError(err_msg)else:err_msg = "LM consistency property violated: LM is not set in a module predictor when dspy.settings.lm is None."- if not self.is_all_predictor_lms_unset():+ if not self._is_all_predictor_lms_unset():self._print_lm_information()raise AssertionError(err_msg)@@ -176,4 +177,4 @@ class Module(BaseModule, metaclass=ProgramMeta):def set_attribute_by_name(obj, name, value):magicattr.set(obj, name, value)-Program = Module\ No newline at end of file+Program = Module