returnn.extern.graph_editor.reroute#

Various function for graph rerouting.

returnn.extern.graph_editor.reroute.swap_ts(ts0, ts1, can_modify=None, cannot_modify=None)[source]#

For each tensor’s pair, swap the end of (t0,t1).

B0 B1 B0 B1 | | => X A0 A1 A0 A1

Args:

ts0: an object convertible to a list of tf.Tensor. ts1: an object convertible to a list of tf.Tensor. can_modify: iterable of operations which can be modified. Any operation

outside within_ops will be left untouched by this function.

cannot_modify: iterable of operations which cannot be modified.

Any operation within cannot_modify will be left untouched by this function.

Returns:

The number of individual modifications made by the function.

Raises:

TypeError: if ts0 or ts1 cannot be converted to a list of tf.Tensor. TypeError: if can_modify or cannot_modify is not None and cannot be

converted to a list of tf.Operation.

returnn.extern.graph_editor.reroute.reroute_ts(ts0, ts1, can_modify=None, cannot_modify=None)[source]#

For each tensor’s pair, replace the end of t1 by the end of t0.

B0 B1 B0 B1 | | => |/ A0 A1 A0 A1

The end of the tensors in ts1 are left dangling.

Args:

ts0: an object convertible to a list of tf.Tensor. ts1: an object convertible to a list of tf.Tensor. can_modify: iterable of operations which can be modified. Any operation

outside within_ops will be left untouched by this function.

cannot_modify: iterable of operations which cannot be modified. Any

operation within cannot_modify will be left untouched by this function.

Returns:

The number of individual modifications made by the function.

Raises:

TypeError: if ts0 or ts1 cannot be converted to a list of tf.Tensor. TypeError: if can_modify or cannot_modify is not None and cannot be

converted to a list of tf.Operation.

returnn.extern.graph_editor.reroute.swap_inputs(sgv0, sgv1)[source]#

Swap all the inputs of sgv0 and sgv1 (see reroute_inputs).

returnn.extern.graph_editor.reroute.reroute_inputs(sgv0, sgv1)[source]#

Re-route all the inputs of two subgraphs.

Args:
sgv0: the first subgraph to have its inputs swapped. This argument is

converted to a subgraph using the same rules than the function subgraph.make_view.

sgv1: the second subgraph to have its inputs swapped. This argument is

converted to a subgraph using the same rules than the function subgraph.make_view.

Returns:
A tuple (sgv0, sgv1) of subgraph views with their inputs swapped.

Note that the function argument sgv0 and sgv1 are also modified in place.

Raises:
StandardError: if sgv0 or sgv1 cannot be converted to a SubGraphView using

the same rules than the function subgraph.make_view.

returnn.extern.graph_editor.reroute.swap_outputs(sgv0, sgv1)[source]#

Swap all the outputs of sgv0 and sgv1 (see reroute_outputs).

returnn.extern.graph_editor.reroute.reroute_outputs(sgv0, sgv1)[source]#

Re-route all the outputs of two operations.

Args:
sgv0: the first subgraph to have its outputs swapped. This argument is

converted to a subgraph using the same rules than the function subgraph.make_view.

sgv1: the second subgraph to have its outputs swapped. This argument is

converted to a subgraph using the same rules than the function subgraph.make_view.

Returns:
A tuple (sgv0, sgv1) of subgraph views with their outputs swapped.

Note that the function argument sgv0 and sgv1 are also modified in place.

Raises:
StandardError: if sgv0 or sgv1 cannot be converted to a SubGraphView using

the same rules than the function subgraph.make_view.

returnn.extern.graph_editor.reroute.swap_ios(sgv0, sgv1)[source]#

Swap the inputs and outputs of sgv1 to sgv0 (see _reroute_sgv).

returnn.extern.graph_editor.reroute.reroute_ios(sgv0, sgv1)[source]#

Re-route the inputs and outputs of sgv0 to sgv1 (see _reroute_sgv).

returnn.extern.graph_editor.reroute.remove_control_inputs(op, cops)[source]#

Remove the control inputs cops from co.

Warning: this function is directly manipulating the internals of the tf.Graph.

Args:

op: a tf.Operation from which to remove the control inputs. cops: an object convertible to a list of tf.Operation.

Raises:

TypeError: if op is not a tf.Operation. ValueError: if any cop in cops is not a control input of op.

returnn.extern.graph_editor.reroute.add_control_inputs(op, cops)[source]#

Add the control inputs cops to op.

Warning: this function is directly manipulating the internals of the tf.Graph.

Args:

op: a tf.Operation to which the control inputs are added. cops: an object convertible to a list of tf.Operation.

Raises:

TypeError: if op is not a tf.Operation ValueError: if any cop in cops is already a control input of op.