code: def allreduce_grads(params, coalesce=True, bucket_size_mb=-1):
      """Allreduce gradients.
  
      Args:
          params (list[torch.Parameters]): List of parameters of a model
          coalesce (bool, optional): Whether allreduce parameters as a whole.
              Defaults to True.
          bucket_size_mb (int, optional): Size of bucket, the unit is MB.
              Defaults to -1.
      """
      grads = [
          param.grad.data
          for param in params
          if param.requires_grad and param.grad is not None
      ]
      _, world_size = get_dist_info()
      if world_size == 1:
          return
      if coalesce:
          _allreduce_coalesced(grads, world_size, bucket_size_mb)
      else:
          for tensor in grads:
              dist.all_reduce(tensor.div_(world_size))
  
file_path: lavis/lavis/common/annotator/uniformer/mmcv/runner/dist_utils.py
imports: import functools
  import os
  import subprocess
  from collections import OrderedDict
  import torch
  import torch.multiprocessing
  from torch import distributed
  from torch._utils import _flatten_dense_tensors, _take_tensors, _unflatten_dense_tensors
label_desc: Use image node_id 8 for calling a global function with example usage: allreduce_grads(params, coalesce, bucket_size_mb) without return types