Skip to content

[SimplifyExpr] Simplify consecutive adds with constants#9671

Merged
comaniac merged 1 commit intoapache:mainfrom
crazydemo:dev-simplify_expr
Dec 10, 2021
Merged

[SimplifyExpr] Simplify consecutive adds with constants#9671
comaniac merged 1 commit intoapache:mainfrom
crazydemo:dev-simplify_expr

Conversation

@crazydemo
Copy link

To make FoldConstant able to fuse pattern conv add add relu (comes from conv bias_add bn relu) into conv add relu.
A simplifyConsecuitiveAdd pattern are added in simplify_expr pass.
Related RFC
Test case is also added in "test_pass_simplify_expr.py"

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM. Just some coding style comments.

Comment on lines 595 to 597
DFPattern add_op1_ = IsOp("add");
DFPattern add_op2_ = IsOp("add");
pattern_ = add_op2_({add_op1_({x_, const1_}), const2_});
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Only private class members need the underline suffix.
  2. You actually don't need two add_ops because all ops are the same.
  3. Might be better to add a comment saying pattern matching supports commutative property for addition so this pattern already covers all possible cases.
Suggested change
DFPattern add_op1_ = IsOp("add");
DFPattern add_op2_ = IsOp("add");
pattern_ = add_op2_({add_op1_({x_, const1_}), const2_});
DFPattern add_op = IsOp("add");
pattern_ = add_op({add_op({x_, const1_}), const2_});

@comaniac comaniac changed the title add simplify consetuitive add pattern in simplify expr pass [SimplifyExpr] Simplify consecutive adds with constants Dec 9, 2021
@comaniac comaniac merged commit 01599d1 into apache:main Dec 10, 2021
@comaniac
Copy link
Contributor

Thanks @crazydemo

ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 12, 2022
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
@crazydemo crazydemo deleted the dev-simplify_expr branch April 14, 2022 03:18
qsqqsqqsq-intellif pushed a commit to qsqqsqqsq-intellif/tvm that referenced this pull request Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants