code: def average_runs(
      path_to_runs_dir: str,
  ) -> Dict[str, Union[int, float]]:
      """Return average metrics from code blocks/function that ran more than once.
  
      Metrics for code blocks/functions that were executed exactly once will be returned as is.
  
      :param path_to_runs_dir: path to where metrics specific to a tag are stored.
          e.g. resource_usage_out_dir/torch_ops_resource_usage/LudwigModel.evaluate/
          This directory will contain JSON files with the following pattern run_*.json
      """
      runs = [
          load_json(os.path.join(path_to_runs_dir, run))
          for run in os.listdir(path_to_runs_dir)
      ]
      # asserting that keys to each of the dictionaries are consistent throughout the runs.
      assert len(runs) == 1 or all(
          runs[i].keys() == runs[i + 1].keys()
          for i in range(len(runs) - 1)
      )
      runs_average = {"num_runs": len(runs)}
      for key in runs[0]:
          if isinstance(runs[0][key], (int, float)):
              runs_average[key] = mean([run[key] for run in runs])
      return runs_average
  
imports: import csv
  import logging
  import os
  from dataclasses import dataclass
  from statistics import mean
  from typing import Dict, List, Optional, Set, Union
  import ludwig.modules.metric_modules
  from ludwig.benchmarking.utils import format_memory, format_time
  from ludwig.globals import MODEL_HYPERPARAMETERS_FILE_NAME
  from ludwig.modules.metric_registry import get_metric_classes, metric_feature_type_registry
  from ludwig.types import ModelConfigDict
  from ludwig.utils.data_utils import load_json
label_desc: Use image node_id 6 for calling a global function with example usage: average_runs(path_to_runs_dir) and returns: runs_average