code: def _get_current_device_spec():
      """Best guess at checking the current device string in eager and graph mode.
  
      Using callable in `with tf.device(...)` for Graph mode will probably break it.
      The graph in use is assumed to be current default graph.
      """
      if tf.executing_eagerly():
          # We are not using this `tf.device` with `with ...`,
          # so we do not change the context, it returns _EagerDeviceContext
          dummy_context_manager = tf.device(None)
          # Get the eager.context singleton instance for this thread
          context = dummy_context_manager._ctx
          # DeviceSpec
          return context.device_spec
      else:
          # Get the default graf, we assume that it's the one in use
          g = tf.compat.v1.get_default_graph()
          # Get the top element of _UserDeviceSpec stack - `with tf.device()` pushes to the stack
          # in graph mode.
          spec = g._device_function_stack.peek_top_obj()
          # Try to normalize to DeviceSpec
          return tf.DeviceSpec.from_string(spec.display_name)
  
imports: import sys
  import tensorflow
  from tensorflow.python.data.util import nest
  from tensorflow.python.framework import tensor_shape
  from nvidia.dali import types
  from nvidia.dali import internal
  from nvidia.dali.external_source import _is_external_source, _has_external_source
  from nvidia.dali.external_source import _is_external_source_with_callback
  from nvidia.dali._utils.external_source_impl import _get_generator_from_source_desc
  from nvidia.dali._utils.external_source_impl import _cycle_enabled
  from distutils.version import LooseVersion
  import warnings
  from nvidia.dali_tf_plugin import dali_tf_plugin
  from collections.abc import Mapping, Iterable
label_desc: Use image node_id 13 for calling a global function with example usage: _get_current_device_spec() and returns: context, tf