-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Support adk eval --num_runs N as AgentEvaluator
#4411
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
ftnext
wants to merge
3
commits into
google:main
Choose a base branch
from
ftnext:adk-eval-num-runs
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.
+354
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import importlib.util | ||
| import logging | ||
| import os | ||
| import statistics | ||
| import sys | ||
| from typing import Any | ||
| from typing import Optional | ||
|
|
@@ -34,6 +35,8 @@ | |
| from ..evaluation.eval_case import get_all_tool_calls | ||
| from ..evaluation.eval_case import IntermediateDataType | ||
| from ..evaluation.eval_metrics import EvalMetric | ||
| from ..evaluation.eval_metrics import EvalMetricResult | ||
| from ..evaluation.eval_metrics import EvalStatus | ||
| from ..evaluation.eval_metrics import Interval | ||
| from ..evaluation.eval_metrics import MetricInfo | ||
| from ..evaluation.eval_metrics import MetricValueInfo | ||
|
|
@@ -132,6 +135,95 @@ def parse_and_get_evals_to_run( | |
| return eval_set_to_evals | ||
|
|
||
|
|
||
| def _generate_final_eval_status( | ||
| overall_eval_metric_results: list[EvalMetricResult], | ||
| ) -> EvalStatus: | ||
| """Returns final eval status for a case from overall metric results.""" | ||
| final_eval_status = EvalStatus.NOT_EVALUATED | ||
| for overall_eval_metric_result in overall_eval_metric_results: | ||
| overall_eval_status = overall_eval_metric_result.eval_status | ||
| if overall_eval_status == EvalStatus.PASSED: | ||
| final_eval_status = EvalStatus.PASSED | ||
| elif overall_eval_status == EvalStatus.NOT_EVALUATED: | ||
| continue | ||
| elif overall_eval_status == EvalStatus.FAILED: | ||
| final_eval_status = EvalStatus.FAILED | ||
| break | ||
| else: | ||
| raise ValueError(f"Unknown eval status: {overall_eval_status}.") | ||
| return final_eval_status | ||
|
|
||
|
|
||
| def _aggregate_metric_results( | ||
| metric_results: list[EvalMetricResult], | ||
| ) -> EvalMetricResult: | ||
| """Aggregates results of the same metric across runs.""" | ||
| if not metric_results: | ||
| raise ValueError("`metric_results` should not be empty.") | ||
|
|
||
| aggregate_metric_result = metric_results[0].model_copy(deep=True) | ||
| scores = [m.score for m in metric_results if m.score is not None] | ||
| if scores: | ||
| aggregate_metric_result.score = statistics.mean(scores) | ||
| aggregate_metric_result.eval_status = ( | ||
| EvalStatus.PASSED | ||
| if aggregate_metric_result.score >= aggregate_metric_result.threshold | ||
| else EvalStatus.FAILED | ||
| ) | ||
| else: | ||
| aggregate_metric_result.score = None | ||
| aggregate_metric_result.eval_status = EvalStatus.NOT_EVALUATED | ||
|
|
||
| return aggregate_metric_result | ||
|
|
||
|
|
||
| def aggregate_eval_case_results( | ||
| eval_results: list[EvalCaseResult], | ||
| ) -> list[EvalCaseResult]: | ||
| """Aggregates EvalCaseResults with the same eval_set_id and eval_id.""" | ||
| eval_results_by_case_id: dict[tuple[str, str], list[EvalCaseResult]] = {} | ||
| for eval_result in eval_results: | ||
| key = (eval_result.eval_set_id, eval_result.eval_id) | ||
| if key not in eval_results_by_case_id: | ||
| eval_results_by_case_id[key] = [] | ||
| eval_results_by_case_id[key].append(eval_result) | ||
|
|
||
| aggregate_results: list[EvalCaseResult] = [] | ||
| for _, per_case_results in eval_results_by_case_id.items(): | ||
| aggregate_result = per_case_results[0].model_copy(deep=True) | ||
| metric_results_by_name: dict[str, list[EvalMetricResult]] = {} | ||
| for per_case_result in per_case_results: | ||
| for metric_result in per_case_result.overall_eval_metric_results: | ||
| metric_name = metric_result.metric_name | ||
| if metric_name not in metric_results_by_name: | ||
| metric_results_by_name[metric_name] = [] | ||
| metric_results_by_name[metric_name].append(metric_result) | ||
|
Comment on lines
+198
to
+200
Contributor
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. |
||
|
|
||
| metric_names_in_order = [ | ||
| metric_result.metric_name | ||
| for metric_result in aggregate_result.overall_eval_metric_results | ||
| ] | ||
| missing_metric_names = sorted( | ||
| set(metric_results_by_name.keys()) - set(metric_names_in_order) | ||
| ) | ||
| metric_names_in_order.extend(missing_metric_names) | ||
|
|
||
| aggregate_overall_eval_metric_results: list[EvalMetricResult] = [] | ||
| for metric_name in metric_names_in_order: | ||
| aggregate_overall_eval_metric_results.append( | ||
| _aggregate_metric_results(metric_results_by_name[metric_name]) | ||
| ) | ||
| aggregate_result.overall_eval_metric_results = ( | ||
| aggregate_overall_eval_metric_results | ||
| ) | ||
| aggregate_result.final_eval_status = _generate_final_eval_status( | ||
| aggregate_overall_eval_metric_results | ||
| ) | ||
| aggregate_results.append(aggregate_result) | ||
|
|
||
| return sorted(aggregate_results, key=lambda x: (x.eval_set_id, x.eval_id)) | ||
|
|
||
|
|
||
| async def _collect_inferences( | ||
| inference_requests: list[InferenceRequest], | ||
| eval_service: BaseEvalService, | ||
|
|
||
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
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.
To make the code more concise, you can use
dict.setdefault()to simplify the logic for grouping evaluation results by case ID. This avoids the explicit check for the key's existence.