class_docstr: The standalone GPU usage metric.
  Important: this metric approximates the real maximum GPU percentage
  usage since it sample at discrete amount of time the GPU values.
  
  Instances of this metric keeps the maximum GPU usage percentage detected.
  The `start_thread` method starts the usage tracking.
  The `stop_thread` method stops the tracking.
  
  The result, obtained using the `result` method, is the usage in mega-bytes.
  
  The reset method will bring the metric to its initial state. By default
  this metric in its initial state will return an usage value of 0.
class_docstr_tok: ["The","standalone","GPU","usage","metric",".","Important",":","this","metric","approximates","the","real","maximum","GPU","percentage","usage","since","it","sample","at","discrete","amount","of","time","the","GPU","values",".","Instances","of","this","metric","keeps","the","maximum","GPU","usage","percentage","detected",".","The","`","start_thread","`","method","starts","the","usage","tracking",".","The","`","stop_thread","`","method","stops","the","tracking",".","The","result",",","obtained","using","the","`","result","`","method",",","is","the","usage","in","mega-bytes",".","The","reset","method","will","bring","the","metric","to","its","initial","state",".","By","default","this","metric","in","its","initial","state","will","return","an","usage","value","of","0","."]
docstr: Creates an instance of the GPU usage metric.
  
  :param gpu_id: GPU device ID.
  :param every: seconds after which update the maximum GPU
      usage
docstr_tok: ["Creates","an","instance","of","the","GPU","usage","metric",".",":","param","gpu_id",":","GPU","device","ID",".",":","param","every",":","seconds","after","which","update","the","maximum","GPU","usage"]
code: def __init__(self, gpu_id, every=0.5):
      """
      Creates an instance of the GPU usage metric.
  
      :param gpu_id: GPU device ID.
      :param every: seconds after which update the maximum GPU
          usage
      """
  
      self.every = every
      self.gpu_id = gpu_id
  
      n_gpus = len(GPUtil.getGPUs())
      if n_gpus == 0:
          warnings.warn("Your system has no GPU!")
          self.gpu_id = None
      elif gpu_id < 0:
          warnings.warn(
              "GPU metric called with negative GPU id."
              "GPU logging disabled"
          )
          self.gpu_id = None
      else:
          if gpu_id >= n_gpus:
              warnings.warn(f"GPU {gpu_id} not found. Using GPU 0.")
              self.gpu_id = 0
  
      self.thread = None
      """
          Thread executing GPU monitoring code
          """
  
      self.stop_f = False
      """
          Flag to stop the thread
          """
  
      self.max_usage = 0
      """
          Main metric result. Max GPU usage.
          """
  
imports: import GPUtil
  from threading import Thread
  import time
  import warnings
  from typing import Optional, TYPE_CHECKING, List
  from avalanche.evaluation import Metric, PluginMetric, GenericPluginMetric
  from avalanche.evaluation.metric_results import MetricResult
label_desc: Use image node_id 1 to create a new MaxGPU object from inherited base classes: Metric with example: obj = MaxGPU(gpu_id, every)