code: def average_checkpoints(
      checkpoint_list,
      recoverable_name,
      parameter_loader=torch.load,
      averager=average_state_dicts,
  ):
      """Average parameters from multiple checkpoints.
  
      Use Checkpointer.find_checkpoints() to get the list of checkpoints to
      average over.
      Averaging parameters from some of the last checkpoints in training has been
      shown to sometimes improve performance.
  
      The default loader and averager work for standard PyTorch modules.
  
      Arguments
      ---------
      checkpoint_list : list
          List of checkpoints to average.
      recoverable_name : str
          The name of the recoverable, the parameters of which are loaded and
          averaged.
      parameter_loader : function
          A function which takes a single argument, the path to a parameter file,
          and loads the parameters from that file. By default, torch.load,
          which produces state_dict dictionaries.
      averager : function
          A function which takes an iterator over the parameters from each
          checkpoint, as loaded by parameter_loader, and produces their average.
          Note that the function is called with an iterator, so the length is
          initially unknown; the implementation should simply count the number of
          different parameter sets as they are yielded. See average_state_dicts
          above for an example. It is the default averager, and averages
          state_dicts.
  
      Returns
      -------
      Any
          The output of the averager function.
  
      Example
      -------
      >>> # Consider this toy Module again:
      >>> class Recoverable(torch.nn.Module):
      ...     def __init__(self, param):
      ...         super().__init__()
      ...         self.param = torch.nn.Parameter(torch.tensor([param]))
      ...     def forward(self, x):
      ...         return x * self.param
      >>> # Now let's make some checkpoints:
      >>> model = Recoverable(1.)
      >>> tempdir = getfixture('tmpdir')
      >>> checkpointer = Checkpointer(tempdir, {"model": model})
      >>> for new_param in range(10):
      ...     model.param.data = torch.tensor([float(new_param)])
      ...     _ = checkpointer.save_checkpoint()  # Suppress output with assignment
      >>> # Let's average the 3 latest checkpoints
      >>> # (parameter values 7, 8, 9 -> avg=8)
      >>> ckpt_list = checkpointer.find_checkpoints(max_num_checkpoints = 3)
      >>> averaged_state = average_checkpoints(ckpt_list, "model")
      >>> # Now load that state in the normal way:
      >>> _ = model.load_state_dict(averaged_state)  # Suppress output
      >>> model.param.data
      tensor([8.])
      """
      device = "cpu"
      parameter_iterator = (
          parameter_loader(
              ckpt.paramfiles[recoverable_name], map_location=device
          )
          for ckpt in checkpoint_list
      )
      return averager(parameter_iterator)
  
imports: import torch
  import collections
  import collections.abc
  import os
  import time
  import yaml
  import pathlib
  import inspect
  import shutil
  import logging
  import warnings
  from packaging import version
  import speechbrain.utils._workarounds
  from speechbrain.utils.distributed import main_process_only, if_main_process, ddp_barrier
label_desc: Use image node_id 11 for calling a global function with example usage: average_checkpoints(checkpoint_list, recoverable_name, parameter_loader, averager) and returns: averager