returnn.extern.graph_editor.util#

Utility functions for the graph_editor.

returnn.extern.graph_editor.util.make_list_of_op(ops, check_graph=True, allow_graph=True, ignore_ts=False)[source]#

Convert ops to a list of tf.Operation.

Args:
ops: can be an iterable of tf.Operation, a tf.Graph or a single

operation.

check_graph: if True check if all the operations belong to the same graph. allow_graph: if False a tf.Graph cannot be converted. ignore_ts: if True, silently ignore tf.Tensor.

Returns:

A newly created list of tf.Operation.

Raises:
TypeError: if ops cannot be converted to a list of tf.Operation or,

if check_graph is True, if all the ops do not belong to the same graph.

returnn.extern.graph_editor.util.get_tensors(graph)[source]#

get all the tensors which are input or output of an op in the graph.

Args:

graph: a tf.Graph.

Returns:

A list of tf.Tensor.

Raises:

TypeError: if graph is not a tf.Graph.

returnn.extern.graph_editor.util.make_list_of_t(ts, check_graph=True, allow_graph=True, ignore_ops=False)[source]#

Convert ts to a list of tf.Tensor.

Args:

ts: can be an iterable of tf.Tensor, a tf.Graph or a single tensor. check_graph: if True check if all the tensors belong to the same graph. allow_graph: if False a tf.Graph cannot be converted. ignore_ops: if True, silently ignore tf.Operation.

Returns:

A newly created list of tf.Tensor.

Raises:
TypeError: if ts cannot be converted to a list of tf.Tensor or,

if check_graph is True, if all the ops do not belong to the same graph.

returnn.extern.graph_editor.util.get_generating_ops(ts)[source]#

Return all the generating ops of the tensors in ts.

Args:

ts: a list of tf.Tensor

Returns:

A list of all the generating tf.Operation of the tensors in ts.

Raises:

TypeError: if ts cannot be converted to a list of tf.Tensor.

returnn.extern.graph_editor.util.get_consuming_ops(ts)[source]#

Return all the consuming ops of the tensors in ts.

Args:

ts: a list of tf.Tensor

Returns:

A list of all the consuming tf.Operation of the tensors in ts.

Raises:

TypeError: if ts cannot be converted to a list of tf.Tensor.

class returnn.extern.graph_editor.util.ControlOutputs(graph)[source]#

The control outputs topology.

Create a dictionary of control-output dependencies.

Args:

graph: a tf.Graph.

Returns:
A dictionary where a key is a tf.Operation instance and the

corresponding value is a list of all the ops which have the key as one of their control-input dependencies.

Raises:

TypeError: graph is not a tf.Graph.

update()[source]#

Update the control outputs if the graph has changed.

get_all()[source]#
get(op)[source]#

return the control outputs of op.

property graph[source]#
returnn.extern.graph_editor.util.placeholder_name(t=None, scope=None, prefix='geph')[source]#

Create placeholder name for the graph editor.

Args:
t: optional tensor on which the placeholder operation’s name will be based

on

scope: absolute scope with which to prefix the placeholder’s name. None

means that the scope of t is preserved. “” means the root scope.

prefix: placeholder name prefix.

Returns:
A new placeholder name prefixed by “geph”. Note that “geph” stands for

Graph Editor PlaceHolder. This convention allows to quickly identify the placeholder generated by the Graph Editor.

Raises:

TypeError: if t is not None or a tf.Tensor.

returnn.extern.graph_editor.util.make_placeholder_from_tensor(t, scope=None, prefix='geph')[source]#

Create a tf.compat.v1.placeholder for the Graph Editor.

Note that the correct graph scope must be set by the calling function.

Args:
t: a tf.Tensor whose name will be used to create the placeholder (see

function placeholder_name).

scope: absolute scope within which to create the placeholder. None means

that the scope of t is preserved. “” means the root scope.

prefix: placeholder name prefix.

Returns:

A newly created tf.compat.v1.placeholder.

Raises:

TypeError: if t is not None or a tf.Tensor.

returnn.extern.graph_editor.util.make_placeholder_from_dtype_and_shape(dtype, shape=None, scope=None, prefix='geph')[source]#

Create a tf.compat.v1.placeholder for the Graph Editor.

Note that the correct graph scope must be set by the calling function. The placeholder is named using the function placeholder_name (with no tensor argument).

Args:

dtype: the tensor type. shape: the tensor shape (optional). scope: absolute scope within which to create the placeholder. None means

that the scope of t is preserved. “” means the root scope.

prefix: placeholder name prefix.

Returns:

A newly created tf.placeholder.