code: def get_nvidia_smi_gpu_stats(
      device: torch.device,
  ) -> GPUStats:  # pragma: no-cover
      """Get GPU stats from nvidia smi.
  
      Args:
           device: A GPU torch.device to get stats from.
  
      Returns:
          dict (str, float): a dict that maps gpu stats to their values.
  
          Keys:
              - 'utilization_gpu_percent'
              - 'utilization_memory_percent'
              - 'fan_speed_percent'
              - 'memory_used_mb'
              - 'memory_free_mb'
              - 'temperature_gpu_celsius'
              - 'temperature_memory_celsius'
  
      Raises:
          FileNotFoundError:
              If nvidia-smi command is not found.
      """
      # Check for nvidia-smi
      nvidia_smi_path = shutil.which("nvidia-smi")
      if nvidia_smi_path is None:
          raise FileNotFoundError("nvidia-smi: command not found.")
  
      # Prepare keys
      gpu_stat_keys = [
          "utilization_gpu_percent",
          "utilization_memory_percent",
          "fan_speed_percent",
          "memory_used_mb",
          "memory_free_mb",
          "temperature_gpu_celsius",
          "temperature_memory_celsius",
      ]
  
      # Format as "utilization.gpu,utilization.memory,fan.speed,etc"
      smi_query = ",".join(
          [".".join(key.split("_")[:-1]) for key in gpu_stat_keys]
      )
  
      gpu_id = torch._utils._get_device_index(device)
  
      # Get values from nvidia-smi
      result = subprocess.run(
          [
              nvidia_smi_path,
              f"--query-gpu={smi_query}",
              "--format=csv,nounits,noheader",
              f"--id={gpu_id}",
          ],
          encoding="utf-8",
          capture_output=True,
          check=True,
      )
  
      # Format output
      output = result.stdout.strip()
      stats = []
      for value in output.split(", "):
          try:
              float_val = float(value)
          except ValueError:
              float_val = 0.0
          stats.append(float_val)
  
      # Add units to keys and populate values
      # This is not a dict comprehension to prevent pyre warnings.
      gpu_stats: GPUStats = {
          "utilization_gpu_percent": stats[0],
          "utilization_memory_percent": stats[1],
          "fan_speed_percent": stats[2],
          "memory_used_mb": stats[3],
          "memory_free_mb": stats[4],
          "temperature_gpu_celsius": stats[5],
          "temperature_memory_celsius": stats[6],
      }
      return gpu_stats
  
imports: import logging
  import os
  import shutil
  import subprocess
  from collections import defaultdict
  from dataclasses import fields, is_dataclass
  from typing import Any, Dict, Mapping, TypeVar
  import torch
  from torchtnt.utils.version import is_torch_version_geq_1_12
  from typing_extensions import Protocol, runtime_checkable, TypedDict
label_desc: Use image node_id 5 for calling a global function with example usage: get_nvidia_smi_gpu_stats(device) and returns: gpu_stats