code: def test_linear_quant_batchedmatmul_8bit(self):
      np.random.seed(1988)
      W = np.random.rand(32, 32) * 2.0 - 1
      bias = np.random.rand(32)
  
      input_features = [("data", datatypes.Array(2, 32))]
      output_features = [("out", None)]
      builder = NeuralNetworkBuilder(
          input_features,
          output_features,
          disable_rank5_shape_mapping=True,
      )
      builder.add_batched_mat_mul(
          name="batched_matmul",
          input_names=["data"],
          output_name="out",
          weight_matrix_rows=32,
          weight_matrix_columns=32,
          W=W,
          bias=bias,
      )
      mlmodel = MLModel(
          builder.spec, compute_units=ComputeUnit.CPU_ONLY
      )
      q_mlmodel = quantize_weights(mlmodel, 8)
      q_spec = q_mlmodel.get_spec()
      q_layer = q_spec.neuralNetwork.layers[0].batchedMatmul
  
      self.assertTrue(len(q_layer.weights.floatValue) == 0)
      self.assertTrue(len(q_layer.weights.rawValue) > 0)
  
      data = np.random.rand(2, 32)
      data_dict = {"data": data}
      out = q_mlmodel.predict(data_dict)["out"]
      expected_out = np.matmul(data, W) + bias
      self.assertTrue(out.shape == expected_out.shape)
      self.assertTrue(
          np.allclose(out.flatten(), expected_out.flatten(), atol=0.1)
      )
  
imports: import numpy
  import pytest
  import unittest
  import coremltools
  from coremltools import ComputeUnit
  from coremltools.converters.mil.mil.types.type_mapping import np_val_to_py_type
  from coremltools.models import MLModel, datatypes
  from coremltools.models.neural_network import NeuralNetworkBuilder
  from coremltools.models.neural_network.quantization_utils import _convert_array_to_nbit_quantized_bytes, quantize_weights
  from coremltools.models.utils import _is_macos, _macos_version
label_desc: Use image node_id 2 for calling the BasicNumericCorrectnessTest_1015NewLayers obj's underlying member method code with example usage: obj.test_linear_quant_batchedmatmul_8bit() without return types