You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by JoeyChou via Apache TVM Discuss <no...@discuss.tvm.ai> on 2020/10/09 19:01:00 UTC

[Apache TVM Discuss] [Questions] FoldConstant doesn't fold two consecutive add


Hi, I am using TVM to load an MXNet model and saw there is two consecutive `add` that do not get constant folded. Below are three screenshots showing **(1) the Original MXNet model** **(2) the model without `FoldConstant` and `FoldScaleAxis`** **(3) with the relay transforms as below, which has two consecutive `add`**

    relay.transform.RemoveUnusedFunctions(),
    relay.transform.CanonicalizeOps(),
    relay.transform.InferType(), 
    relay.transform.SimplifyInference(),
    relay.transform.FoldConstant(),  # Commented out in (2)
    relay.transform.FoldScaleAxis(), # Commented out in (2)
    relay.transform.EliminateCommonSubexpr(),

**(1) the Original MXNet model**
![image|690x201](upload://41C8UlxYu34t45X9Tq4iZbVYsQ4.png) 

**(2) the model without `FoldConstant` and `FoldScaleAxis`**

    relay.transform.RemoveUnusedFunctions(),
    relay.transform.CanonicalizeOps(),
    relay.transform.InferType(), 
    relay.transform.SimplifyInference(),
    relay.transform.EliminateCommonSubexpr(),

![image|690x450](upload://cpmys9m65ENHSkSe4PlBsKhlgDK.png) 

**(3) with the relay transforms as below, which has two consecutive `add`**

    relay.transform.RemoveUnusedFunctions(),
    relay.transform.CanonicalizeOps(),
    relay.transform.InferType(), 
    relay.transform.SimplifyInference(),
    relay.transform.FoldConstant(),  # Commented out in (2)
    relay.transform.FoldScaleAxis(), # Commented out in (2)
    relay.transform.EliminateCommonSubexpr(),

![image|413x500](upload://ekibEK06pMQwESrzBEUz3TjBRKB.png) 


Some suggestions about how to fold two `add` will be awesome!





---
[Visit Topic](https://discuss.tvm.apache.org/t/foldconstant-doesnt-fold-two-consecutive-add/8132/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/53f01310e2f423bf2a7fd57d98606cf5e232e77657b1b4c83466d065b7458db6).

[Apache TVM Discuss] [Questions] FoldConstant doesn't fold two consecutive add

Posted by JoeyChou via Apache TVM Discuss <no...@discuss.tvm.ai>.

Hi @electriclilies thanks for the suggestion. I tried your method. However, I still see two adds instead of one. I will try to put on a code snippet later.





---
[Visit Topic](https://discuss.tvm.apache.org/t/foldconstant-doesnt-fold-two-consecutive-add/8132/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/a94bfd42004bd5b4275acdf3b67ec83eee5273dd794c9e8af61dc03f4ada89ff).

[Apache TVM Discuss] [Questions] FoldConstant doesn't fold two consecutive add

Posted by Lily Orth-Smith via Apache TVM Discuss <no...@discuss.tvm.ai>.

If I understand your question, you want the two adds to fuse into one add. 
To do this, I would try using the FuseOps pass after FoldConstant and FoldScaleAxis.
(Without seeing more of the program, I can't tell what your two adds are adding -- can you post an excerpt of the relay program here as well?)





---
[Visit Topic](https://discuss.tvm.apache.org/t/foldconstant-doesnt-fold-two-consecutive-add/8132/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/ff5d54a0b1d70e7c730be7dea3351f0f8195cbdaa012aaf54a9a8990f0496094).