class_docstr: Collect and plot the memory stats at operator level.
  
  Includes ``memories_allocated``, ``memories_active`` and ``memories_reserved``.
  It also prints a summary for the top 20 operators that generate the most memories.
  
  Example usage:
  
      >>> # xdoctest: +SKIP(failing)
      >>> net.cuda()
      >>> input = input.cuda()
  
      >>> mem_tracker = MemoryTracker()
      >>> mem_tracker.start_monitor(net)
  
      >>> net.zero_grad(True)
      >>> loss = net(input)
      >>> if isinstance(loss, dict):
      >>>    loss = loss['out']
      >>> loss.sum().backward()
      >>> net.zero_grad(set_to_none=True)
  
      >>> mem_tracker.stop()
      >>> mem_tracker.summary()
      >>> mem_tracker.show_traces()
class_docstr_tok: ["Collect","and","plot","the","memory","stats","at","operator","level",".","Includes","``","memories_allocated","``",",","``","memories_active","``","and","``","memories_reserved","``",".","It","also","prints","a","summary","for","the","top","20","operators","that","generate","the","most","memories",".","Example","usage",":",">",">",">","#","xdoctest",":","+SKIP","(","failing",")",">",">",">","net.cuda","(",")",">",">",">","input","=","input.cuda","(",")",">",">",">","mem_tracker","=","MemoryTracker","(",")",">",">",">","mem_tracker.start_monitor","(","net",")",">",">",">","net.zero_grad","(","True",")",">",">",">","loss","=","net","(","input",")",">",">",">","if","isinstance","(","loss",",","dict",")",":",">",">",">","loss","=","loss","[","'out","'","]",">",">",">","loss.sum","(",")",".backward","(",")",">",">",">","net.zero_grad","(","set_to_none=True",")",">",">",">","mem_tracker.stop","(",")",">",">",">","mem_tracker.summary","(",")",">",">",">","mem_tracker.show_traces","(",")"]
docstr: Print out the top operators that generate the most memories.
  
  The number of the top operators can be configured.
docstr_tok: ["Print","out","the","top","operators","that","generate","the","most","memories",".","The","number","of","the","top","operators","can","be","configured","."]
code: def summary(self, top: int = 20) -> None:
      """
      Print out the top operators that generate the most memories.
  
      The number of the top operators can be configured.
      """
      op_diff: Dict[str, float] = defaultdict(float)
      op_name, previous_allocated_memory = self.memories_allocated[0]
      for i in range(1, self._op_index):
          op_name, current_allocated_memory = self.memories_allocated[i]
          op_diff[op_name] = (
              current_allocated_memory - previous_allocated_memory
          )
          previous_allocated_memory = current_allocated_memory
  
      print("------------------------------------------------")
      print(f"The number of cuda retries are: {self._num_cuda_retries}")
      print(f"Top {top} ops that generates memory are:")
      for k, v in sorted(
          op_diff.items(), key=lambda item: item[1], reverse=True
      )[:top]:
          print(f"{k}: {v}MB")
      print("------------------------------------------------")
  
imports: from collections import defaultdict
  from itertools import chain
  import pickle
  from typing import Any, Callable, Dict, List, no_type_check, Sequence
  import torch
  import torch.nn
  from torch.utils.hooks import RemovableHandle
  from torch.utils._python_dispatch import TorchDispatchMode
label_desc: Use image node_id 4 for calling the MemoryTracker obj's underlying member method code with example usage: obj.summary(top) without return types