Skip to content

Commit ff42c19

Browse files
committed
fix the case : tensor output in parent graph ---> Identity --> graph output
1 parent 75abbc2 commit ff42c19

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/test_optimizers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def test_identity_output_as_multiple_graph_outputs(self):
208208
self.run_identity_compare(["Z1", "Z2"], {"X": np.random.randn(2, 3, 4, 5).astype(np.float32)},
209209
model_proto, remaining_identity_num=1)
210210

211-
212211
def test_identity_in_subgraph_non_graph_output(self):
213212
node1 = helper.make_node("Add", ["X", "X"], ["Y"], name="add")
214213

tf2onnx/optimizer/identity_optimizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def _handle_non_graph_output_identity(self, graph, identity):
7373
def _handle_graph_output_identity(self, graph, identity, graph_outputs):
7474
input_id = identity.input[0]
7575
input_node = identity.inputs[0]
76+
77+
if input_node.graph != graph:
78+
# If input node is in parent graph, we don't handle it now
79+
log.debug("input node in parent graph, skip")
80+
return False
81+
7682
if input_node.is_graph_input():
7783
# Identity between input and output should not be removed.
7884
log.debug("skip identity between input and output")

0 commit comments

Comments
 (0)