code: def log_number_of_parameters(model, logger=None):
      if not logger:
          logger = logging
      num_params = reduce(
          operator.add,
          (reduce(operator.mul, x.size()) for x in model.parameters()),
      )
      if hasattr(model, "group"):
          total = torch.Tensor([num_params])
          if torch.cuda.is_available():
              total = total.cuda()
          torch.distributed.all_reduce(total, group=model.group)
          logger.debug(
              f"training model, #params = {num_params}, group: {model.group.rank()}, grank:"
              f" {torch.distributed.get_rank()}, sizes {model.group.size()}"
          )
          torch.distributed.barrier()
          if model.group.rank() == 0:
              logger.debug(f"total #prams = {total.item()}")
      else:
          logger.debug(f"training model, #params = {num_params}")
  
file_path: fairscale/benchmarks/utils.py
imports: import argparse
  from functools import reduce
  import logging
  import operator
  import datasets.wikitext2_data
  from models import transformer_lm
  import numpy
  import torch
  from torch.optim import Adam
label_desc: Use image node_id 8 for calling a global function with example usage: log_number_of_parameters(model, logger) without return types