|
6 | 6 | from gepa import GEPAResult, optimize |
7 | 7 |
|
8 | 8 | from dspy.clients.lm import LM |
9 | | -from dspy.dsp.utils.settings import settings |
10 | 9 | from dspy.primitives import Example, Module, Prediction |
11 | 10 | from dspy.teleprompt.teleprompt import Teleprompter |
12 | 11 |
|
@@ -199,7 +198,7 @@ def metric( |
199 | 198 | Reflection based configuration: |
200 | 199 | - reflection_minibatch_size: The number of examples to use for reflection in a single GEPA step. |
201 | 200 | - candidate_selection_strategy: The strategy to use for candidate selection. Default is "pareto", which stochastically selects candidates from the Pareto frontier of all validation scores. |
202 | | - - reflection_lm: The language model to use for reflection. If not provided, student's LM is used, or dspy.settings.lm is used. |
| 201 | + - reflection_lm: [Required] The language model to use for reflection. GEPA benefits from a strong reflection model, and you can use `dspy.LM(model='gpt-5', temperature=1.0, max_tokens=32000)` to get a good reflection model. |
203 | 202 |
|
204 | 203 | Merge-based configuration: |
205 | 204 | - use_merge: Whether to use merge-based optimization. Default is True. |
@@ -273,7 +272,9 @@ def __init__( |
273 | 272 | # Reflection based configuration |
274 | 273 | self.reflection_minibatch_size = reflection_minibatch_size |
275 | 274 | self.candidate_selection_strategy = candidate_selection_strategy |
276 | | - self.reflection_lm = reflection_lm |
| 275 | + # self.reflection_lm = reflection_lm |
| 276 | + assert reflection_lm is not None, "GEPA requires a reflection language model to be provided. Typically, you can use `dspy.LM(model='gpt-5', temperature=1.0, max_tokens=32000)` to get a good reflection model. Reflection LM is used by GEPA to reflect on the behavior of the program and propose new instructions, and will benefit from a strong model." |
| 277 | + self.reflection_lm = lambda x: reflection_lm(x)[0] |
277 | 278 | self.skip_perfect_score = skip_perfect_score |
278 | 279 | self.add_format_failure_as_feedback = add_format_failure_as_feedback |
279 | 280 |
|
@@ -409,7 +410,7 @@ def feedback_fn( |
409 | 410 | rng=rng, |
410 | 411 | ) |
411 | 412 |
|
412 | | - reflection_lm = lambda x: (self.reflection_lm or settings.lm or student.get_lm())(x)[0] |
| 413 | + reflection_lm = self.reflection_lm |
413 | 414 |
|
414 | 415 | # Instantiate GEPA with the simpler adapter-based API |
415 | 416 | base_program = {name: pred.signature.instructions for name, pred in student.named_predictors()} |
|
0 commit comments