-
Notifications
You must be signed in to change notification settings - Fork 14
feat(zero_shot): enhance evaluation pipeline with rerun-judge and cha… #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XiaoBoAI
wants to merge
1
commit into
main
Choose a base branch
from
feat/zero-shot-evaluation-enhancements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| python -m cookbooks.zero_shot_evaluation --config config.yaml | ||
| python -m cookbooks.zero_shot_evaluation --config config.yaml --save | ||
| python -m cookbooks.zero_shot_evaluation --config config.yaml --queries_file queries.json --save | ||
| python -m cookbooks.zero_shot_evaluation --config config.yaml --rerun-judge --save | ||
| """ | ||
|
|
||
| import asyncio | ||
|
|
@@ -28,6 +29,43 @@ def _load_queries_from_file(queries_file: str) -> List[GeneratedQuery]: | |
| return queries | ||
|
|
||
|
|
||
| def _clear_judge_results(output_dir: str) -> bool: | ||
| """Clear only comparison results to re-run with new judge model. | ||
|
|
||
| Keeps queries, responses, and rubrics intact. | ||
| Only removes comparison_details.json and resets checkpoint to RUBRICS_GENERATED. | ||
|
|
||
| Returns: | ||
| True if successfully cleared, False if no checkpoint exists | ||
| """ | ||
| output_path = Path(output_dir) | ||
| checkpoint_file = output_path / "checkpoint.json" | ||
| details_file = output_path / "comparison_details.json" | ||
|
|
||
| if not checkpoint_file.exists(): | ||
| logger.warning("No checkpoint found, nothing to clear") | ||
| return False | ||
|
|
||
| # Remove comparison details | ||
| if details_file.exists(): | ||
| details_file.unlink() | ||
| logger.info(f"Removed {details_file}") | ||
|
|
||
| # Update checkpoint to RUBRICS_GENERATED stage | ||
| with open(checkpoint_file, "r", encoding="utf-8") as f: | ||
| checkpoint = json.load(f) | ||
|
|
||
| checkpoint["stage"] = "rubrics_generated" | ||
| checkpoint["evaluated_pairs"] = 0 | ||
| checkpoint["total_pairs"] = 0 | ||
|
|
||
| with open(checkpoint_file, "w", encoding="utf-8") as f: | ||
| json.dump(checkpoint, f, indent=2, ensure_ascii=False) | ||
|
|
||
| logger.info("Reset checkpoint to RUBRICS_GENERATED stage (will re-run pairwise evaluation)") | ||
| return True | ||
|
|
||
|
|
||
| async def _run_evaluation( | ||
| config_path: str, | ||
| output_dir: Optional[str] = None, | ||
|
|
@@ -67,6 +105,7 @@ def main( | |
| queries_file: Optional[str] = None, | ||
| save: bool = False, | ||
| fresh: bool = False, | ||
| rerun_judge: bool = False, | ||
| ) -> None: | ||
| """Zero-shot evaluation CLI with checkpoint support. | ||
|
|
||
|
|
@@ -76,6 +115,8 @@ def main( | |
| queries_file: Path to pre-generated queries JSON (skip query generation) | ||
| save: Whether to save results to file | ||
| fresh: Start fresh, ignore any existing checkpoint | ||
| rerun_judge: Re-run only pairwise evaluation with new judge model | ||
| (keeps queries, responses, and rubrics) | ||
|
|
||
| Examples: | ||
| # Normal run (auto-resumes from checkpoint) | ||
|
|
@@ -86,6 +127,9 @@ def main( | |
|
|
||
| # Start fresh, ignore checkpoint | ||
| python -m cookbooks.zero_shot_evaluation --config config.yaml --fresh --save | ||
|
|
||
| # Re-run with new judge model (keeps queries/responses/rubrics) | ||
| python -m cookbooks.zero_shot_evaluation --config config.yaml --rerun-judge --save | ||
| """ | ||
| config_path = Path(config) | ||
| if not config_path.exists(): | ||
|
|
@@ -98,15 +142,27 @@ def main( | |
| logger.error(f"Queries file not found: {queries_file}") | ||
| return | ||
|
|
||
| # Load config to get output_dir | ||
| loaded_config = load_config(str(config_path)) | ||
| effective_output_dir = output_dir or loaded_config.output.output_dir | ||
|
|
||
| # Handle rerun_judge flag | ||
| if rerun_judge: | ||
| if fresh: | ||
| logger.warning("--rerun-judge and --fresh are mutually exclusive, using --rerun-judge") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #160 - #163 should be moved here and merged with #150/151 |
||
| logger.info("Re-running pairwise evaluation with new judge model...") | ||
| if not _clear_judge_results(effective_output_dir): | ||
| logger.info("No previous results found, will run full evaluation") | ||
|
|
||
| logger.info(f"Starting zero-shot evaluation with config: {config}") | ||
| if queries_file: | ||
| logger.info(f"Using pre-generated queries from: {queries_file}") | ||
| if fresh: | ||
| if fresh and not rerun_judge: | ||
| logger.info("Starting fresh (ignoring checkpoint)") | ||
| else: | ||
| logger.info("Resume mode enabled (will continue from checkpoint if exists)") | ||
|
|
||
| asyncio.run(_run_evaluation(str(config_path), output_dir, queries_file, save, resume=not fresh)) | ||
| asyncio.run(_run_evaluation(str(config_path), output_dir, queries_file, save, resume=not fresh or rerun_judge)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration is loaded twice: once here to get the
output_dirand again inside_run_evaluation. To improve efficiency and avoid redundant operations, consider passingeffective_output_dirdirectly to_run_evaluationand modifying_run_evaluationto accept it, thus removing the need for_run_evaluationto load the config itself.