[Relay] Improve the "clip" op optimization in simplify expr pass#15068
[Relay] Improve the "clip" op optimization in simplify expr pass#15068masahi merged 7 commits intoapache:mainfrom
Conversation
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
…is is to avoid destroying the structure required by LegalizeQnnOpForDnnl; 2. code reformatted.
|
cc @ibsidorenko |
…dd a test case of bfloat16 in test_pass_simplify_expr.
| const ClipAttrs* clip_attrs = clip_node->attrs.as<ClipAttrs>(); | ||
|
|
||
| // TODO(kfeng123): For now, the arg of "clip" is forced to not be "qnn.requantize" and | ||
| // "ann.add". This is to avoid destroying the structure required by LegalizeQnnOpForDnnl |
There was a problem hiding this comment.
Thanks. Typo fixed.
ibsidorenko
left a comment
There was a problem hiding this comment.
By the way, what is motivation for this change? New case came from the real life DNN model... or this is required for some kind of synthetic test?
The motivation is just to improve simplify_expr pass. Did not come from a real model or a test case... Nevertheless, this improvement may be practical after I develop further improvements. (I plan to give a series of PR to improve simplify_expr and related things shortly. There is still a lot of room for improvement in simplify_expr.) Suppose we already have an improved optimization for "cast" op (although we do not have for now). Consider the following model fragment: Note that the “cast” and "transpose" are commutative, and a lazy cast make transpose exected in uint8, which is faster: Next, note that the “cast” and "clip" are commutative, which leads to For now, we can use the pass in this PR to remove clip. (Note that the original pass can not remove the clip in this case!) |
This PR improves the optimization of clip in simplify expr pass.
Previously, there is a SimplifyCastClip class, it deals with the pattern "cast->clip": it checks if the a_min/a_max values of clip equals the min/max values of the data type of cast OP.
This PR improve SimplifyCastClip in 2 aspects:
Since the new optimization of "clip" does not rely on "cast" op, the name is changed to SimplifyClip.