code: def get_batchsize_per_replica(x: Union[Tuple, List, Dict]) -> int:
      """
      Some layer may take tuple/list/dict/list[dict] as input in forward function. We
      recursively dive into the tuple/list until we meet a tensor and infer the batch size
      """
      while isinstance(x, (list, tuple)):
          assert (
              len(x) > 0
          ), "input x of tuple/list type must have at least one element"
          x = x[0]
  
      if isinstance(x, (dict,)):
          # index zero is always equal to batch size. select an arbitrary key.
          key_list = list(x.keys())
          x = x[key_list[0]]
  
      return x.size()[0]
  
imports: import collections.abc
  import contextlib
  import json
  import logging
  import os
  import time
  from functools import partial
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from classy_vision.generic.distributed_util import broadcast_object, is_primary
  from fvcore.common.file_io import PathManager
label_desc: Use image node_id 27 for calling a global function with example usage: get_batchsize_per_replica(x) and returns: x