code: def auto_select_device(
      memory_max=8000, memory_bias=200, strategy="random"
  ):
      r"""
      Auto select device for the experiment. Useful when having multiple GPUs.
  
      Args:
          memory_max (int): Threshold of existing GPU memory usage. GPUs with
          memory usage beyond this threshold will be deprioritized.
          memory_bias (int): A bias GPU memory usage added to all the GPUs.
          Avoild dvided by zero error.
          strategy (str, optional): 'random' (random select GPU) or 'greedy'
          (greedily select GPU)
  
      """
      if cfg.device != "cpu" and torch.cuda.is_available():
          if cfg.device == "auto":
              memory_raw = get_gpu_memory_map()
              if strategy == "greedy" or np.all(
                  memory_raw > memory_max
              ):
                  cuda = np.argmin(memory_raw)
                  logging.info("GPU Mem: {}".format(memory_raw))
                  logging.info(
                      "Greedy select GPU, select GPU {} with mem: {}".format(
                          cuda, memory_raw[cuda]
                      )
                  )
              elif strategy == "random":
                  memory = 1 / (memory_raw + memory_bias)
                  memory[memory_raw > memory_max] = 0
                  gpu_prob = memory / memory.sum()
                  cuda = np.random.choice(len(gpu_prob), p=gpu_prob)
                  logging.info("GPU Mem: {}".format(memory_raw))
                  logging.info("GPU Prob: {}".format(gpu_prob.round(2)))
                  logging.info(
                      "Random select GPU, select GPU {} with mem: {}".format(
                          cuda, memory_raw[cuda]
                      )
                  )
  
              cfg.device = "cuda:{}".format(cuda)
      else:
          cfg.device = "cpu"
  
file_path: GraphGym/graphgym/utils/device.py
imports: import logging
  import os
  import subprocess
  import numpy
  import torch
  from graphgym.config import cfg
label_desc: Use image node_id 3 for calling a global function with example usage: auto_select_device(memory_max, memory_bias, strategy) without return types