code: def test_linear_quant_embedding_7bit(self):
      embed_size = 2
      vocab_size = 3
      W = np.zeros((embed_size, vocab_size), dtype=np.uint8)
      W[:, 0] = [100, 127]
      W[:, 1] = [20, 40]
      W[:, 2] = [90, 1]
      quant_scale = np.reshape(np.array([10.0, 2.0]), (2, 1))
      quant_bias = np.reshape(np.array([-2.0, -10.0]), (2, 1))
      W_unquantized = np.broadcast_to(
          quant_scale, (2, 3)
      ) * W + np.broadcast_to(quant_bias, (2, 3))
      bias = np.reshape(np.array([1.0, 2.0]), (2, 1))
      W_unquantized = W_unquantized + np.broadcast_to(bias, (2, 3))
  
      input_features = [("data", datatypes.Array(4, 1, 1, 1))]
      output_features = [("out", None)]
      builder = NeuralNetworkBuilder(
          input_features,
          output_features,
          disable_rank5_shape_mapping=True,
      )
      builder.add_embedding(
          name="embed",
          W=_convert_array_to_nbit_quantized_bytes(
              W.flatten(), 7
          ).tobytes(),
          b=bias,
          input_dim=vocab_size,
          output_channels=embed_size,
          has_bias=True,
          input_name="data",
          output_name="out",
          is_quantized_weight=True,
          quantization_type="linear",
          nbits=7,
          quant_scale=np_val_to_py_type(quant_scale),
          quant_bias=np_val_to_py_type(quant_bias),
      )
  
      mlmodel = MLModel(
          builder.spec, compute_units=ComputeUnit.CPU_ONLY
      )
      data = np.reshape(np.array([2.0, 2.0, 1.0, 0.0]), (4, 1, 1, 1))
      data_dict = {"data": data}
      out = mlmodel.predict(data_dict)["out"]
      self.assertTrue(out.shape == (4, embed_size, 1, 1))
      expected_out = np.zeros((4, embed_size), dtype=np.float32)
      expected_out[0, :] = W_unquantized[:, 2].flatten()
      expected_out[1, :] = W_unquantized[:, 2].flatten()
      expected_out[2, :] = W_unquantized[:, 1].flatten()
      expected_out[3, :] = W_unquantized[:, 0].flatten()
      self.assertTrue(
          np.allclose(out.flatten(), expected_out.flatten())
      )
  
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 4 for calling the BasicNumericCorrectnessTest_1015NewLayers obj's underlying member method code with example usage: obj.test_linear_quant_embedding_7bit() without return types