code: def _get_nvidia_gpus() -> List[GPU]:
      try:
          proc = subprocess.Popen(
              [
                  "nvidia-smi",
                  "--query-gpu=" + ",".join(gpu_fields),
                  "--format=csv,noheader,nounits",
              ],
              stdout=subprocess.PIPE,
              universal_newlines=True,
          )
      except FileNotFoundError:
          logger.info("detected 0 gpus (nvidia-smi not found)")
          # This case is expected if NVIDIA drivers are not available.
          return []
      except Exception as e:
          logger.warning(
              f"detected 0 gpus (error with nvidia-smi: {e})"
          )
          return []
  
      gpus = []
      with proc:
          for field_list in csv.reader(proc.stdout):  # type: ignore
              if len(field_list) != len(gpu_fields):
                  logger.warning(
                      f"Ignoring unexpected nvidia-smi output: {field_list}"
                  )
                  continue
              fields = dict(zip(gpu_fields, field_list))
              try:
                  gpus.append(
                      GPU(
                          id=int(fields["index"]),
                          uuid=fields["uuid"].strip(),
                          load=float_or_default(
                              fields, "utilization.gpu", 0.0
                          )
                          / 100,
                          memoryUtil=float_or_default(
                              fields, "memory.used", 0.0
                          )
                          / float_or_default(
                              fields, "memory.total", 1.0
                          ),
                      )
                  )
              except ValueError:
                  logger.warning(
                      f"Ignoring GPU with unexpected nvidia-smi output: {fields}"
                  )
      if proc.returncode:
          logger.warning(
              f"`nvidia-smi` exited with failure status code {proc.returncode}"
          )
  
      logger.info(f"detected {len(gpus)} gpus")
      return gpus
  
file_path: determined/harness/determined/gpu.py
imports: import csv
  import json
  import logging
  import subprocess
  from typing import List, NamedTuple, Tuple
label_desc: Use image node_id 2 for calling a global function with example usage: _get_nvidia_gpus() and returns: gpus, list, list