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

Add sign to idempotent ops list #139

Open
wants to merge 2 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct EliminateConsecutiveIdempotentOps final : public PredicateBasedPass {

bool patternMatchPredicate(Node* node) override {
static const std::unordered_set<std::string> idempotent_ops = {
"Ceil", "Floor", "Round", "Relu", "Reshape"};
"Ceil", "Floor", "Round", "Relu", "Reshape", "Sign"};
for (const auto& op : idempotent_ops) {
// TODO: support uses().size() > 1 for ops except Reshape
if (CheckKind(node, Symbol(op), 0, Symbol(op)) &&
Expand Down
20 changes: 20 additions & 0 deletions onnxoptimizer/test/optimizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4597,6 +4597,26 @@ def test_eliminate_consecutive_idempotent_op(self):
assert optimized_model.graph.node[0].op_type == "Constant"
assert optimized_model.graph.node[1].op_type == "Reshape"

def test_eliminate_consecutive_idempotent_sign_op(self):
model = parser.parse_model("""
<
ir_version: 7,
opset_import:["": 11]
>
agraph (float[1, 2, 3] X) => (float[1, 2, 3] Z)
{
T1 = Sign(X)
T2 = Sign(T1)
T3 = Sign(T2)
Z = Sign(T3)
}
""")

optimized_model = self._optimized(
model, ['eliminate_consecutive_idempotent_ops', 'eliminate_deadend'], True)
assert len(optimized_model.graph.node) == 1
assert optimized_model.graph.node[0].op_type == "Sign"


if __name__ == "__main__":
unittest.main()