# \[solved\] Segfault on MergeCompositeFunctions

**URL:** <https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999>\
**Category:** unity\
**Created:** [May 25, 2023, 3:23pm UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999 "2023-05-25T15:23:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slai-nick](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@slai-nick](https://discuss.tvm.apache.org/u/slai-nick)\
**Post date:** [May 25, 2023, 3:23pm UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999/1 "2023-05-25T15:23:54Z")

</div>

Why am I getting a segfault on `MergeCompositeFunctions`?

Here is the code:

```python
import torch
import torch.nn as nn
import torch.fx as fx

import tvm
from tvm import relax
import tvm.relax.frontend.torch
from tvm.relax.dpl import is_op, wildcard

class NeuralNetwork(nn.Module):
    def __init__ (self):
        super(). __init__ ()
        self.flatten = nn.Flatten()
        self.linear_relu_stack = nn.Sequential(
            nn.Linear(28*28, 512),
            nn.ReLU(),
            nn.Linear(512, 512),
            nn.ReLU(),
            nn.Linear(512, 10),
        )

    def forward(self, x):
        x = self.flatten(x)
        logits = self.linear_relu_stack(x)
        return logits

network = NeuralNetwork()
input_shape = (1, 1, 28, 28)
input_dtype = "float"

traced_network = fx.symbolic_trace(network)
input_info = [(input_shape, input_dtype)]
mod = relax.frontend.torch.from_fx(traced_network, input_info)

patterns = [
        ("tensorrt.matmul", is_op("relax.matmul")(wildcard(), wildcard())),
]
mod1 = relax.transform.FuseOpsByPattern(patterns)(mod)
mod2 = relax.transform.MergeCompositeFunctions()(mod1)
# segfault

```

---

<div class="post-metadata">

**Author:** ![masahi](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/masahi/32/74_2.png) [@masahi](https://discuss.tvm.apache.org/u/masahi)\
**Post date:** [May 25, 2023, 7:37pm UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999/2 "2023-05-25T19:37:51Z")

</div>

Sorry about that, I’m taking a look

---

<div class="post-metadata">

**Author:** ![masahi](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/masahi/32/74_2.png) [@masahi](https://discuss.tvm.apache.org/u/masahi)\
**Post date:** [May 26, 2023, 12:37am UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999/3 "2023-05-26T00:37:48Z")

</div>

For now you can use this commit [fix · apache/tvm@7150f23 · GitHub](https://github.com/apache/tvm/commit/7150f239ba484985e24b4c7df0aaa31f2cd88833)

The problem was that the pass doesn’t handle `Constant` and `ShapeExpr` nodes properly. It was assuming that all inputs to `CallNode` are another `CallNode`.

---

<div class="post-metadata">

**Author:** ![masahi](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/masahi/32/74_2.png) [@masahi](https://discuss.tvm.apache.org/u/masahi)\
**Post date:** [May 26, 2023, 2:55am UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999/4 "2023-05-26T02:55:08Z")

</div>

> <https://github.com/apache/tvm/pull/14959>
>
> Fix for https://discuss.tvm.apache.org/t/segfault-on-mergecompositefunctions/149…99. We are not creating \`Group\` for non \`CallNodes\` that appear in the arguments of another \`CallNode\`. This results in a segfault when OpFuser tries to look up the group for all call node inputs.
> 
> @vinx13 @yelite

---

<div class="post-metadata">

**Author:** ![slai-nick](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@slai-nick](https://discuss.tvm.apache.org/u/slai-nick)\
**Post date:** [May 26, 2023, 6:47am UTC](https://discuss.tvm.apache.org/t/solved-segfault-on-mergecompositefunctions/14999/5 "2023-05-26T06:47:49Z")

</div>

Thank you!

20 characters
