code: def test_diamond_graph_fanouts():
      """
      This tests that the data dependencies present in a diamond-shaped
      graph are correctly resolved by the merging pass.
  
      O = supported by target
      X = not supported by target
  
         O         O
        / \\      /               \\
       O   X --> O    +       +    X
       \\ /             \\ /
         O                O
  
      Note that we can't just merge the three supported operators together,
      otherwise both subgraphs would depend on the other.
      """
  
      def diamond_graph_fanouts():
          data = relay.var("data", shape=(10, 10))
          cb_1 = compiler_begin(data, "test")
          O_1 = relay.abs(cb_1)
          ce_1 = compiler_end(O_1, "test")
          ce_2 = compiler_end(O_1, "test")
          cb_2 = compiler_begin(ce_1, "test")
          cb_3 = compiler_begin(ce_2, "default")
          O_2 = relay.nn.relu(cb_2)
          ce_3 = compiler_end(O_2, "test")
  
          X = relay.tanh(cb_3)
          ce_4 = compiler_end(X, "default")
  
          cb_4 = compiler_begin(ce_3, "test")
          cb_5 = compiler_begin(ce_4, "test")
          O_3 = relay.add(cb_4, cb_5)
          ce_5 = compiler_end(O_3, "test")
  
          diamond = relay.Function([data], ce_5)
          return diamond
  
      def expected():
          data = relay.var("data", shape=(10, 10))
          cb_1 = compiler_begin(data, "test")
          O_1 = relay.abs(cb_1)
          ce_2 = compiler_end(O_1, "test")
          O_2 = relay.nn.relu(O_1)
          ce_3 = compiler_end(O_2, "test")
  
          cb_3 = compiler_begin(ce_2, "default")
          X = relay.tanh(cb_3)
          ce_4 = compiler_end(X, "default")
  
          cb_4 = compiler_begin(ce_3, "test")
          cb_5 = compiler_begin(ce_4, "test")
          O_3 = relay.add(cb_4, cb_5)
          ce_5 = compiler_end(O_3, "test")
  
          func = relay.Function([data], ce_5)
          return func
  
      result = run_opt_pass(
          diamond_graph_fanouts(),
          relay.transform.MergeCompilerRegions(),
      )
      golden = run_opt_pass(expected(), relay.transform.InferType())
      assert tvm.ir.structural_equal(result, golden)
  
file_path: tvm/tests/python/relay/test_pass_merge_compiler_regions.py
imports: import tvm
  from tvm import relay
  import tvm.relay.transform
  from tvm.relay.op.annotation import compiler_begin, compiler_end
  from tvm.relay.testing import run_opt_pass
label_desc: Use image node_id 1 for calling a global function with example usage: test_diamond_graph_fanouts() and returns: diamond, func