code: def _get_all_trackables(root, exclude_set):
      """Return the list of checkpointable trackables dependent on `root`.
  
      Args:
        root: The root trackable from where we get all its dependent trackables.
        exclude_set: An ObjectIdentitySet of Trackables to exclude before returning.
            Each element in `exclude_set` is a specific instance of a `Trackable`
            and appears precisely once in `TrackableView(root).descendants()`.
  
      Returns:
        saveable_trackables: All trackables that are saveable in `all_trackables`
            (see definition of "saveable" in `_trackable_needs_to_be_saved()`). A
            subset of `all_trackables`.
        all_trackables: All trackables returned by `TrackableView`'s `descendants()`
            after excluding `exclude_set`. A superset of `saveable_trackables`.
      """
      all_trackables = trackable_view.TrackableView(
          root=root
      ).descendants()
  
      # Kick out the trackable we want to exclude.
      # The goal of writing such loop is to only scan the list once and stop
      # scanning as early as possible (unlike filtering with list comprehension).
      trackable_index = 0
      while trackable_index < len(all_trackables) and exclude_set:
          # While we have not excluded all items, or gone through all trackables.
          if all_trackables[trackable_index] in exclude_set:
              # If want to exclude this trackable, we pop it and do not update ptr
              exclude_set.discard(all_trackables[trackable_index])
              all_trackables.pop(trackable_index)
          else:
              # Otherwise update ptr
              trackable_index += 1
  
      # Kick out trackables that do not need to be saved (e.g. ListWrapper, etc.)
      # We define any trackable that does not implement `_serialize_to_tensor` or
      # `_gather_saveables` as "no need to be saved". If the trackable has one or
      # both of the methods defined, it should have `_copy_trackable_to_cpu`
      # defined; if not, we will raise warning in `_copy_to_cpu()`. In case of
      # special case, we also check whether a trackable (who has neither of the
      # other two methods defined) defines `_copy_trackable_to_cpu` only; we still
      # define such cases as "needs to be saved".
      def _trackable_needs_to_be_saved(obj):
          """Returns whether a trackable needs to be saved.
  
          Returns a bool to indicate whether obj's class has `_serialize_to_tensors`,
          `gather_saveables_for_checkpoint`, or `_copy_trackable_to_cpu` defined.
  
          Args:
            obj: A Trackable object.
          """
          if hasattr(obj, "__dict__"):
              # Data structure proxy wrappers don't have __dict__.
              if (
                  "_serialize_to_tensors" in obj.__dict__
                  or "_gather_saveables_for_checkpoint" in obj.__dict__
                  or "_copy_trackable_to_cpu" in obj.__dict__
              ):
                  return True
  
          # Use MRO so that if a parent class has one of the three methods, we still
          # consider `t` as needed to be saved.
          for t in type(obj).mro():
              if t is base.Trackable:
                  # Base class always has them implemented, but would raise error.
                  continue
              elif (
                  "_serialize_to_tensors" in t.__dict__
                  or "_gather_saveables_for_checkpoint" in t.__dict__
                  or "_copy_trackable_to_cpu" in t.__dict__
              ):
                  return True
  
          return False
  
      saveable_trackables = [
          x for x in all_trackables if _trackable_needs_to_be_saved(x)
      ]
  
      return saveable_trackables, all_trackables
  
imports: import atexit
  import copy
  import queue
  import threading
  import time
  import weakref
  from absl import logging
  from tensorflow.python.checkpoint import checkpoint_context
  from tensorflow.python.checkpoint import trackable_view
  from tensorflow.python.distribute import device_util
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.eager import executor
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import variables
  from tensorflow.python.saved_model.pywrap_saved_model import metrics
  from tensorflow.python.trackable import base
  from tensorflow.python.util import object_identity
label_desc: Use image node_id 2 for calling a global function with example usage: _get_all_trackables(root, exclude_set) and returns: saveable_trackables,  all_trackables, False, True, True