Skip to content

Commit 8a2093b

Browse files
committed
updates
1 parent 2d787bf commit 8a2093b

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

eval_protocol/training/gepa_trainer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ def __init__(
153153
module_factory=module_factory,
154154
)
155155

156+
# Debug: Verify program structure
157+
print("\n🔍 DEBUG [GEPATrainer] PROGRAM STRUCTURE:")
158+
print(f" Program type: {type(self.program).__name__}")
159+
print(f" Has .predict: {hasattr(self.program, 'predict')}")
160+
if hasattr(self.program, "predict"):
161+
print(f" predict type: {type(self.program.predict).__name__}")
162+
print(f" predict.signature: {self.program.predict.signature}")
163+
print(
164+
f" predict.signature.instructions (first 300 chars): {(self.program.predict.signature.instructions or '')[:300]}..."
165+
)
166+
print(f" Named predictors: {[name for name, _ in self.program.named_predictors()]}")
167+
for name, pred in self.program.named_predictors():
168+
print(
169+
f" - '{name}': {pred.signature.instructions[:100] if pred.signature.instructions else 'None'}..."
170+
)
171+
156172
# Convert EP rows to DSPy Examples
157173
self.train_set: List[Example] = evaluation_rows_to_dspy_examples(train_rows, input_field, output_field)
158174
self.val_set: List[Example] = evaluation_rows_to_dspy_examples(val_rows, input_field, output_field)
@@ -348,6 +364,20 @@ def train(
348364
marker = " 🏆" if i == results.best_idx else ""
349365
print(f" Candidate {i}: {score:.3f}{marker}")
350366

367+
# Show all candidate instructions
368+
print("\n📝 ALL CANDIDATE INSTRUCTIONS:")
369+
if hasattr(results, "candidates") and results.candidates:
370+
for i, cand_prog in enumerate(results.candidates):
371+
marker = " 🏆 BEST" if i == results.best_idx else ""
372+
print(f"\n --- Candidate {i}{marker} (score: {results.val_aggregate_scores[i]:.3f}) ---")
373+
# Get instructions from the candidate program
374+
for name, pred in cand_prog.named_predictors():
375+
instr = pred.signature.instructions or ""
376+
print(f" Predictor '{name}' instructions (first 500 chars):")
377+
print(f" {instr[:500]}...")
378+
if len(instr) > 500:
379+
print(f" ... ({len(instr)} total chars)")
380+
351381
optimized_instructions = self.get_optimized_system_prompt(optimized_program)
352382
print("\n🎯 OPTIMIZED SYSTEM PROMPT:")
353383
print("-" * 60)

eval_protocol/training/gepa_utils.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def gold_and_pred_to_row(gold: Example, pred: Prediction) -> EvaluationRow:
110110

111111
content = pred.get("answer", "")
112112

113+
# Debug: print conversion details (only first few)
114+
import os
115+
116+
if os.environ.get("EP_DEBUG_GEPA"):
117+
print("\n [gold_and_pred_to_row] Converting:")
118+
print(f" gold.answer type: {type(gt)}, value preview: {str(gt)[:100]}...")
119+
print(f" pred.answer type: {type(content)}, value preview: {str(content)[:100]}...")
120+
113121
return EvaluationRow(
114122
messages=[
115123
Message(role="assistant", content=str(content))
@@ -325,6 +333,14 @@ def create_single_turn_program(
325333
module_factory=lambda sig: MyCustomModule(sig)
326334
)
327335
"""
336+
print("\n" + "⚙️" * 20)
337+
print("DEBUG [create_single_turn_program] CREATING DSPY MODULE")
338+
print("⚙️" * 20)
339+
print(f" input_field: '{input_field}'")
340+
print(f" output_field: '{output_field}'")
341+
print(f" module_type: {module_type}")
342+
print(f" system_prompt (first 200 chars): {(system_prompt or '')[:200]}...")
343+
328344
# Create the signature
329345
sig = create_signature(
330346
input_field=input_field,
@@ -334,8 +350,12 @@ def create_single_turn_program(
334350
output_desc=output_desc,
335351
)
336352

353+
print(f"\n Created signature: {sig}")
354+
print(f" Signature instructions (first 200 chars): {(sig.instructions or '')[:200]}...")
355+
337356
# Use custom factory if provided
338357
if module_factory is not None:
358+
print(" Using custom module factory")
339359
return module_factory(sig)
340360

341361
# Convert string to enum if needed
@@ -344,14 +364,22 @@ def create_single_turn_program(
344364

345365
# Create the appropriate module type
346366
if module_type == DSPyModuleType.PREDICT:
347-
return dspy.Predict(sig)
367+
program = dspy.Predict(sig)
348368
elif module_type == DSPyModuleType.CHAIN_OF_THOUGHT:
349-
return dspy.ChainOfThought(sig)
369+
program = dspy.ChainOfThought(sig)
350370
elif module_type == DSPyModuleType.PROGRAM_OF_THOUGHT:
351-
return dspy.ProgramOfThought(sig)
371+
program = dspy.ProgramOfThought(sig)
352372
else:
353373
raise ValueError(f"Unknown module type: {module_type}")
354374

375+
print(f"\n Created module: {type(program).__name__}")
376+
print(f" Named predictors: {[name for name, _ in program.named_predictors()]}")
377+
for name, pred in program.named_predictors():
378+
print(f" '{name}' signature.instructions (first 200 chars): {(pred.signature.instructions or '')[:200]}...")
379+
print("⚙️" * 20 + "\n")
380+
381+
return program
382+
355383

356384
def configure_dspy_lm(ep_params: EPParameters) -> None:
357385
"""

0 commit comments

Comments
 (0)