-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Enhance evaluation functionality with support for multiple runs and d… #4495
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -709,6 +709,13 @@ def wrapper(*args, **kwargs): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.argument("eval_set_file_path_or_id", nargs=-1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.option("--config_file_path", help="Optional. The path to config file.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--num_runs", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=click.IntRange(min=1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default=1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| show_default=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Optional. Number of times to run each eval case.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--print_detailed_results", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_flag=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -721,6 +728,7 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agent_module_file_path: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_set_file_path_or_id: list[str], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_file_path: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_runs: int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print_detailed_results: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_storage_uri: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_level: str = "INFO", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -789,6 +797,7 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.base_eval_service import InferenceRequest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.custom_metric_evaluator import _CustomMetricEvaluator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.eval_config import get_eval_metrics_from_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.eval_config import discover_eval_config_for_test_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.eval_config import get_evaluation_criteria_or_default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.eval_result import EvalCaseResult | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..evaluation.evaluator import EvalStatus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -808,9 +817,12 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ModuleNotFoundError as mnf: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise click.ClickException(MISSING_EVAL_DEPENDENCIES_MESSAGE) from mnf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_config = get_evaluation_criteria_or_default(config_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Using evaluation criteria: {eval_config}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics = get_eval_metrics_from_config(eval_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics_by_eval_set_id = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global_eval_metrics = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if config_file_path: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_config = get_evaluation_criteria_or_default(config_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Using evaluation criteria: {eval_config}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global_eval_metrics = get_eval_metrics_from_config(eval_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| root_agent = get_root_agent(agent_module_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app_name = os.path.basename(agent_module_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -854,6 +866,18 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"`{eval_set_file_path}` should be a valid eval set file." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) from fne | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_config_for_eval_set = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get_evaluation_criteria_or_default(config_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if config_file_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else discover_eval_config_for_test_file(eval_set_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Using evaluation criteria for {eval_set_file_path}:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f" {eval_config_for_eval_set}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics_by_eval_set_id[eval_set.eval_set_id] = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get_eval_metrics_from_config(eval_config_for_eval_set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_sets_manager.create_eval_set( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app_name=app_name, eval_set_id=eval_set.eval_set_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -873,6 +897,10 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # We assume that what we have are eval set ids instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if global_eval_metrics is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_config = get_evaluation_criteria_or_default(config_file_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Using evaluation criteria: {eval_config}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global_eval_metrics = get_eval_metrics_from_config(eval_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_sets_manager = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_sets_manager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if eval_storage_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -888,6 +916,7 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_config=InferenceConfig(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics_by_eval_set_id[eval_set_id_key] = global_eval_metrics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_simulator_provider = UserSimulatorProvider( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_simulator_config=eval_config.user_simulator_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -920,18 +949,31 @@ def cli_eval( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metric_evaluator_registry=metric_evaluator_registry, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repeated_inference_requests = inference_requests * num_runs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_results = asyncio.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _collect_inferences( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_requests=inference_requests, eval_service=eval_service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_results = asyncio.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _collect_eval_results( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_results=inference_results, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_requests=repeated_inference_requests, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_service=eval_service, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics=eval_metrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_results = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for eval_set_id, eval_metrics in eval_metrics_by_eval_set_id.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_results_for_eval_set = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for inference_result in inference_results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if inference_result.eval_set_id == eval_set_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not inference_results_for_eval_set: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_results.extend( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| asyncio.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _collect_eval_results( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inference_results=inference_results_for_eval_set, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_service=eval_service, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eval_metrics=eval_metrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+959
to
+976
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. The current implementation filters You can improve performance by grouping the inference results by
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ModuleNotFoundError as mnf: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise click.ClickException(MISSING_EVAL_DEPENDENCIES_MESSAGE) from mnf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
There's a potential
UnboundLocalErrorforeval_config. It is used on line 922, but it's only defined within thisif config_file_path:block, or later when handling eval set IDs. Ifconfig_file_pathis not provided and the code proceeds to handle eval set file paths,eval_configwill not be defined when it's needed forUserSimulatorProvider.To fix this, you should initialize
eval_configunconditionally at the beginning of the function. Applying this fix will also allow you to simplify the code in a couple of other places:eval_configvariable instead of callingget_evaluation_criteria_or_defaultagain.get_evaluation_criteria_or_default.