code: def merge_dicts(  # pragma: no cover
      dicts: Sequence[Mapping],
      agg_key_funcs: Optional[Mapping] = None,
      default_func: Callable[[Sequence[float]], float] = np.mean,
  ) -> Dict:
      """Merge a sequence with dictionaries into one dictionary by aggregating the same keys with some given function.
  
      Args:
          dicts:
              Sequence of dictionaries to be merged.
          agg_key_funcs:
              Mapping from key name to function. This function will aggregate a
              list of values, obtained from the same key of all dictionaries.
              If some key has no specified aggregation function, the default one
              will be used. Default is: ``None`` (all keys will be aggregated by the
              default function).
          default_func:
              Default function to aggregate keys, which are not presented in the
              `agg_key_funcs` map.
  
      Returns:
          Dictionary with merged values.
  
      Examples:
          >>> import pprint
          >>> d1 = {'a': 1.7, 'b': 2.0, 'c': 1, 'd': {'d1': 1, 'd3': 3}}
          >>> d2 = {'a': 1.1, 'b': 2.2, 'v': 1, 'd': {'d1': 2, 'd2': 3}}
          >>> d3 = {'a': 1.1, 'v': 2.3, 'd': {'d3': 3, 'd4': {'d5': 1}}}
          >>> dflt_func = min
          >>> agg_funcs = {'a': np.mean, 'v': max, 'd': {'d1': sum}}
          >>> pprint.pprint(merge_dicts([d1, d2, d3], agg_funcs, dflt_func))
          {'a': 1.3,
           'b': 2.0,
           'c': 1,
           'd': {'d1': 3, 'd2': 3, 'd3': 3, 'd4': {'d5': 1}},
           'v': 2.3}
  
      """
      agg_key_funcs = agg_key_funcs or {}
      keys = list(
          functools.reduce(operator.or_, [set(d.keys()) for d in dicts])
      )
      d_out: Dict = defaultdict(dict)
      for k in keys:
          fn = agg_key_funcs.get(k)
          values_to_agg = [
              v
              for v in [d_in.get(k) for d_in in dicts]
              if v is not None
          ]
  
          if isinstance(values_to_agg[0], dict):
              d_out[k] = merge_dicts(values_to_agg, fn, default_func)
          else:
              d_out[k] = (fn or default_func)(values_to_agg)
  
      return dict(d_out)
  
imports: import functools
  import operator
  from abc import ABC
  from collections import defaultdict
  from typing import Any, Callable, Dict, Mapping, Optional, Sequence
  import numpy
  from typing_extensions import override
  from lightning.fabric.loggers import Logger
  from lightning.fabric.loggers.logger import _DummyExperiment
  from lightning.fabric.loggers.logger import rank_zero_experiment
  from lightning.pytorch.callbacks.model_checkpoint import ModelCheckpoint
label_desc: Use image node_id 1 for calling a global function with example usage: merge_dicts(dicts, agg_key_funcs, default_func) and returns: dict