code: def _get_obj_state(obj):
      # Get the state of the python subclass
      # This loosely mimicks the function on the object class but since Tensor do not inherit
      # from it, we cannot call that function directly
      # https://github.com/python/cpython/blob/c83919bd635f4433f1c6ae8504996a9fe3c215e5/Objects/typeobject.c#L4891
      # Note that starting with Python 3.11, this `__getstate__` is always defined and thus
      # the else branch will never be taken.
      getstate_fn = getattr(obj, "__getstate__", None)
      if getstate_fn:
          state = getstate_fn()
      else:
          slots_to_save = copyreg._slotnames(obj.__class__)  # type: ignore[attr-defined]
          if slots_to_save:
              state = (
                  obj.__dict__,
                  {
                      name: getattr(obj, name)
                      for name in slots_to_save
                      if hasattr(obj, name)
                  },
              )
          else:
              state = obj.__dict__
  
      return state
  
imports: import copyreg
  import functools
  import sys
  import traceback
  import warnings
  from collections import defaultdict
  from typing import Any, DefaultDict, List, Optional
  import torch
label_desc: Use image node_id 19 for calling a global function with example usage: _get_obj_state(obj) and returns: state