code: def get_device(
      num_gpus=None,
      local_rank=-1,
      #    backend="nccl",
      #    rank=0,
      #    world_size=1,
      #    init_method="file:///distributed",
  ):
      if local_rank == -1:
          num_gpus = (
              min(num_gpus, torch.cuda.device_count())
              if num_gpus is not None
              else torch.cuda.device_count()
          )
          device = torch.device(
              "cuda"
              if torch.cuda.is_available() and num_gpus > 0
              else "cpu"
          )
      else:
          torch.cuda.set_device(local_rank)
          device = torch.device("cuda", local_rank)
          # torch.distributed.init_process_group(backend="nccl")
          # torch.distributed.init_process_group(backend=backend, rank=rank,
          # world_size=world_size, init_method=init_method)
          num_gpus = 1
      return device, num_gpus
  
imports: import torch
  import torch.nn
  import warnings
label_desc: Use image node_id 1 for calling a global function with example usage: get_device(num_gpus, local_rank) and returns: device,  num_gpus