code: def __init__(self, index: int, detail: bool):
      self.index = index
      self._procs = []
  
      try:
          device = nvmlDeviceGetHandleByIndex(self.index)
      except Exception as e:
          errors.add(f"device: {e}")
          return
  
      if detail:
          try:
              self.model = nvmlDeviceGetName(device)
          except Exception as e:
              errors.add(f"model: {e}")
  
          try:
              self.cuda_cores = nvmlDeviceGetNumGpuCores(device)
          except Exception as e:
              errors.add(f"cuda_cores: {e}")
  
          try:
              mem = nvmlDeviceGetMemoryInfo(device)
              self.gpu_memory = mem.total
              self.free_gpu_memory = mem.free
          except Exception as e:
              errors.add(f"gpu_memory: {e}")
  
      try:
          util = nvmlDeviceGetUtilizationRates(device)
          self.gpu_core_utilization = util.gpu / 100
          self.gpu_memory_utilization = util.memory / 100
      except Exception as e:
          errors.add(f"gpu_utilization: {e}")
  
      try:
          cprocs = nvmlDeviceGetComputeRunningProcesses_v3(device)
          gprocs = nvmlDeviceGetGraphicsRunningProcesses_v3(device)
          self._procs += [
              ProcessInfo(proc, self.index, "compute", detail)
              for proc in cprocs
          ]
          self._procs += [
              ProcessInfo(proc, self.index, "graphics", detail)
              for proc in gprocs
          ]
      except Exception as e:
          errors.add(f"process: {e}")
  
file_path: nni/nni/tools/nni_manager_scripts/collect_gpu_info.py
imports: from __future__ import annotations
  from dataclasses import asdict, dataclass
  import json
  import sys
  from typing import Any, Literal
  from pynvml import *
label_desc: Use image node_id 1 to create a new GpuInfo object  with example: obj = GpuInfo(index, detail)