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

[frontend] Fix bugs in maxpool2d_simplify and rename MaxPool2dOp for clarity #335

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions frontend/Python/graph/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,19 @@ def args(self):
@property
def kwargs(self):
return self._keyword_arguments

@property
def parents(self):
return self._parents

@property
def children(self):
return self._children

@property
def name(self):
return self._name

@name.setter
def name(self, new_name):
self._name = new_name
Expand Down
15 changes: 13 additions & 2 deletions frontend/Python/graph/transform/useless_op_eliminate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ def maxpool2d_simplify(graph: Graph):
and getitem_node.args[1] == 0
):
new_node = MaxPool2dOp()
new_node.name = getitem_node.name
new_node.name = node.name.replace("_with_indices", "")
for arg in node.args:
new_node.add_argument(arg)
for parent in node._parents:
new_node.add_parent(parent)
parent_node = graph.node_table[parent]
for cindex, child in enumerate(parent_node.children):
if child == node.name:
parent_node.children[cindex] = new_node.name
for child in getitem_node._children:
new_node.add_children(child)
child_node = graph.node_table[child]
for pindex, parent in enumerate(child_node.parents):
if parent == getitem_node.name:
child_node.parents[pindex] = new_node.name
for aindex, arg in enumerate(child_node.args):
if arg == getitem_node.name:
child_node.args[aindex] = new_node.name
new_node.tensor_meta["shape"] = getitem_node.tensor_meta[
"shape"
]
Expand All @@ -63,4 +74,4 @@ def maxpool2d_simplify(graph: Graph):
for j, op in enumerate(graph.body):
if op == getitem_node:
graph.body[j] = new_node
break
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove the empty line.