def retrieve_sources(sinks, ignore_control_dependencies=False):
  """Captures subgraph between sources and sinks.

  Walk a Graph backwards from `sinks` and return any sources encountered in the
  subgraph. This util is refactored from `_map_subgraph` in
  tensorflow/.../ops/op_selector.py.

  Arguments:
    sinks:  An iterable of Operations where the subgraph terminates.
    ignore_control_dependencies: (Optional) If `True`, ignore any
      `control_inputs` for all ops while walking the graph.

  Returns:
    The set of placeholders upon which `sinks` depend. This could also contain
    placeholders representing `captures` in the graph.
  """
  stop_at_tensors = object_identity.ObjectIdentitySet()
  ops_to_visit = object_identity.ObjectIdentitySet(sinks)
  visited_ops = object_identity.ObjectIdentitySet()
  potential_extra_sources = object_identity.ObjectIdentitySet()
  while ops_to_visit:
    op = ops_to_visit.pop()
    visited_ops.add(op)

    if op.type == 'Placeholder':
      potential_extra_sources.update(op.outputs)

    input_ops = [t.op for t in op.inputs if t not in stop_at_tensors]
    if not ignore_control_dependencies:
      input_ops = itertools.chain(input_ops, op.control_inputs)
    for input_op in input_ops:
      if input_op not in visited_ops:
        ops_to_visit.add(input_op)

  return potential_extra_sources
Captures subgraph between sources and sinks.

  Walk a Graph backwards from `sinks` and return any sources encountered in the
  subgraph. This util is refactored from `_map_subgraph` in
  tensorflow/.../ops/op_selector.py.

  Arguments:
    sinks:  An iterable of Operations where the subgraph terminates.
    ignore_control_dependencies: (Optional) If `True`, ignore any
      `control_inputs` for all ops while walking the graph.

  Returns:
    The set of placeholders upon which `sinks` depend. This could also contain
    placeholders representing `captures` in the graph.
  
tensorflow_transform/graph_tools.py