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: Insert the current module name with backward prefix for the operator name.
docstr_tok: ["Insert","the","current","module","name","with","backward","prefix","for","the","operator","name","."]
code: def _create_backward_hook(self, name: str) -> Callable:
      """Insert the current module name with backward prefix for the operator name."""
  
      def _backward_hook(
          module: nn.Module,
          grad_input: torch.Tensor,
          grad_output: torch.Tensor,
      ) -> None:
          self._cur_module_name = f"{name}.backward"
  
      return _backward_hook
  
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 10 for calling the MemoryTracker obj's underlying member method code with example usage: obj._create_backward_hook(name) and returns: _backward_hook