code: def __init__(self, ctx):
      def pack_hook(t):
          tid = _get_tid(t)
          sid = _get_sid(t)
          # Tensors saved for backward have an entry in _tid_to_weakhandle
          handle: Optional[_Handle] = None
  
          # Save aliasing information
          ctx.sid_to_tid[sid].add(tid)
  
          # NB: The same tensor (of the same version) can be saved multiple times
          if tid not in ctx.tid_to_weakhandle:
              handle = _Handle()
              ctx.tid_to_weakhandle[tid] = handle
              ctx.original[handle] = t
          else:
              # Store an additional strong reference to the handle
              handle = ctx.tid_to_weakhandle[tid]
          return handle
  
      def unpack_hook(tup):
          handle = tup
          error_msg = (
              "Trying to backward outside of the 'allow_mutation_on_saved_tensors' context"
              "in which the graph was originally recorded."
          )
          assert _allow_mutation_on_saved_tensors_enabled, error_msg
          if handle in ctx.cloned:
              res = ctx.cloned[handle]
          else:
              assert handle in ctx.original, error_msg
              res = ctx.original[handle]
          return res
  
      super().__init__(pack_hook, unpack_hook)
  
imports: import abc
  import collections
  import contextlib
  import logging
  import weakref
  from collections import defaultdict, namedtuple
  from typing import Any, Callable, Deque, Dict, List, Optional, Sequence, Set, Tuple
  import torch
  from torch.autograd.variable import Variable
  from torch.utils._python_dispatch import TorchDispatchMode
  from torch.utils.hooks import RemovableHandle
label_desc: Use image node_id 1 to create a new _swap_with_cloned object from inherited base classes: saved_tensors_hooks with example: obj = _swap_with_cloned(ctx)