Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a regression bug that transpose optimizer doesn't work as expected. #2313

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tf2onnx/optimizer/transpose_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,15 @@ def _add_handler(self, trans, node):
return True
return self._handle_node_having_branches(trans, node)

def _output_node_has_single_consumer_node(self, node):
def _output_has_no_multiple_consumers(self, node):
output_node = self._g.get_node_by_name(node.output[0])
return output_node and output_node.output and self._nodes_has_single_consumer_node([output_node])
return True if output_node is None \
else (output_node.output and self._nodes_has_single_consumer_node([output_node]))

def _transpose_handler(self, trans, node):
perm = trans.get_attr_value("perm")
perm_inv = invert_perm(perm)
if is_tranpose_of_type(node, perm_inv) and self._output_node_has_single_consumer_node(node):
if is_tranpose_of_type(node, perm_inv) and self._output_has_no_multiple_consumers(node):
for g in {self._g, node.graph}:
g.replace_all_inputs(node.output[0], trans.input[0]) # ops=g.get_nodes()

Expand Down
Loading