Skip to content
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

[Executor] Fix flex flow metrices #3010

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/promptflow-core/promptflow/executor/_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,22 @@ def _exec_aggregation(
output, metrics = None, {}
try:
output = self._aggr_func(**{self._aggr_input_name: inputs})
metrics = output if isinstance(output, dict) else {"metrics": output}
for k, v in metrics.items():
log_metric(k, v)
except Exception:
pass
if isinstance(output, dict):
metrics = output
for k, v in metrics.items():
log_metric(k, v)
else:
logger.warning("The output of aggregation function isn't a dictionary, skip the metrices update.")
except Exception as e:
error_type_and_message = f"({e.__class__.__name__}) {e}"
e = ScriptExecutionError(
message_format="Execution failure in '{func_name}': {error_type_and_message}",
func_name=self._aggr_func.__name__,
error_type_and_message=error_type_and_message,
)
error = ExceptionPresenter.create(e).to_dict(include_debug_info=True)
logger.warning(f"Failed to execute aggregation function with error: {error}")
logger.warning("The flow will have empty metrics.")
return AggregationResult(output, metrics, {})

async def exec_aggregation_async(
Expand All @@ -216,12 +227,15 @@ async def exec_aggregation_async(
return await self._exec_aggregation_async(aggregation_inputs)

async def _exec_aggregation_async(self, inputs):
output = None
output, metrics = None, {}
try:
output = await self._aggr_func_async(**{self._aggr_input_name: inputs})
metrics = output if isinstance(output, dict) else {"metrics": output}
for k, v in metrics.items():
log_metric(k, v)
if isinstance(output, dict):
metrics = output
for k, v in metrics.items():
log_metric(k, v)
else:
logger.warning("The output of aggregation function isn't a dictionary, skip the metrices update.")
except Exception as e:
error_type_and_message = f"({e.__class__.__name__}) {e}"
e = ScriptExecutionError(
Expand Down
Loading