code: def get_gpu_memory(dev: int) -> t.Tuple[float, float]:
      """
      Return Total Memory and Free Memory in given GPU device. in MiB
      """
      import pynvml.nvml  # type: ignore
      from pynvml.smi import nvidia_smi  # type: ignore
  
      unit_multiplier = {
          "PiB": 1024.0 * 1024 * 1024,
          "TiB": 1024.0 * 1024,
          "GiB": 1024.0,
          "MiB": 1.0,
          "KiB": 1.0 / 1024,
          "B": 1.0 / 1024 / 1024,
      }
  
      try:
          inst = nvidia_smi.getInstance()
          query: t.Dict[str, int] = inst.DeviceQuery(dev)  # type: ignore
      except (pynvml.nvml.NVMLError, OSError):
          return 0.0, 0.0
  
      try:
          gpus: t.List[t.Dict[str, t.Any]] = query.get("gpu", [])  # type: ignore
          gpu = gpus[dev]
          unit = gpu["fb_memory_usage"]["unit"]
          total = (
              gpu["fb_memory_usage"]["total"] * unit_multiplier[unit]
          )
          free = gpu["fb_memory_usage"]["free"] * unit_multiplier[unit]
          return total, free
      except IndexError:
          raise ValueError(f"Invalid GPU device index {dev}")
      except KeyError:
          raise RuntimeError(f"unexpected nvml query result: {query}")
  
imports: from __future__ import annotations
  import functools
  import logging
  import math
  import os
  import re
  import typing
  from abc import ABC
  from abc import abstractmethod
  import psutil
  from ..exceptions import BentoMLConfigException
label_desc: Use image node_id 5 for calling a global function with example usage: get_gpu_memory(dev) and returns: total,  free, int,  int