code: def average_gradients(model: nn.Module) -> None:
      """
      For all parameters of a given ``model`` averages gradients over all workers
  
      Args:
          model: model
  
      Returns:
          None
      """
      world_size = torch.distributed.get_world_size()
      for param in model.parameters():
          if not param.requires_grad:
              continue
          torch.distributed.all_reduce(
              param.grad, op=torch.distributed.ReduceOp.SUM
          )
          param.grad /= world_size
  
imports: import torch
  import torch.nn
label_desc: Use image node_id 1 for calling a global function with example usage: average_gradients(model) without return types