Skip to content

Commit 2624889

Browse files
Add GEPA (Genetic-Pareto) Optimizer (#8624)
* Add GEPA Draft * Add GEPA paper to README * Improve GEPA Interface * Add Instruction Proposal function (commented) * Update imports * Fix README * Add track_best_outputs * Fix auto_budget bug * Fix bug in TraceData type * Fix ruff checks
1 parent 44ba438 commit 2624889

File tree

6 files changed

+724
-2
lines changed

6 files changed

+724
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ If you're looking to understand the framework, please go to the [DSPy Docs at ds
4646
4747
If you're looking to understand the underlying research, this is a set of our papers:
4848

49+
**[Jul'25] [GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning](https://arxiv.org/abs/2507.19457)**
4950
**[Jun'24] [Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs](https://arxiv.org/abs/2406.11695)**
5051
**[Oct'23] [DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines](https://arxiv.org/abs/2310.03714)**
5152
[Jul'24] [Fine-Tuning and Prompt Optimization: Two Great Steps that Work Better Together](https://arxiv.org/abs/2407.10930)

dspy/teleprompt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dspy.teleprompt.bootstrap_finetune import BootstrapFinetune
55
from dspy.teleprompt.copro_optimizer import COPRO
66
from dspy.teleprompt.ensemble import Ensemble
7+
from dspy.teleprompt.gepa.gepa import GEPA
78
from dspy.teleprompt.infer_rules import InferRules
89
from dspy.teleprompt.knn_fewshot import KNNFewShot
910
from dspy.teleprompt.mipro_optimizer_v2 import MIPROv2
@@ -20,6 +21,7 @@
2021
"BootstrapFinetune",
2122
"COPRO",
2223
"Ensemble",
24+
"GEPA",
2325
"KNNFewShot",
2426
"MIPROv2",
2527
"BootstrapFewShotWithRandomSearch",

dspy/teleprompt/bootstrap_finetune.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from collections import defaultdict
33
from dataclasses import dataclass
4-
from typing import Any, Callable
4+
from typing import Any, Callable, TypedDict
55

66
import dspy
77
from dspy.adapters.base import Adapter
@@ -13,6 +13,7 @@
1313
from dspy.predict.predict import Predict
1414
from dspy.primitives.example import Example
1515
from dspy.primitives.module import Module
16+
from dspy.primitives.prediction import Prediction
1617
from dspy.teleprompt.teleprompt import Teleprompter
1718
from dspy.utils.exceptions import AdapterParseError
1819

@@ -220,6 +221,12 @@ class FailedPrediction:
220221
completion_text: str
221222
format_reward: float | None = None
222223

224+
class TraceData(TypedDict):
225+
example_ind: int
226+
example: Example
227+
prediction: Prediction
228+
trace: list[tuple[Any, dict[str, Any], Prediction]]
229+
score: float | None
223230

224231
def bootstrap_trace_data(
225232
program: Module,
@@ -231,7 +238,7 @@ def bootstrap_trace_data(
231238
failure_score: float = 0,
232239
format_failure_score: float = -1,
233240
log_format_failures: bool = False,
234-
) -> list[dict[str, Any]]:
241+
) -> list[TraceData]:
235242
# Return a list of dicts with the following keys: example_ind, example, prediction, trace, and score
236243
# (if metric != None)
237244
evaluator = Evaluate(

0 commit comments

Comments
 (0)