code: def init_cuda_from_args(no_cuda, local_rank, fp16, verbose=True):
      """Perform initial CUDA setup for DistributedDataParallel, DataParallel or w/o CUDA configs.
  
      Adapted from Hugging Face template: https://github.com/huggingface/transformers/blob/ac99217e92
      c43066af7ec96554054d75532565d7/templates/adding_a_new_example_script/run_xxx.py#L578-L586
  
      Args:
          no_cuda (bool): True to ignore CUDA devices (i.e., use CPU instead).
          local_rank (int): Which GPU the script should use in DistributedDataParallel mode.
          fp16 (bool): True for half-precision mode.
          verbose: True to print device, device count, and whether training is distributed or FP16.
  
      Notes:
          local_rank == -1 is used to indicate that DistributedDataParallel should be disabled.
          n_gpu > 1 is used to indicate that DataParallel should be used. Currently, local_rank == -1
          sets n_gpu = 1 even if torch.cuda.device_count() would show more than one GPU is available.
  
      Returns:
          (tuple): tuple containing:
              device (str): string handle for device.
              n_gpu (int): number of GPU devices.
  
      """
      # TODO break local_rank == -1 and no_cuda into separate cases to make the logic easier to read.
      if local_rank == -1 or no_cuda:
          device = torch.device(
              "cuda"
              if torch.cuda.is_available() and not no_cuda
              else "cpu"
          )
          n_gpu = torch.cuda.device_count()
      else:
          torch.cuda.set_device(local_rank)
          device = torch.device("cuda", local_rank)
          n_gpu = 1
          # Initializes the distributed backend which will take care of synchronizing nodes/GPUs
          # noinspection PyUnresolvedReferences
          torch.distributed.init_process_group(backend="nccl")
      if verbose:
          print(
              "device: {} n_gpu: {}, distributed training: {}, 16-bits training: {}".format(
                  device, n_gpu, bool(local_rank != -1), fp16
              )
          )
  
      return device, n_gpu
  
imports: import json
  import numpy
  import os
  import random
  import time
  import torch
  from dataclasses import dataclass
  from typing import Any
  import jiant.utils.python.io
  import jiant.utils.zlog
label_desc: Use image node_id 3 for calling a global function with example usage: init_cuda_from_args(no_cuda, local_rank, fp16, verbose) and returns: device,  n_gpu