code: def test_alter_op_with_global_var():
      """Test directly replacing an operator with a new one"""
  
      def before():
          x = relay.var("x", shape=(1, 64, 56, 56))
          weight = relay.var("weight", shape=(64, 64, 3, 3))
          y = relay.nn.conv2d(
              x, weight, channels=64, kernel_size=(3, 3), padding=(1, 1)
          )
          y = relay.nn.relu(y)
          mod = tvm.IRModule()
          foo = relay.GlobalVar("foo")
          mod[foo] = relay.Function([x, weight], y)
          mod = transform.InferType()(mod)
          mod["main"] = relay.Function([x, weight], foo(x, weight))
          mod = transform.InferType()(mod)
          return mod
  
      def alter_conv2d(attrs, inputs, tinfos, out_type):
          data, weight = inputs
          weight = relay.multiply(weight, relay.const(2.0, "float32"))
          return relay.nn.conv2d(data, weight, **attrs)
  
      def expected():
          x = relay.var("x", shape=(1, 64, 56, 56))
          weight = relay.var("weight", shape=(64, 64, 3, 3))
          y = relay.nn.conv2d(
              x,
              relay.multiply(weight, relay.const(2.0, "float32")),
              channels=64,
              kernel_size=(3, 3),
              padding=(1, 1),
          )
          y = relay.nn.relu(y)
          mod = tvm.IRModule()
          foo = relay.GlobalVar("foo")
          mod[foo] = relay.Function([x, weight], y)
          mod = transform.InferType()(mod)
          mod["main"] = relay.Function([x, weight], foo(x, weight))
          return mod
  
      with TempOpAttr("nn.conv2d", "FTVMAlterOpLayout", alter_conv2d):
          a = before()
          a = transform.AlterOpLayout()(a)
          b = transform.InferType()(expected())
  
      assert tvm.ir.structural_equal(
          a, b, map_free_vars=True
      ), "Actual = \n" + str(a)
  
imports: import pytest
  import tvm
  from tvm import relay, topi
  from tvm.relay import transform, analysis
  from tvm.relay.testing.temp_op_attr import TempOpAttr
  from tvm.relay.testing import run_infer_type
  import numpy
  import tvm.testing
  from tvm.relay import testing
label_desc: Use image node_id 25 for calling a global function with example usage: test_alter_op_with_global_var() and returns: mod, relay, mod