Spaces:
Sleeping
Sleeping
Add debug logging to diagnose GEPA candidate generation issue
Browse files- Added INFO level logging to make_reflective_dataset() to confirm if GEPA is calling it
- Added logging when evaluate() is called with capture_traces=True (training minibatch)
- Added GEPA version check
- Added logging to show GEPA's captured output
- This will help identify why GEPA isn't generating new candidates
Files changed (3)
350 unmodified lines351352353354355356357358359350 unmodified lines# Run optimizationtry:logger.info(f"π Starting optimization with model: {final_model}")logger.info(f" Parameters: iterations={max_iterations}, metric_calls={max_metric_calls}, batch={batch_size}, llego={use_llego}")logger.info(f" Dataset size: {len(dataset)} examples")result = quick_optimize_sync(seed_prompt=seed_prompt,350 unmodified lines351352353354355356357358359360361362363364365366367368350 unmodified lines# Run optimizationtry:# Check GEPA version for debuggingif BACKEND_AVAILABLE:try:import gepalogger.info(f"π¦ GEPA library version: {getattr(gepa, '__version__', 'unknown')}")except Exception as e:logger.warning(f"Could not check GEPA version: {e}")logger.info(f"π Starting optimization with model: {final_model}")logger.info(f" Parameters: iterations={max_iterations}, metric_calls={max_metric_calls}, batch={batch_size}, llego={use_llego}")logger.info(f" Dataset size: {len(dataset)} examples")logger.info(f" π GEPA should call: evaluate(capture_traces=True) β make_reflective_dataset() β propose_new_texts()")result = quick_optimize_sync(seed_prompt=seed_prompt,
1007 unmodified lines1008100910101011101210131014101510161007 unmodified linesdef _run_gepa_with_logging(self, gepa_params: Dict[str, Any], output_buffer: io.StringIO) -> Any:"""Run GEPA optimization while capturing its output."""# Capture GEPA's print statements and loggingwith redirect_stdout(output_buffer), redirect_stderr(output_buffer):return gepa.optimize(**gepa_params)def _log_pareto_front_info(self, gepa_logs: str) -> int: # Return int instead of None"""Extract and log pareto front information from GEPA logs. Returns max iteration count."""1007 unmodified lines100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331007 unmodified linesdef _run_gepa_with_logging(self, gepa_params: Dict[str, Any], output_buffer: io.StringIO) -> Any:"""Run GEPA optimization while capturing its output."""self.logger.info("π Calling gepa.optimize() - GEPA should now:")self.logger.info(" 1. Evaluate seed on validation set")self.logger.info(" 2. For each iteration: evaluate on training minibatch (capture_traces=True)")self.logger.info(" 3. Call make_reflective_dataset() with trajectories")self.logger.info(" 4. Call propose_new_texts() or reflection_lm to generate new candidates")self.logger.info(" 5. Evaluate new candidates and update Pareto front")# Capture GEPA's print statements and loggingwith redirect_stdout(output_buffer), redirect_stderr(output_buffer):result = gepa.optimize(**gepa_params)# Log GEPA output for debugginggepa_output = output_buffer.getvalue()if gepa_output:self.logger.info("π GEPA Output (captured):")for line in gepa_output.split('\n')[:50]: # First 50 linesif line.strip():self.logger.info(f" GEPA: {line}")return resultdef _log_pareto_front_info(self, gepa_logs: str) -> int: # Return int instead of None"""Extract and log pareto front information from GEPA logs. Returns max iteration count."""
240 unmodified lines241242243244245246247349 unmodified lines597598599600601602603604240 unmodified lines# We must NEVER use cache in this case, otherwise trajectories=None breaks GEPA!if capture_traces:dataset_type = 'dfeedback' # Training minibatch - need fresh evaluation with trajectoriesself.logger.debug(f"π― Forced dataset_type to 'dfeedback' (capture_traces=True)")# If _is_baseline_evaluation is True, we KNOW this is the validation setelif hasattr(self, '_is_baseline_evaluation') and self._is_baseline_evaluation:dataset_type = 'dpareto' # Baseline is ALWAYS evaluated on validation set349 unmodified linesπ₯ NEW: If hybrid mode is enabled, this method ALSO generates hybrid candidates(GEPA Reflection + LLEGO Operators) and stores them for GEPA to use."""# π₯ REMOVED: Excessive diagnostic logs - moved to DEBUG level if neededself.logger.debug(f"make_reflective_dataset() called - generating feedback and hybrid candidates")reflective_dataset = {}system_prompt = candidate.get('system_prompt', '')240 unmodified lines241242243244245246247248349 unmodified lines598599600601602603604605606607608609610611240 unmodified lines# We must NEVER use cache in this case, otherwise trajectories=None breaks GEPA!if capture_traces:dataset_type = 'dfeedback' # Training minibatch - need fresh evaluation with trajectoriesself.logger.info(f"π― evaluate() called with capture_traces=True - this is a TRAINING MINIBATCH")self.logger.info(f" Batch size: {len(batch)}, Will generate trajectories for reflection")# If _is_baseline_evaluation is True, we KNOW this is the validation setelif hasattr(self, '_is_baseline_evaluation') and self._is_baseline_evaluation:dataset_type = 'dpareto' # Baseline is ALWAYS evaluated on validation set349 unmodified linesπ₯ NEW: If hybrid mode is enabled, this method ALSO generates hybrid candidates(GEPA Reflection + LLEGO Operators) and stores them for GEPA to use."""# π₯ DEBUG: Log that this method is being called (CRITICAL for debugging)self.logger.info(f"\n{'='*80}")self.logger.info(f"π₯ make_reflective_dataset() CALLED BY GEPA")self.logger.info(f"{'='*80}")self.logger.info(f" Candidate prompt: {candidate.get('system_prompt', '')[:100]}...")self.logger.info(f" Eval batch has trajectories: {eval_batch.trajectories is not None and len(eval_batch.trajectories) > 0 if eval_batch.trajectories else False}")self.logger.info(f" Eval batch scores: {eval_batch.scores if eval_batch.scores else 'None'}")self.logger.info(f" Components to update: {components_to_update}")reflective_dataset = {}system_prompt = candidate.get('system_prompt', '')
app.py+9
src/gepa_optimizer/core/optimizer.py+18-1
src/gepa_optimizer/core/universal_adapter.py+10-3