code: def test_if_free_vars():
      target = "test_if_free_vars"
  
      @tvm.ir.register_op_attr("equal", "target." + target)
      def equal(expr):  # pylint: disable=unused-variable
          return True
  
      @tvm.ir.register_op_attr("sigmoid", "target." + target)
      def sigmoid(expr):  # pylint: disable=unused-variable
          return True
  
      @tvm.ir.register_op_attr("erf", "target." + target)
      def erf(expr):  # pylint: disable=unused-variable
          return True
  
      """Test that If-else nodes compiles correctly when surrounded by free variables"""
  
      def before():
          data = relay.var("data", shape=(1, 32))
          eq1 = relay.var("e1", shape=[], dtype="float32")
          eq2 = relay.var("e2", shape=[], dtype="float32")
          eq = relay.equal(eq1, eq2)
  
          true_branch = relay.zeros(shape=(1, 32), dtype="float32")
          false_branch = relay.sigmoid(data)
          ife = relay.If(eq, true_branch, false_branch)
          out = relay.erf(ife)
  
          func = relay.Function([data, eq1, eq2], out)
          mod = tvm.IRModule.from_expr(func)
  
          return mod
  
      def after():
          data = relay.var("data", shape=(1, 32))
          eq1 = relay.var("e1", shape=[], dtype="float32")
          eq2 = relay.var("e2", shape=[], dtype="float32")
  
          cb_1 = relay.annotation.compiler_begin(eq1, target)
          cb_2 = relay.annotation.compiler_begin(eq2, target)
  
          equality_condition = relay.equal(cb_1, cb_2)
          ce_1 = relay.annotation.compiler_end(
              equality_condition, target
          )
  
          # if condition
          true_branch = relay.zeros(shape=(1, 32), dtype="float32")
  
          # else condition
          cb_3 = relay.annotation.compiler_begin(data, target)
          false_branch = relay.sigmoid(cb_3)
          ce_2 = relay.annotation.compiler_end(false_branch, target)
  
          if_condition = relay.If(ce_1, true_branch, ce_2)
          cb_4 = relay.annotation.compiler_begin(if_condition, target)
          erf_out = relay.erf(cb_4)
          ce_3 = relay.annotation.compiler_end(erf_out, target)
          func = relay.Function([data, eq1, eq2], ce_3)
          mod = tvm.IRModule.from_expr(func)
          return mod
  
      for annotate_non_call_ops in [True, False]:
          result = transform.AnnotateTarget(
              target, annotate_non_call_ops
          )(before())
          expected = transform.InferType()(after())
          assert tvm.ir.structural_equal(expected, result)
  
imports: import os
  import sys
  import numpy
  import pytest
  import tvm
  import tvm.relay.testing
  import tvm.relay.transform
  from tvm import relay
  from tvm import runtime
  from tvm.contrib import utils
label_desc: Use image node_id 15 for calling a global function with example usage: test_if_free_vars() and returns: True, True, True, mod, mod