code: def compute_num_gpus(
      config_num_gpus: Union[int, float, List], accelerator: str
  ):
      """
      Compute the gpu number to initialize the lightning trainer.
  
      Parameters
      ----------
      config_num_gpus
          The gpu number provided by config.
      accelerator
          # "cpu", "gpu", or "auto".
  
      Returns
      -------
      A valid gpu number for the current environment and config.
      """
      if isinstance(accelerator, str) and accelerator.lower() not in [
          "gpu",
          "auto",
      ]:
          return 0
  
      config_num_gpus = (
          math.floor(config_num_gpus)
          if isinstance(config_num_gpus, (int, float))
          else len(config_num_gpus)
      )
      detected_num_gpus = ResourceManager.get_gpu_count_torch()
  
      if (
          config_num_gpus < 0
      ):  # In case config_num_gpus is -1, meaning using all gpus.
          num_gpus = detected_num_gpus
      else:
          num_gpus = min(config_num_gpus, detected_num_gpus)
          if detected_num_gpus < config_num_gpus:
              warnings.warn(
                  f"Using the detected GPU number {detected_num_gpus}, "
                  f"smaller than the GPU number {config_num_gpus} in the config.",
                  UserWarning,
              )
  
      return num_gpus
  
imports: import contextlib
  import logging
  import math
  import sys
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from lightning.pytorch.accelerators import find_usable_cuda_devices
  from torch import nn
  from autogluon.common.utils.resource_utils import ResourceManager
  from ..constants import DDP_STRATEGIES, OBJECT_DETECTION, OCR
label_desc: Use image node_id 3 for calling a global function with example usage: compute_num_gpus(config_num_gpus, accelerator) and returns: num_gpus, int