code: def test_alter_layout_strided_slice(target, dev):
      """Test rewriting strided_slice during alter_iop_layout"""
  
      def before():
          x = relay.var("x", shape=(1, 32, 28, 28))
          weight = relay.var("weight", shape=(32, 32, 3, 3))
          y = relay.nn.conv2d(
              x, weight, channels=32, kernel_size=(3, 3), padding=(1, 1)
          )
          y = relay.strided_slice(
              y, begin=[0, 16], end=[1, 33], strides=[1, 1]
          )
          y = relay.Function(analysis.free_vars(y), y)
          return y
  
      def alter_conv2d(attrs, inputs, tinfos, out_type):
          data, weight = inputs
          new_attrs = dict(attrs)
          new_attrs["data_layout"] = "NCHW4c"
          return relay.nn.conv2d(data, weight, **new_attrs)
  
      def expected():
          x = relay.var("x", shape=(1, 32, 28, 28))
          weight = relay.var("weight", shape=(32, 32, 3, 3))
          weight = relay.layout_transform(weight, "OIHW", "OIHW4i4o")
          x = relay.layout_transform(x, "NCHW", "NCHW4c")
          y = relay.op.nn.contrib_conv2d_nchwc(
              x,
              weight,
              channels=32,
              kernel_size=(3, 3),
              padding=(1, 1),
              data_layout="NCHW4c",
          )
  
          y = relay.strided_slice(
              y, begin=[0, 4], end=[1, 21], strides=[1, 1]
          )
  
          y = relay.layout_transform(y, "NCHW4c", "NCHW")
          y = relay.Function(analysis.free_vars(y), y)
          return y
  
      with TempOpAttr("nn.conv2d", "FTVMAlterOpLayout", alter_conv2d):
          a = before()
          b = run_opt_pass(expected(), transform.InferType())
  
      # Verify inference result
      mod_before = tvm.IRModule()
      mod_new = tvm.IRModule()
      mod_before["main"] = a
      mod_new["main"] = b
      mod_before = transform.InferType()(mod_before)
      mod_new = transform.InferType()(mod_new)
      with relay.build_config(opt_level=3):
          for kind in ["graph", "debug", "vm"]:
              np_data = np.random.uniform(size=(1, 32, 28, 28)).astype(
                  "float32"
              )
              np_weight = np.random.uniform(size=(32, 32, 3, 3)).astype(
                  "float32"
              )
              f_before = relay.create_executor(
                  kind, mod=mod_before, device=dev, target=target
              ).evaluate()
              result_before = f_before(np_data, np_weight)
              f_new = relay.create_executor(
                  kind, mod=mod_new, device=dev, target=target
              ).evaluate()
              result_new = f_new(np_data, np_weight)
              tvm.testing.assert_allclose(
                  result_before.numpy(),
                  result_new.numpy(),
                  rtol=1e-5,
                  atol=1e-5,
              )
  
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 16 for calling a global function with example usage: test_alter_layout_strided_slice(target, dev) and returns: y, relay, y