def strip_and_get_tensors_and_control_dependencies(
    flat_tensor_list: Iterable[tf.Tensor]
) -> Tuple[Iterable[tf.Tensor], Iterable[tf.Operation]]:
  """Strips automatic control dependencies from `flat_tensor_list`.

  Args:
    flat_tensor_list: A flattened list of output tensors from a tf.function.

  Returns:
    A tuple of:
      Tensors from `flat_tensor_list` with control dependencies removed.
      The set of control dependency ops that `flat_tensor_list` depended on.
  """
  # If an automatic control dependency node was added, all tensors in
  # `flat_tensor_list` will be the result of Identity ops with the original
  # tensor as an input and the automatic control dependencies as control inputs.
  if all(tensor.op.type == 'Identity' and len(tensor.op.inputs) == 1
         for tensor in flat_tensor_list):
    control_dependency_ops = [t.op.control_inputs for t in flat_tensor_list]
    return ([t.op.inputs[0] for t in flat_tensor_list],
            set(itertools.chain(*control_dependency_ops)))
  else:
    return flat_tensor_list, set()
Strips automatic control dependencies from `flat_tensor_list`.

  Args:
    flat_tensor_list: A flattened list of output tensors from a tf.function.

  Returns:
    A tuple of:
      Tensors from `flat_tensor_list` with control dependencies removed.
      The set of control dependency ops that `flat_tensor_list` depended on.
  
tensorflow_transform/tf2_utils.py