code: def convert_to_eager_tensor(
      value, ctx, dtype=None
  ) -> ops._EagerTensorBase:
      """Converts the given `value` to an `EagerTensor`.
  
      Note that this function could return cached copies of created constants for
      performance reasons.
  
      Args:
        value: value to convert to EagerTensor.
        ctx: value of context.context().
        dtype: optional desired dtype of the converted EagerTensor.
  
      Returns:
        EagerTensor created from value.
  
      Raises:
        TypeError: if `dtype` is not compatible with the type of t.
      """
      if isinstance(value, np.ndarray):
          # Make a copy explicitly because the EagerTensor might share the underlying
          # memory with the input array. Without this copy, users will be able to
          # modify the EagerTensor after its creation by changing the input array.
          value = value.copy()
      if isinstance(value, ops.EagerTensor):
          if dtype is not None and value.dtype != dtype:
              raise TypeError(
                  f"Expected tensor {value} with dtype {dtype!r}, but got "
                  f"dtype {value.dtype!r}."
              )
          return value
      if dtype is not None:
          try:
              dtype = dtype.as_datatype_enum
          except AttributeError:
              dtype = dtypes.as_dtype(dtype).as_datatype_enum
      ctx.ensure_initialized()
      return ops.EagerTensor(value, ctx.device_name, dtype)
  
imports: from typing import Union
  import numpy
  from tensorflow.core.framework import types_pb2
  from tensorflow.core.protobuf import struct_pb2
  from tensorflow.python.eager import context
  from tensorflow.python.eager import execute
  from tensorflow.python.framework import constant_tensor_conversion
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_conversion_registry
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.profiler import trace
  from tensorflow.python.saved_model import nested_structure_coder
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 4 for calling a global function with example usage: convert_to_eager_tensor(value, ctx, dtype) and returns: ops, value