Skip to content

Commit 8388495

Browse files
Change how forward is patched to avoid warning on explicit forward call (stanfordnlp#8700)
* Suppress warning on patch * different patch
1 parent 3b53ba1 commit 8388495

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

dspy/teleprompt/bootstrap_trace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def wrapped_metric(example, prediction, trace=None):
5555
return prediction.format_reward or format_failure_score
5656
return metric(example, prediction, trace) if metric else True
5757

58-
original_forward = program.forward
58+
# Use `object.__getattribute__` to bypass the custom hook `Module.__getattribute__` so that we avoid
59+
# the warning that `forward` is not accessed through `__call__`.
60+
original_forward = object.__getattribute__(program, "forward")
5961

6062
def patched_forward(program_to_use: Module, **kwargs):
6163
with dspy.context(trace=[]):

0 commit comments

Comments
 (0)