How to add fuse op like conv+leaky, or conv+clip in the MergeComposite pass?

Hi,

In the MergeComposite pass, it only match the pattern pre-defined in the BYOC’s backend, so that it could be extracted out for later fusion. But for the op like leaky/clip, it has parameter, which is not like the sigmoid or relu’s case, which we know its existence could generate the right code. So how to extract out leaky/clip’s parameter in the mergecomposite pass, so that later backend could generate right code?

Thx

1 Like

That’s probably not possible with MergeComposite. You can use pattern match & rewrite directly instead, see for example https://github.com/apache/tvm/blob/a49273e05092480bde8593c6a137bb251b5dee6c/python/tvm/relay/op/contrib/dnnl.py#L776

I take a deeper investigation, and find FunctionNode in the Call’s op member already contains the clip’s attribue like a_min and a_max. And further reassign the function node as Callnode, the a_min/max could be extracted by call->attrs.as < ClipAttrs >();

So seems to me it is doable?

Maybe you can create a new op which contain conv’s attr and clip’s attr. then use pattern to generate the new op.

I think no need to create new one, MergeComposite already could do it. with the ClipAttrs, I already create the composite op.

2 Likes