synth-optimizers 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. synth_optimizers-0.1.0/LICENSE +176 -0
  2. synth_optimizers-0.1.0/PKG-INFO +243 -0
  3. synth_optimizers-0.1.0/README.md +229 -0
  4. synth_optimizers-0.1.0/pyproject.toml +23 -0
  5. synth_optimizers-0.1.0/setup.cfg +4 -0
  6. synth_optimizers-0.1.0/src/gepa/__init__.py +5 -0
  7. synth_optimizers-0.1.0/src/prompt_opt/__init__.py +16 -0
  8. synth_optimizers-0.1.0/src/prompt_opt/adapters/__init__.py +18 -0
  9. synth_optimizers-0.1.0/src/prompt_opt/adapters/synth_container.py +170 -0
  10. synth_optimizers-0.1.0/src/prompt_opt/adapters/synth_offline.py +81 -0
  11. synth_optimizers-0.1.0/src/prompt_opt/dspy/__init__.py +5 -0
  12. synth_optimizers-0.1.0/src/prompt_opt/dspy/gepa.py +5 -0
  13. synth_optimizers-0.1.0/src/prompt_opt/dspy/miprov2.py +281 -0
  14. synth_optimizers-0.1.0/src/prompt_opt/gepa_ai_compat.py +225 -0
  15. synth_optimizers-0.1.0/src/prompt_opt/mipro.py +114 -0
  16. synth_optimizers-0.1.0/src/prompt_opt/sdk/__init__.py +2 -0
  17. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/__init__.py +14 -0
  18. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/__init__.py +2 -0
  19. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/configs/__init__.py +16 -0
  20. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/configs/prompt_learning.py +230 -0
  21. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/configs/shared.py +12 -0
  22. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/prompt_learning.py +302 -0
  23. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/runtime.py +1465 -0
  24. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/internal/utils.py +29 -0
  25. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/models.py +71 -0
  26. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/policy/__init__.py +6 -0
  27. synth_optimizers-0.1.0/src/prompt_opt/sdk/optimization/policy/v1.py +470 -0
  28. synth_optimizers-0.1.0/src/synth_optimizers.egg-info/PKG-INFO +243 -0
  29. synth_optimizers-0.1.0/src/synth_optimizers.egg-info/SOURCES.txt +32 -0
  30. synth_optimizers-0.1.0/src/synth_optimizers.egg-info/dependency_links.txt +1 -0
  31. synth_optimizers-0.1.0/src/synth_optimizers.egg-info/requires.txt +1 -0
  32. synth_optimizers-0.1.0/src/synth_optimizers.egg-info/top_level.txt +2 -0
  33. synth_optimizers-0.1.0/tests/test_local_offline_sdk.py +263 -0
  34. synth_optimizers-0.1.0/tests/test_mipro.py +157 -0
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: synth-optimizers
3
+ Version: 0.1.0
4
+ Summary: Apache-2.0 prompt optimization package with GEPA and MIPRO adapters.
5
+ Author: Synth
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/synth-laboratories/optimizers
8
+ Project-URL: Repository, https://github.com/synth-laboratories/optimizers
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pydantic<3,>=2
13
+ Dynamic: license-file
14
+
15
+ # synth-optimizers
16
+
17
+ Apache-2.0 licensed Python-only prompt optimization package that provides a local offline mirror of the public Synth GEPA/MIPRO SDK surfaces under `prompt_opt.sdk.optimization.*`.
18
+
19
+ Repo name: `optimizers`
20
+
21
+ PyPI distribution name: `synth-optimizers`
22
+
23
+ Python import package: `prompt_opt`
24
+
25
+ ## What is included
26
+
27
+ - `prompt_opt.sdk.optimization.policy.v1.PolicyOptimizationOfflineJob`
28
+ - Local drop-in offline job surface for `gepa_offline` and `mipro_offline`.
29
+ - `prompt_opt.sdk.optimization.internal.prompt_learning.PromptLearningJob`
30
+ - High-level local prompt-learning wrapper with candidate/state accessors.
31
+ - `prompt_opt.sdk.optimization.internal.configs.prompt_learning.PromptLearningConfig`
32
+ - Canonical prompt-learning config models with local `proxied -> retrieved` normalization.
33
+ - `prompt_opt.dspy.MIPROv2`
34
+ - DSPy-compatible local MIPRO wrapper routed through the mirrored offline SDK.
35
+ - `prompt_opt.dspy.gepa`
36
+ - GEPA slot-in wrapper routed through the same local offline runtime.
37
+ - `prompt_opt.adapters.synth_container`
38
+ - Container request/response helpers for local rollout integration.
39
+ - `src/gepa/__init__.py`
40
+ - Import compatibility shim so `import gepa` works against this package.
41
+
42
+ ## Install (editable, local)
43
+
44
+ ```bash
45
+ cd optimizers
46
+ pip install -e .
47
+ ```
48
+
49
+ ## Quick usage
50
+
51
+ ```python
52
+ from prompt_opt.sdk.optimization.policy.v1 import PolicyOptimizationOfflineJob
53
+
54
+ def task_model(prompt: str) -> str:
55
+ if "Return exactly one of" in prompt:
56
+ return "paris"
57
+ return "rome"
58
+
59
+ job = PolicyOptimizationOfflineJob.create(
60
+ kind="mipro_offline",
61
+ system_name="cities-local",
62
+ backend_url="local://prompt-opt",
63
+ api_key="local",
64
+ config={
65
+ "prompt_learning": {
66
+ "algorithm": "mipro",
67
+ "execution_mode": "retrieved",
68
+ "task_data": {
69
+ "train_examples": [{"input": "Capital of France?", "answer": "paris"}],
70
+ "validation_examples": [{"input": "Capital of France?", "answer": "paris"}],
71
+ },
72
+ "mipro": {
73
+ "initial_candidate": {
74
+ "stages": [
75
+ {
76
+ "id": "main",
77
+ "name": "main",
78
+ "messages": [
79
+ {"role": "system", "pattern": "Answer the question.", "order": 0},
80
+ {"role": "user", "pattern": "{input}", "order": 1},
81
+ ],
82
+ }
83
+ ]
84
+ },
85
+ "num_candidates": 4,
86
+ "max_iterations": 3,
87
+ },
88
+ "local_runtime": {"task_model": task_model},
89
+ }
90
+ },
91
+ )
92
+
93
+ result = job.stream_until_complete(timeout=30.0, interval=0.05)
94
+ best_candidate = job.get_state_envelope()["state"]["candidates"][result["best_candidate_id"]]
95
+ print(best_candidate["candidate_content"])
96
+ ```
97
+
98
+ ## GEPA shim
99
+
100
+ ```python
101
+ from gepa import optimize
102
+ from prompt_opt.adapters.synth_offline import LocalEvaluator, SynthOfflineLearningAdapter
103
+
104
+ def score_fn(example, candidate):
105
+ expected = str(example.get("answer", "")).strip().lower()
106
+ prompt = " ".join(candidate.values()).lower()
107
+ return 1.0 if expected and expected in prompt else 0.0
108
+
109
+ adapter = SynthOfflineLearningAdapter(LocalEvaluator(score_fn=score_fn))
110
+ result = optimize(
111
+ seed_candidate={"system_prompt": "Answer briefly."},
112
+ trainset=[{"input": "Capital of France?", "answer": "paris"}],
113
+ adapter=adapter,
114
+ max_metric_calls=8,
115
+ )
116
+
117
+ print(result.best_candidate)
118
+ print(result.val_aggregate_scores[result.best_idx])
119
+ ```
120
+
121
+ ## Notes
122
+
123
+ - This package is local-only and does not call Synth backend APIs.
124
+ - Runtime execution is retrieval-based only. Hosted configs that specify `execution_mode="proxied"` are accepted and normalized to `retrieved` locally.
125
+ - The local runtime mirrors candidate/state/result payloads and offline job methods; `backend_url` and `api_key` are kept for signature parity but are inert in local mode.
126
+ - Multi-stage candidates are first-class in both local GEPA and local MIPRO.
127
+
128
+ ## Examples
129
+
130
+ - Local DSPy MIPRO:
131
+ - `examples/mipro_local_example.py`
132
+ - DSPy GEPA slot-in:
133
+ - `examples/dspy_gepa_slot_example.py`
134
+ - Local offline Banking77 via Synth `InProcessContainer`:
135
+ - `examples/banking77_container_example.py`
136
+ - Local offline GEPA for simple JSONL task files:
137
+ - `examples/gepa_taskfile_container_eval.py`
138
+
139
+ Run the Banking77 local regression harness with:
140
+
141
+ ```bash
142
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
143
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/banking77_container_example.py \
144
+ --algorithms gepa mipro \
145
+ --train-per-label 4 \
146
+ --held-out-per-label 2 \
147
+ --num-generations 2 \
148
+ --children-per-generation 8 \
149
+ --num-candidates 8 \
150
+ --max-iterations 6
151
+ ```
152
+
153
+ The script prints per-algorithm JSON with `train_*` and `held_out_*` metrics and raises if held-out improvement does not exceed `--min-held-out-delta`.
154
+
155
+ Find simple eval task files and run local taskfile optimization (`gepa` or `mipro`) with:
156
+
157
+ ```bash
158
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
159
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
160
+ --list-simple-task-files
161
+ ```
162
+
163
+ ```bash
164
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
165
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
166
+ --algorithm gepa \
167
+ --task-file /Users/joshpurtell/Documents/GitHub/evals/mipro/tasks/multimodal_smoke.jsonl \
168
+ --train-size 8 \
169
+ --num-generations 2 \
170
+ --children-per-generation 8 \
171
+ --total-rollouts 64
172
+ ```
173
+
174
+ ```bash
175
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
176
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
177
+ --algorithm gepa \
178
+ --task-preset medec_smoke \
179
+ --train-size 8 \
180
+ --num-generations 2 \
181
+ --children-per-generation 8 \
182
+ --total-rollouts 64
183
+ ```
184
+
185
+ ```bash
186
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
187
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
188
+ --algorithm mipro \
189
+ --task-preset drugprot_train_public \
190
+ --train-size 8 \
191
+ --num-candidates 24 \
192
+ --max-iterations 16 \
193
+ --children-per-generation 16 \
194
+ --total-rollouts 256
195
+ ```
196
+
197
+ ```bash
198
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
199
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
200
+ --algorithm mipro \
201
+ --task-preset langprobe_banking77 \
202
+ --train-size 32 \
203
+ --num-candidates 12 \
204
+ --max-iterations 8 \
205
+ --children-per-generation 8 \
206
+ --total-rollouts 96
207
+ ```
208
+
209
+ ```bash
210
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
211
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
212
+ --algorithm mipro \
213
+ --task-preset langprobe_hotpotqa \
214
+ --train-size 8 \
215
+ --num-candidates 8 \
216
+ --max-iterations 6 \
217
+ --children-per-generation 8 \
218
+ --total-rollouts 64
219
+ ```
220
+
221
+ ```bash
222
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
223
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
224
+ --algorithm mipro \
225
+ --task-preset langprobe_iris \
226
+ --train-size 60 \
227
+ --num-candidates 10 \
228
+ --max-iterations 8 \
229
+ --children-per-generation 8 \
230
+ --total-rollouts 96
231
+ ```
232
+
233
+ ```bash
234
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
235
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
236
+ --algorithm mipro \
237
+ --task-preset langprobe_hover \
238
+ --train-size 60 \
239
+ --num-candidates 10 \
240
+ --max-iterations 8 \
241
+ --children-per-generation 8 \
242
+ --total-rollouts 96
243
+ ```
@@ -0,0 +1,229 @@
1
+ # synth-optimizers
2
+
3
+ Apache-2.0 licensed Python-only prompt optimization package that provides a local offline mirror of the public Synth GEPA/MIPRO SDK surfaces under `prompt_opt.sdk.optimization.*`.
4
+
5
+ Repo name: `optimizers`
6
+
7
+ PyPI distribution name: `synth-optimizers`
8
+
9
+ Python import package: `prompt_opt`
10
+
11
+ ## What is included
12
+
13
+ - `prompt_opt.sdk.optimization.policy.v1.PolicyOptimizationOfflineJob`
14
+ - Local drop-in offline job surface for `gepa_offline` and `mipro_offline`.
15
+ - `prompt_opt.sdk.optimization.internal.prompt_learning.PromptLearningJob`
16
+ - High-level local prompt-learning wrapper with candidate/state accessors.
17
+ - `prompt_opt.sdk.optimization.internal.configs.prompt_learning.PromptLearningConfig`
18
+ - Canonical prompt-learning config models with local `proxied -> retrieved` normalization.
19
+ - `prompt_opt.dspy.MIPROv2`
20
+ - DSPy-compatible local MIPRO wrapper routed through the mirrored offline SDK.
21
+ - `prompt_opt.dspy.gepa`
22
+ - GEPA slot-in wrapper routed through the same local offline runtime.
23
+ - `prompt_opt.adapters.synth_container`
24
+ - Container request/response helpers for local rollout integration.
25
+ - `src/gepa/__init__.py`
26
+ - Import compatibility shim so `import gepa` works against this package.
27
+
28
+ ## Install (editable, local)
29
+
30
+ ```bash
31
+ cd optimizers
32
+ pip install -e .
33
+ ```
34
+
35
+ ## Quick usage
36
+
37
+ ```python
38
+ from prompt_opt.sdk.optimization.policy.v1 import PolicyOptimizationOfflineJob
39
+
40
+ def task_model(prompt: str) -> str:
41
+ if "Return exactly one of" in prompt:
42
+ return "paris"
43
+ return "rome"
44
+
45
+ job = PolicyOptimizationOfflineJob.create(
46
+ kind="mipro_offline",
47
+ system_name="cities-local",
48
+ backend_url="local://prompt-opt",
49
+ api_key="local",
50
+ config={
51
+ "prompt_learning": {
52
+ "algorithm": "mipro",
53
+ "execution_mode": "retrieved",
54
+ "task_data": {
55
+ "train_examples": [{"input": "Capital of France?", "answer": "paris"}],
56
+ "validation_examples": [{"input": "Capital of France?", "answer": "paris"}],
57
+ },
58
+ "mipro": {
59
+ "initial_candidate": {
60
+ "stages": [
61
+ {
62
+ "id": "main",
63
+ "name": "main",
64
+ "messages": [
65
+ {"role": "system", "pattern": "Answer the question.", "order": 0},
66
+ {"role": "user", "pattern": "{input}", "order": 1},
67
+ ],
68
+ }
69
+ ]
70
+ },
71
+ "num_candidates": 4,
72
+ "max_iterations": 3,
73
+ },
74
+ "local_runtime": {"task_model": task_model},
75
+ }
76
+ },
77
+ )
78
+
79
+ result = job.stream_until_complete(timeout=30.0, interval=0.05)
80
+ best_candidate = job.get_state_envelope()["state"]["candidates"][result["best_candidate_id"]]
81
+ print(best_candidate["candidate_content"])
82
+ ```
83
+
84
+ ## GEPA shim
85
+
86
+ ```python
87
+ from gepa import optimize
88
+ from prompt_opt.adapters.synth_offline import LocalEvaluator, SynthOfflineLearningAdapter
89
+
90
+ def score_fn(example, candidate):
91
+ expected = str(example.get("answer", "")).strip().lower()
92
+ prompt = " ".join(candidate.values()).lower()
93
+ return 1.0 if expected and expected in prompt else 0.0
94
+
95
+ adapter = SynthOfflineLearningAdapter(LocalEvaluator(score_fn=score_fn))
96
+ result = optimize(
97
+ seed_candidate={"system_prompt": "Answer briefly."},
98
+ trainset=[{"input": "Capital of France?", "answer": "paris"}],
99
+ adapter=adapter,
100
+ max_metric_calls=8,
101
+ )
102
+
103
+ print(result.best_candidate)
104
+ print(result.val_aggregate_scores[result.best_idx])
105
+ ```
106
+
107
+ ## Notes
108
+
109
+ - This package is local-only and does not call Synth backend APIs.
110
+ - Runtime execution is retrieval-based only. Hosted configs that specify `execution_mode="proxied"` are accepted and normalized to `retrieved` locally.
111
+ - The local runtime mirrors candidate/state/result payloads and offline job methods; `backend_url` and `api_key` are kept for signature parity but are inert in local mode.
112
+ - Multi-stage candidates are first-class in both local GEPA and local MIPRO.
113
+
114
+ ## Examples
115
+
116
+ - Local DSPy MIPRO:
117
+ - `examples/mipro_local_example.py`
118
+ - DSPy GEPA slot-in:
119
+ - `examples/dspy_gepa_slot_example.py`
120
+ - Local offline Banking77 via Synth `InProcessContainer`:
121
+ - `examples/banking77_container_example.py`
122
+ - Local offline GEPA for simple JSONL task files:
123
+ - `examples/gepa_taskfile_container_eval.py`
124
+
125
+ Run the Banking77 local regression harness with:
126
+
127
+ ```bash
128
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
129
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/banking77_container_example.py \
130
+ --algorithms gepa mipro \
131
+ --train-per-label 4 \
132
+ --held-out-per-label 2 \
133
+ --num-generations 2 \
134
+ --children-per-generation 8 \
135
+ --num-candidates 8 \
136
+ --max-iterations 6
137
+ ```
138
+
139
+ The script prints per-algorithm JSON with `train_*` and `held_out_*` metrics and raises if held-out improvement does not exceed `--min-held-out-delta`.
140
+
141
+ Find simple eval task files and run local taskfile optimization (`gepa` or `mipro`) with:
142
+
143
+ ```bash
144
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
145
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
146
+ --list-simple-task-files
147
+ ```
148
+
149
+ ```bash
150
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
151
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
152
+ --algorithm gepa \
153
+ --task-file /Users/joshpurtell/Documents/GitHub/evals/mipro/tasks/multimodal_smoke.jsonl \
154
+ --train-size 8 \
155
+ --num-generations 2 \
156
+ --children-per-generation 8 \
157
+ --total-rollouts 64
158
+ ```
159
+
160
+ ```bash
161
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
162
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
163
+ --algorithm gepa \
164
+ --task-preset medec_smoke \
165
+ --train-size 8 \
166
+ --num-generations 2 \
167
+ --children-per-generation 8 \
168
+ --total-rollouts 64
169
+ ```
170
+
171
+ ```bash
172
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
173
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
174
+ --algorithm mipro \
175
+ --task-preset drugprot_train_public \
176
+ --train-size 8 \
177
+ --num-candidates 24 \
178
+ --max-iterations 16 \
179
+ --children-per-generation 16 \
180
+ --total-rollouts 256
181
+ ```
182
+
183
+ ```bash
184
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
185
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
186
+ --algorithm mipro \
187
+ --task-preset langprobe_banking77 \
188
+ --train-size 32 \
189
+ --num-candidates 12 \
190
+ --max-iterations 8 \
191
+ --children-per-generation 8 \
192
+ --total-rollouts 96
193
+ ```
194
+
195
+ ```bash
196
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
197
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
198
+ --algorithm mipro \
199
+ --task-preset langprobe_hotpotqa \
200
+ --train-size 8 \
201
+ --num-candidates 8 \
202
+ --max-iterations 6 \
203
+ --children-per-generation 8 \
204
+ --total-rollouts 64
205
+ ```
206
+
207
+ ```bash
208
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
209
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
210
+ --algorithm mipro \
211
+ --task-preset langprobe_iris \
212
+ --train-size 60 \
213
+ --num-candidates 10 \
214
+ --max-iterations 8 \
215
+ --children-per-generation 8 \
216
+ --total-rollouts 96
217
+ ```
218
+
219
+ ```bash
220
+ PYTHONPATH=/Users/joshpurtell/Documents/GitHub/prompt-opt/src:/Users/joshpurtell/Documents/GitHub/synth-ai \
221
+ uv run --active /Users/joshpurtell/Documents/GitHub/prompt-opt/examples/gepa_taskfile_container_eval.py \
222
+ --algorithm mipro \
223
+ --task-preset langprobe_hover \
224
+ --train-size 60 \
225
+ --num-candidates 10 \
226
+ --max-iterations 8 \
227
+ --children-per-generation 8 \
228
+ --total-rollouts 96
229
+ ```
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "synth-optimizers"
7
+ version = "0.1.0"
8
+ description = "Apache-2.0 prompt optimization package with GEPA and MIPRO adapters."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "Synth" }]
13
+ dependencies = ["pydantic>=2,<3"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://github.com/synth-laboratories/optimizers"
17
+ Repository = "https://github.com/synth-laboratories/optimizers"
18
+
19
+ [tool.setuptools]
20
+ package-dir = { "" = "src" }
21
+
22
+ [tool.setuptools.packages.find]
23
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """Drop-in `gepa` module shim provided by prompt-opt."""
2
+
3
+ from prompt_opt.gepa_ai_compat import LocalGEPAAdapterProtocol, optimize
4
+
5
+ __all__ = ["LocalGEPAAdapterProtocol", "optimize"]