-
Notifications
You must be signed in to change notification settings - Fork 6
Fix compare_results quality metric parsing for judge-enabled runs #4
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
Merged
+167
−4
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a78b2c5
Initial plan
Copilot f63d334
test: add compare-results regression coverage
Copilot a93aca6
fix: read nested quality metrics in compare_results
Copilot db5ff7e
Fix review issues: sentinel in _quality_metric, isinstance for win_ra…
Copilot 171786d
fix: add pythonpath=['.'] to pytest config to resolve ModuleNotFoundE…
Copilot 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
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """Regression tests for scripts.compare_results.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def _load_compare_results_module(): | ||
| script_path = Path(__file__).resolve().parents[1] / "scripts" / "compare_results.py" | ||
| spec = importlib.util.spec_from_file_location("compare_results", script_path) | ||
| assert spec is not None | ||
| module = importlib.util.module_from_spec(spec) | ||
| assert spec.loader is not None | ||
| spec.loader.exec_module(module) | ||
|
leestott marked this conversation as resolved.
|
||
| return module | ||
|
|
||
|
|
||
| def _row_map(rows): | ||
| return {(row["category"], row["metric"]): row for row in rows} | ||
|
|
||
|
|
||
| def _base_run(): | ||
| return { | ||
| "model_router": { | ||
| "total_requests": 10, | ||
| "latency": {"mean_ms": 100.0, "p90_ms": 120.0, "p99_ms": 140.0}, | ||
| "cost": {"estimated_cost_usd": 1.0}, | ||
| }, | ||
| "baseline": { | ||
| "total_requests": 10, | ||
| "latency": {"mean_ms": 150.0, "p90_ms": 180.0, "p99_ms": 210.0}, | ||
| "cost": {"estimated_cost_usd": 2.0}, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def test_compare_reads_nested_quality_metrics(): | ||
| mod = _load_compare_results_module() | ||
| run_a = _base_run() | { | ||
| "quality": { | ||
| "pairwise": { | ||
| "router_win_rate": 0.4, | ||
| "baseline_win_rate": 0.2, | ||
| "tie_rate": 0.4, | ||
| }, | ||
| "absolute_scores": { | ||
| "router_overall": 4.2, | ||
| "baseline_overall": 3.8, | ||
| }, | ||
| "win_rate_by_category": { | ||
| "math": { | ||
| "router_win_rate": 1.0, | ||
| "baseline_win_rate": 0.0, | ||
| "tie_rate": 0.0, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| run_b = _base_run() | { | ||
| "quality": { | ||
| "pairwise": { | ||
| "router_win_rate": 0.5, | ||
| "baseline_win_rate": 0.3, | ||
| "tie_rate": 0.2, | ||
| }, | ||
| "absolute_scores": { | ||
| "router_overall": 4.5, | ||
| "baseline_overall": 4.0, | ||
| }, | ||
| "win_rate_by_category": { | ||
| "math": { | ||
| "router_win_rate": 0.5, | ||
| "baseline_win_rate": 0.5, | ||
| "tie_rate": 0.0, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| rows = _row_map(mod.compare(run_a, run_b, "run-a", "run-b")) | ||
|
|
||
| assert rows[("Quality", "router_win_rate")]["run_a"] == 0.4 | ||
| assert rows[("Quality", "router_win_rate")]["run_b"] == 0.5 | ||
| assert rows[("Quality", "baseline_overall")]["run_a"] == 3.8 | ||
| assert rows[("Quality", "router_overall")]["run_b"] == 4.5 | ||
| assert rows[("Quality by Category", "math router_win_rate")]["run_a"] == 1.0 | ||
| assert rows[("Quality by Category", "math baseline_win_rate")]["run_b"] == 0.5 | ||
|
|
||
|
|
||
| def test_compare_keeps_legacy_flat_quality_metrics(): | ||
| mod = _load_compare_results_module() | ||
| run_a = _base_run() | { | ||
| "quality": { | ||
| "router_win_rate": 0.4, | ||
| "baseline_win_rate": 0.2, | ||
| "tie_rate": 0.4, | ||
| "router_mean_score": 4.1, | ||
| "baseline_mean_score": 3.7, | ||
| }, | ||
| } | ||
| run_b = _base_run() | { | ||
| "quality": { | ||
| "router_win_rate": 0.6, | ||
| "baseline_win_rate": 0.1, | ||
| "tie_rate": 0.3, | ||
| "router_mean_score": 4.4, | ||
| "baseline_mean_score": 3.9, | ||
| }, | ||
| } | ||
|
|
||
| rows = _row_map(mod.compare(run_a, run_b, "run-a", "run-b")) | ||
|
|
||
| assert rows[("Quality", "router_win_rate")]["run_a"] == 0.4 | ||
| assert rows[("Quality", "baseline_win_rate")]["run_b"] == 0.1 | ||
| assert rows[("Quality", "router_overall")]["run_a"] == 4.1 | ||
| assert rows[("Quality", "baseline_overall")]["run_b"] == 3.9 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.