class_docstr: A ``TorchDispatchMode`` allows you to override the meaning of all
  ``__torch_dispatch__`` overrideable functions within a dynamic scope,
  without having to actually create a tensor subclass or manually
  monkey-patch functions in the PyTorch API.  Some common situations
  where you should use a mode:
  
      * You want to override the meaning of factory functions, or other
        functions that do not otherwise take a tensor as an argument
        (these cannot be overridden with tensor subclasses).
  
      * You want to override the behavior of all functions without needing
        to wrap your inputs in tensor subclasses; e.g., if you are just
        interested in logging intermediate computations.
  
      * You want to control the order of execution of various tensor
        subclasses explicitly, rather than implicitly via the return of
        ``NotImplemented``.
  
  Independent subclasses of :class:`TorchDispatchMode` are compositional:
  modes can be pushed onto a stack using ``with MyMode():``.
  When you call functions in the PyTorch API inside your
  ``__torch_dispatch__`` implementation, by default, they will forward on to
  the next mode on the mode stack.  If you want recursively call back into
  your current ``__torch_dispatch__`` implementation, either explicitly
  invoke ``self.__torch_dispatch__(...)``, or use the context manager
  ``__torch_dispatch__(self)`` to make PyTorch
  API self-referential (beware of infinite loops, in this case!)
code: def __exit__(self, exc_type, exc_val, exc_tb):
      mb_dk_or_mode_key = self.__dict__.get("_dispatch_key", None)
      if mb_dk_or_mode_key is None:
          # Today, mode keys are not used at all in the per-dispatch-key-mode logic (for pre-dispatch)
          # We should probably revisit this.
          mb_dk_or_mode_key = self.__dict__.get("_mode_key", None)
      _pop_mode(mb_dk_or_mode_key)
  
imports: import contextlib
  from typing import Optional, Union, List, Set, Dict, Any
  import warnings
  from dataclasses import dataclass
  import torch
  import torchgen
  from torch._C import _len_torch_dispatch_stack, _get_dispatch_stack_at, _pop_torch_dispatch_stack, _push_on_torch_dispatch_stack, DispatchKey
label_desc: Use image node_id 4 for calling the TorchDispatchMode obj's underlying member method code with example usage: obj.__exit__(exc_type, exc_val, exc_tb) without return types