code: def test_alter_layout_scalar_regression():
      """regression test where scalar fails"""
  
      def before():
          x = relay.var("x", shape=(1, 56, 56, 64))
          weight = relay.var("weight", shape=(3, 3, 64, 16))
          bias = relay.var("bias", shape=(1, 1, 1, 16))
          y = relay.nn.conv2d(
              x,
              weight,
              channels=16,
              kernel_size=(3, 3),
              padding=(1, 1),
              data_layout="NHWC",
              kernel_layout="HWIO",
          )
          y = relay.add(y, bias)
          mean = relay.mean(y, axis=3, exclude=True)
          var = relay.variance(y, axis=3, exclude=True)
          gamma = relay.var("gamma")
          beta = relay.var("beta")
          y = relay.nn.batch_norm(y, gamma, beta, mean, var, axis=3)
          y = y[0]
          return relay.Function(analysis.free_vars(y), y)
  
      def alter_conv2d(attrs, inputs, tinfos, out_type):
          data, weight = inputs
          new_attrs = dict(attrs)
          new_attrs["data_layout"] = "NCHW16c"
          return relay.nn.conv2d(data, weight, **new_attrs)
  
      def expected():
          x = relay.var("x", shape=(1, 56, 56, 64))
          weight = relay.var("weight", shape=(3, 3, 64, 16))
          bias = relay.var("bias", shape=(1, 1, 1, 16))
          x = relay.layout_transform(
              x, src_layout="NHWC", dst_layout="NCHW"
          )
          x = relay.layout_transform(
              x, src_layout="NCHW", dst_layout="NCHW16c"
          )
          weight = relay.layout_transform(
              weight, src_layout="HWIO", dst_layout="OIHW"
          )
          y = relay.nn.conv2d(
              x,
              weight,
              channels=16,
              kernel_size=(3, 3),
              padding=(1, 1),
              data_layout="NCHW16c",
          )
          bias = relay.layout_transform(
              bias, src_layout="NHWC", dst_layout="NCHW"
          )
          bias = relay.layout_transform(
              bias, src_layout="NCHW", dst_layout="NCHW16c"
          )
          add = relay.add(y, bias)
          mean = relay.mean(add, axis=[1, 4], exclude=True)
          var = relay.variance(add, axis=[1, 4], exclude=True)
          denom = relay.const(1.0) / relay.sqrt(
              var + relay.const(1e-05)
          )
          gamma = relay.var("gamma", shape=(16,))
          denom_c16c = denom * relay.layout_transform(
              gamma, src_layout="C", dst_layout="C16c"
          )
          denom = relay.layout_transform(
              denom_c16c, src_layout="C16c", dst_layout="C"
          )
          denom_expand1 = relay.expand_dims(
              denom, axis=1, num_newaxis=2
          )
          denom_expand2 = relay.expand_dims(denom_expand1, axis=0)
          denom_nchwc16 = relay.layout_transform(
              denom_expand2, src_layout="NCHW", dst_layout="NCHW16c"
          )
          out = add * denom_nchwc16
          beta = relay.var("beta", shape=(16,))
          numerator_c16c = (
              -mean
          ) * denom_c16c + relay.layout_transform(
              beta, src_layout="C", dst_layout="C16c"
          )
          numerator = relay.layout_transform(
              numerator_c16c, src_layout="C16c", dst_layout="C"
          )
          numerator_expand1 = relay.expand_dims(
              numerator, axis=1, num_newaxis=2
          )
          numerator_expand2 = relay.expand_dims(
              numerator_expand1, axis=0
          )
          numerator_nchwc16 = relay.layout_transform(
              numerator_expand2, src_layout="NCHW", dst_layout="NCHW16c"
          )
          out = out + numerator_nchwc16
          out = relay.layout_transform(
              out, src_layout="NCHW16c", dst_layout="NCHW"
          )
          y = relay.layout_transform(
              out, src_layout="NCHW", dst_layout="NHWC"
          )
          y = relay.Function(analysis.free_vars(y), y)
          return y
  
      with TempOpAttr("nn.conv2d", "FTVMAlterOpLayout", alter_conv2d):
          a = before()
          desired_layouts = {
              "nn.conv2d": ["NCHW", "default"],
              "nn.batch_norm": ["NHWC", "default"],
          }
          a = run_opt_pass(
              a,
              [
                  transform.InferType(),
                  relay.transform.ConvertLayout(desired_layouts),
                  transform.SimplifyInference(),
                  transform.CanonicalizeOps(),
                  transform.AlterOpLayout(),
              ],
          )
          b = run_opt_pass(expected(), transform.InferType())
  
      assert tvm.ir.structural_equal(a, b), "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 12 for calling a global function with example usage: test_alter_layout_scalar_regression() and returns: relay, relay, y