code: def device_setup(opts):
      """Helper function for setting up the device"""
      random_seed = getattr(opts, "common.seed", 0)
      random.seed(random_seed)
      torch.manual_seed(random_seed)
      np.random.seed(random_seed)
  
      is_master_node = is_master(opts)
      if is_master_node:
          logger.log("Random seeds are set to {}".format(random_seed))
          logger.log(
              "Using PyTorch version {}".format(torch.__version__)
          )
  
      n_gpus = torch.cuda.device_count()
      if n_gpus == 0:
          if is_master_node:
              logger.warning("No GPUs available. Using CPU")
          device = torch.device("cpu")
          n_gpus = 0
      else:
          if is_master_node:
              logger.log("Available GPUs: {}".format(n_gpus))
          device = torch.device("cuda")
  
          if torch.backends.cudnn.is_available():
              import torch.backends.cudnn as cudnn
  
              torch.backends.cudnn.enabled = True
              torch.backends.cudnn.benchmark = False
              torch.backends.cudnn.deterministic = True
              if is_master_node:
                  logger.log("CUDNN is enabled")
  
          allow_tf32 = not getattr(opts, "common.disable_tf32", False)
          if torch.cuda.is_available():
              # TF32 is enabled by default in PyTorch < 1.12, but disabled in new versions.
              # See for details: https://github.com/pytorch/pytorch/issues/67384
              # Disable it using common.disable_tf32 flag
              torch.backends.cuda.matmul.allow_tf32 = allow_tf32
  
      setattr(opts, "dev.device", device)
      setattr(opts, "dev.num_gpus", n_gpus)
  
      return opts
  
file_path: ml-cvnets/utils/common_utils.py
imports: import os
  import random
  from typing import Any, Dict, List, Optional, Tuple
  import numpy
  import torch
  from packaging import version
  from torch import Tensor
  from common import MIN_TORCH_VERSION
  from utils import logger
  from utils.ddp_utils import is_master
label_desc: Use image node_id 4 for calling a global function with example usage: device_setup(opts) and returns: opts