class_docstr: A helper class that tracks cpu and gpu memory.
  
  This class will silently skip unless `psutil` is available. Install with `pip install psutil`.
  
  When a stage completes, it can pass metrics dict to update with the memory metrics gathered during this stage.
  
  Example :
  
  ```python
  self._memory_tracker = TrainerMemoryTracker(self.args.skip_memory_metrics)
  self._memory_tracker.start()
  # code ...
  metrics = {"train_runtime": 10.5}
  self._memory_tracker.stop_and_update_metrics(metrics)
  ```
  
  At the moment GPU tracking is only for `pytorch`, but can be extended to support `tensorflow`.
  
  To understand this class' intricacies please read the documentation of [`~Trainer.log_metrics`].
class_docstr_tok: ["A","helper","class","that","tracks","cpu","and","gpu","memory",".","This","class","will","silently","skip","unless","`","psutil","`","is","available",".","Install","with","`","pip","install","psutil","`",".","When","a","stage","completes",",","it","can","pass","metrics","dict","to","update","with","the","memory","metrics","gathered","during","this","stage",".","Example",":","``","`","python","self._memory_tracker","=","TrainerMemoryTracker","(","self.args.skip_memory_metrics",")","self._memory_tracker.start","(",")","#","code","...","metrics","=","{","``","train_runtime","''",":","10.5","}","self._memory_tracker.stop_and_update_metrics","(","metrics",")","``","`","At","the","moment","GPU","tracking","is","only","for","`","pytorch","`",",","but","can","be","extended","to","support","`","tensorflow","`",".","To","understand","this","class","'","intricacies","please","read","the","documentation","of","[","`","~Trainer.log_metrics","`","]","."]
code: def __init__(self, skip_memory_metrics=False):
      self.skip_memory_metrics = skip_memory_metrics
  
      if not is_psutil_available():
          # soft dependency on psutil
          self.skip_memory_metrics = True
  
      if self.skip_memory_metrics:
          return
  
      import psutil  # noqa
  
      if is_torch_cuda_available():
          import torch
  
          self.torch = torch
          self.gpu = {}
      else:
          self.torch = None
  
      self.process = psutil.Process()
  
      self.cur_stage = None
      self.cpu = {}
      self.init_reported = False
  
imports: import copy
  import functools
  import gc
  import inspect
  import os
  import random
  import re
  import threading
  import time
  from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union
  import numpy
  from .utils import ExplicitEnum, is_psutil_available, is_tf_available, is_torch_available, is_torch_cuda_available, is_torch_tpu_available, requires_backends
label_desc: Use image node_id 1 to create a new TrainerMemoryTracker object  with example: obj = TrainerMemoryTracker(skip_memory_metrics)