Skip to content

Commit 78a7ac3

Browse files
committed
Verifies we don't need ops.
1 parent b81b2f8 commit 78a7ac3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tf2onnx/graph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def input(self):
5656

5757
@input.setter
5858
def input(self, val):
59+
# The setter can catch that all inputs are change
60+
# but it cannot catch that one input is changed.
61+
# That's method replace_input and replace_inputs must
62+
# be used to change inputs to let the graph instance
63+
# update its internal indices.
5964
self._input = copy.deepcopy(val)
6065

6166
@property
@@ -1291,6 +1296,19 @@ def replace_all_inputs(self, ops, old_input, new_input):
12911296
# This means old_input is a final output.
12921297
to_ops = set()
12931298

1299+
# Verification that we can use the index to
1300+
# remove nodes.
1301+
for node in ops:
1302+
if old_input in node.input:
1303+
if old_input not in self._input_to_node_name:
1304+
raise RuntimeError(
1305+
"Input %r of node %r, old_input %r not in _input_to_node_name." % (
1306+
old_input, node.name, old_input))
1307+
if node.name not in self._input_to_node_name[old_input]:
1308+
raise RuntimeError(
1309+
"Input %r of node %r, node %r not in _input_to_node_name[%r]." % (
1310+
old_input, node.name, node.name, old_input))
1311+
12941312
for node in ops:
12951313
if old_input in node.input and new_input in node.output:
12961314
raise RuntimeError("creating a circle in the graph is not allowed: " + node.name)

0 commit comments

Comments
 (0)