def hashable_tensor_or_op(tensor_or_op):
  """Returns a hashable reference to a Tensor if given a Tensor/CompositeTensor.

  Use deref_tensor_or_op on the result to get the Tensor (or SparseTensor).

  Args:
    tensor_or_op: A `tf.Tensor`, `tf.CompositeTensor`, or other type.

  Returns:
    A hashable representation for the Tensor or CompositeTensor, or the original
    value for other types.
  """
  if isinstance(tensor_or_op, tf.Tensor):
    return tensor_or_op.ref()
  if isinstance(tensor_or_op, composite_tensor.CompositeTensor):
    return _CompositeTensorRef(
        type_spec=tf.type_spec_from_value(tensor_or_op),
        list_of_refs=tuple(
            hashable_tensor_or_op(component) for component in tf.nest.flatten(
                tensor_or_op, expand_composites=True)))
  return tensor_or_op
Returns a hashable reference to a Tensor if given a Tensor/CompositeTensor.

  Use deref_tensor_or_op on the result to get the Tensor (or SparseTensor).

  Args:
    tensor_or_op: A `tf.Tensor`, `tf.CompositeTensor`, or other type.

  Returns:
    A hashable representation for the Tensor or CompositeTensor, or the original
    value for other types.
  
tensorflow_transform/tf_utils.py