code: def test_conv_example():
      batch, C_in, C_out, H, W = 2, 2, 3, 7, 10
      kH, kW = 3, 5
      img_shape, seq_shape = (batch, C_in, H, W), (batch, C_in, H)
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=img_shape),
              mb.TensorSpec(shape=seq_shape),
          ]
      )
      def prog(img, seq):
          ## 2D convolution
          # Weight
          W_2d = np.random.rand(C_out, C_in, kH, kW).astype(np.float32)
          W_2d = mb.const(val=W_2d, name="const_W")
  
          # Test 1: provide only required arguments.
          conv1 = mb.conv(x=img, weight=W_2d, pad_type="valid")
          logger.info("conv1 shape: {}".format(conv1.shape))
  
          # Test 2: stride > 1
          conv2 = mb.conv(
              x=img, weight=W_2d, pad_type="valid", strides=[2, 3]
          )
          logger.info("conv2 shape: {}".format(conv2.shape))
  
          # Test 3: same padding
          conv3 = mb.conv(
              x=img, weight=W_2d, pad_type="same", strides=[2, 3]
          )
          logger.info("conv3 shape: {}".format(conv3.shape))
  
          # Test max_pool
          pool1 = mb.max_pool(
              x=img,
              kernel_sizes=[kH, kW],
              pad_type="valid",
              strides=[2, 3],
          )
          logger.info("pool1 shape: {}".format(pool1.shape))
  
          # Test max_pool
          pool2 = mb.max_pool(
              x=img,
              kernel_sizes=[kH, kW],
              pad_type="same",
              strides=[2, 3],
          )
          logger.info("pool2 shape: {}".format(pool2.shape))
  
          ## 1D convolution
          W_1d = np.random.rand(C_out, C_in, kH).astype(np.float32)
          W_1d = mb.const(val=W_1d, name="const_W_1d")
          logger.info("W_1d val: {}".format(W_1d.val))
  
          # Test 4: provide only required arguments for 1D.
          conv4 = mb.conv(x=seq, weight=W_1d, pad_type="valid")
  
          logger.info("conv4 shape: {}".format(conv4.shape))
  
          return conv1, conv2, conv3, pool1, pool2, conv4
  
      # rdar://105988903 ([Infra] re-enable the test_conv_example unit test on M1 with compute_units=ALL)
      mlmodel = ct.convert(
          prog,
          source="milinternal",
          convert_to="neuralnetwork",
          compute_units=ct.ComputeUnit.CPU_ONLY,
      )
  
      feed_dict = {
          "img": np.random.rand(*img_shape).astype(np.float32),
          "seq": np.random.rand(*seq_shape).astype(np.float32),
      }
      assert mlmodel is not None
  
      if ct.utils._is_macos():
          prediction = mlmodel.predict(feed_dict)
          assert len(prediction) == 6
  
imports: import numpy
  import pytest
  import coremltools
  from coremltools import _logger
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Function, Program, types
  from coremltools.converters.mil.mil.passes.tests.test_passes import CONSTEXPR_FUNCS
label_desc: Use image node_id 2 for calling a global function with example usage: test_conv_example() and returns: conv1,  conv2,  conv3,  pool1,  pool2,  conv4