class_docstr: Run in ``TorchDispatchMode`` to get memory stats at operator level.
class_docstr_tok: ["Run","in","``","TorchDispatchMode","``","to","get","memory","stats","at","operator","level","."]
code: def __torch_dispatch__(self, func, types, args=..., kwargs=None):
      rs = func(*args, **kwargs)
      if func == torch.ops.aten.detach.default:
          return rs
      func_name: str = (
          self.memory_tracker._cur_module_name
          + "."
          + func.__name__
          + "_"
          + str(self.memory_tracker._operator_names[func.__name__])
      )
      self.memory_tracker._operator_names[func.__name__] = (
          self.memory_tracker._operator_names[func.__name__] + 1
      )
      self.memory_tracker._record_memory_stats(func_name)
  
      return rs
  
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 2 for calling the MemoryProfileDispatchMode obj's underlying member method code with example usage: obj.__torch_dispatch__(func, types, args, kwargs) and returns: rs, rs