@@ -26,14 +26,24 @@ class TaskWrapper:
2626
2727 task : Task
2828 batch_id : Union [int , str ]
29- sub_task_num : int = 1
29+ sub_task_num : int = 1 # number of sub tasks splitted from this task
30+ # if max_repeat_times_per_runner is set, one task may be splitted into multiple sub tasks
3031 results : List [Tuple [Status , List [Experience ]]] = field (default_factory = list )
3132
3233
3334def calculate_task_level_metrics (
3435 metrics : List [Dict ], is_eval : bool , eval_at_k : List [int ]
3536) -> Dict [str , float ]:
36- """Calculate task level metrics from experiences."""
37+ """Calculate task level metrics (mean) from multiple runs of the same task.
38+
39+ Args:
40+ metrics (`List[Dict]`): A list of metric dictionaries from multiple runs of the same task.
41+ is_eval (`bool`): Whether this is an evaluation task.
42+ eval_at_k (`List[int]`): A list of k values to evaluate at.
43+
44+ Returns:
45+ `Dict[str, float]`: A dictionary of aggregated metrics, where each metric is averaged over all runs.
46+ """
3747 if not metrics :
3848 return {}
3949 aggregated_metrics : Dict [str , List [float ]] = defaultdict (list )
@@ -327,11 +337,13 @@ def task_done_callback(self, async_task: asyncio.Task):
327337 return
328338 else :
329339 status , exps , runner_id , run_time = async_task .result ()
330- self .total_running_time += run_time
331- self .total_completed_tasks += 1
340+ if not task .task .is_eval : # only count running time for non-eval tasks
341+ self .total_running_time += run_time
342+ self .total_completed_tasks += 1
332343 task .results .append ((status , exps ))
333344 self .busy_runners .pop (runner_id )
334345 self .idle_runners .add (runner_id )
346+ # If all sub runs in a task are completed
335347 if len (task .results ) == task .sub_task_num :
336348 task_experiences = []
337349 task_metrics = []
@@ -341,6 +353,7 @@ def task_done_callback(self, async_task: asyncio.Task):
341353 task_experiences .extend (exp )
342354 if not s .ok :
343355 all_success = False
356+ # calculate task level metrics
344357 task_status = Status (
345358 ok = all_success ,
346359 metrics = [
0 commit comments