code: def get_mem(device_handle):
      
      try:
          memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle)
          return memory_info.used * 100.0 / memory_info.total
      except pynvml.NVMLError:
          return None
docs: Get GPU device memory consumption in percent.