code: def test_multiple_patterns():
      r"""Test different patterns are merged correctly in the graph.
  
      We would expect the pattern `make_conv_bias_relu_pattern` to be merged
      into a single op `conv_bias_relu`. We would also expect `make_add_relu_pattern`
      to be merged into a single op `add_relu`.
  
          data   kernel
            \      /
             \    /
             conv2d                   data   kernel   bias
               |                         \      |      /
               |   bias                 conv2d_bias_relu
               |   /                            |
            bias_add        ====>               |    a
               |                                |   /
             relu  a                        add_relu
               \  /                             |
               add                              |  b
                |                               | /
              relu  b                          mul
                |  /
               mul
      """
      pattern_table = [
          ("conv2d_bias_relu", make_conv_bias_relu_pattern()),
          ("add_relu", make_add_relu_pattern()),
      ]
  
      def before():
          data = relay.var("data", shape=(1, 512, 28, 28))
          kernel = relay.var("kernel", shape=(256, 512, 1, 1))
          bias = relay.var("bias", shape=(256,))
          a = relay.var("a", shape=(1, 256, 28, 28))
          b = relay.var("b", shape=(1, 256, 28, 28))
  
          conv_node = relay.nn.conv2d(
              data,
              kernel,
              kernel_size=(1, 1),
              padding=(0, 0),
              strides=(1, 1),
          )
  
          bias_node = relay.nn.bias_add(conv_node, bias)
          relu_node = relay.nn.relu(bias_node)
          add_node = relay.add(relu_node, a)
          relu_node_2 = relay.nn.relu(add_node)
          r = relay.multiply(relu_node_2, b)
          return relay.Function([data, kernel, bias, a, b], r)
  
      def expected():
          data = relay.var("data", shape=(1, 512, 28, 28))
          kernel = relay.var("kernel", shape=(256, 512, 1, 1))
          bias = relay.var("bias", shape=(256,))
          a = relay.var("a", shape=(1, 256, 28, 28))
          b = relay.var("b", shape=(1, 256, 28, 28))
  
          # conv_bias_relu function
          in_1 = relay.var("in_1", shape=(1, 512, 28, 28))
          in_2 = relay.var("in_2", shape=(256, 512, 1, 1))
          in_3 = relay.var("in_3", shape=(256,))
  
          conv_node = relay.nn.conv2d(
              in_1,
              in_2,
              kernel_size=(1, 1),
              padding=(0, 0),
              strides=(1, 1),
          )
  
          bias_node = relay.nn.bias_add(conv_node, in_3)
          r = relay.nn.relu(bias_node)
          conv_bias_add_relu = relay.Function([in_1, in_2, in_3], r)
          conv_bias_add_relu = conv_bias_add_relu.with_attr(
              "Composite", "conv2d_bias_relu"
          )
          conv_bias_add_relu = conv_bias_add_relu.with_attr(
              "PartitionedFromPattern", "nn.conv2d_nn.bias_add_nn.relu_"
          )
  
          # add_relu function
          in_4 = relay.var("in_4", shape=(1, 256, 28, 28))
          in_5 = relay.var("in_5", shape=(1, 256, 28, 28))
          add_node = relay.add(in_4, in_5)
          r = relay.nn.relu(add_node)
          add_relu = relay.Function([in_4, in_5], r)
          add_relu = add_relu.with_attr("Composite", "add_relu")
          add_relu = add_relu.with_attr(
              "PartitionedFromPattern", "add_nn.relu_"
          )
  
          # merged function
          conv_bias_add_relu_1 = relay.Call(
              conv_bias_add_relu, [data, kernel, bias]
          )
          add_relu_1 = relay.Call(add_relu, [conv_bias_add_relu_1, a])
          r = relay.multiply(add_relu_1, b)
          return relay.Function([data, kernel, bias, a, b], r)
  
      check_result(pattern_table, before(), expected())
  
imports: import pytest
  import tvm
  from tvm import relay, tir
  from tvm.relay.dataflow_pattern import TuplePattern, TupleGetItemPattern, is_op, wildcard
  from tvm.relay.testing import run_opt_pass
label_desc: Use image node_id 11 for calling a global function with example usage: test_multiple_patterns() and returns: relay, relay