code: def allreduce_parameters(params):
      """
      Allreduce the parameters of all other processes, i.e., forcing all
      processes to have same average model.
      Typical usage is to allreduce the ``model.named_parameters()``,
      or ``model.parameters()``.
  
      Arguments:
          params: One of the following:
              - list of parameters to allreduce
              - dict of parameters to allreduce
      """
      if isinstance(params, dict):
          params = sorted(params.items())
      elif isinstance(params, list):
          # support both named_parameters() and regular parameters()
          params = [
              p if isinstance(p, tuple) else (None, p) for p in params
          ]
      else:
          raise ValueError("invalid params of type: %s" % type(params))
  
      # Run asynchronous broadcasts.
      handles = []
      for name, p in params:
          handle = bf.allreduce_nonblocking_(p, average=True, name=name)
          handles.append(handle)
  
      # Wait for completion.
      for handle in handles:
          bf.synchronize(handle)
  
file_path: bluefog/bluefog/torch/utility.py
imports: from typing import Any, List, Optional
  from functools import wraps
  import collections
  import numpy
  import torch
  import bluefog.torch
label_desc: Use image node_id 2 for calling a global function with example usage: allreduce_parameters(params) without return types