# Incomplete type in BroadcastToRel while doing MergeComposite

**URL:** <https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-while-doing-mergecomposite/10439>\
**Category:** Troubleshooting\
**Created:** [July 9, 2021, 6:29pm UTC](https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-while-doing-mergecomposite/10439 "2021-07-09T18:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeyChou](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/joeychou/32/2849_2.png) [@JoeyChou](https://discuss.tvm.apache.org/u/JoeyChou)\
**Post date:** [July 9, 2021, 6:29pm UTC](https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-while-doing-mergecomposite/10439/1 "2021-07-09T18:29:45Z")

</div>

Hi, community,

I am seeing segfault while running this [code snippet](https://gist.github.com/JoeyTPChou/ba122d7dfe920a672059cb65453bc90e)

In this code snippet, I am running a small model as below:

```auto
def @main(%data: Tensor[(1, 3, 16, 16), float32]) -> Tensor[(1, 6, 8, 8), float32] {
  %0 = nn.conv2d(%data, meta[relay.Constant][0] /* ty=Tensor[(6, 3, 4, 4), float32] */, strides=[2, 2], padding=[1, 1, 1, 1], channels=6, kernel_size=[4, 4]) /* ty=Tensor[(1, 6, 8, 8), float32] */;
  %1 = add(%0, meta[relay.Constant][1] /* ty=Tensor[(6, 1, 1), float32] */) /* ty=Tensor[(1, 6, 8, 8), float32] */;
  %2 = nn.global_avg_pool2d(%1) /* ty=Tensor[(1, 6, 1, 1), float32] */;
  %3 = broadcast_to(%2, meta[relay.attrs.InitOpAttrs][0]) /* ty=Tensor[(1, 6, 8, 8), float32] */;
  multiply(%1, %3) /* ty=Tensor[(1, 6, 8, 8), float32] */
}

```

When I try to apply a MergeComposite pass to merge `weight` + `nn.conv2d` + `bias` + `add`. I got a segfault due to an incomplete type in `src/relay/op/tensor/transform.cc::BroadCastToRel`. The `types[0]` in below’s code has incomplete type.

> <https://github.com/apache/tvm/blob/main/src/relay/op/tensor/transform.cc#L2356>

Has anyone encountered a similar issue? Is there any suggestion about how to fix it?

Thanks, Joey

---

<div class="post-metadata">

**Author:** ![comaniac](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/comaniac/32/899_2.png) [@comaniac](https://discuss.tvm.apache.org/u/comaniac)\
**Post date:** [July 9, 2021, 6:55pm UTC](https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-while-doing-mergecomposite/10439/2 "2021-07-09T18:55:48Z")

</div>

Looks like the type function of broadcast doesn’t cover the case of IncompleteType. I fixed it in this PR

> <https://github.com/apache/tvm/pull/8438>
>
> Reported by https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-w…hile-doing-mergecomposite/10439, the broadcast type function cannot deal with IncompleteType. This PR fixes this issue using the similar approach used by other type functions.
> 
> cc @electriclilies @mbrookhart

The output with this PR:

```auto
def @main(%data: Tensor[(1, 3, 16, 16), float32]) -> Tensor[(1, 6, 8, 8), float32] {
  %1 = fn (%FunctionVar_0_0: Tensor[(1, 3, 16, 16), float32], PartitionedFromPattern="nn.conv2d_add_", Composite="conv2d_add") -> Tensor[(1, 6, 8, 8), float32] {
    %0 = nn.conv2d(%FunctionVar_0_0, meta[relay.Constant][0] /* ty=Tensor[(6, 3, 4, 4), float32] */, strides=[2, 2], padding=[1, 1, 1, 1], channels=6, kernel_size=[4, 4]) /* ty=Tensor[(1, 6, 8, 8), float32] */;
    add(%0, meta[relay.Constant][1] /* ty=Tensor[(6, 1, 1), float32] */) /* ty=Tensor[(1, 6, 8, 8), float32] */
  };
  %2 = %1(%data) /* ty=Tensor[(1, 6, 8, 8), float32] */;
  %3 = nn.global_avg_pool2d(%2) /* ty=Tensor[(1, 6, 1, 1), float32] */;
  %4 = broadcast_to(%3, meta[relay.attrs.InitOpAttrs][0]) /* ty=Tensor[(1, 6, 8, 8), float32] */;
  multiply(%2, %4) /* ty=Tensor[(1, 6, 8, 8), float32] */
}

```

---

<div class="post-metadata">

**Author:** ![JoeyChou](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/joeychou/32/2849_2.png) [@JoeyChou](https://discuss.tvm.apache.org/u/JoeyChou)\
**Post date:** [July 9, 2021, 6:59pm UTC](https://discuss.tvm.apache.org/t/incomplete-type-in-broadcasttorel-while-doing-mergecomposite/10439/3 "2021-07-09T18:59:42Z")

</div>

Hi @comaniac,

Thanks a lot for your help! It works perfectly now!
