code: def test_lut_quant_embedding_nd_2bit(self):
      embed_size = 2
      vocab_size = 3
      W = np.zeros((embed_size, vocab_size), dtype=np.uint8)
      W[:, 0] = [1, 0]
      W[:, 1] = [0, 1]
      W[:, 2] = [3, 2]
      bias = np.array([1.0, 2.0])
      quant_lut = np.array([34.0, 12.0, -6.0, 6.0])
  
      input_features = [("data", datatypes.Array(4, 1))]
      output_features = [("out", None)]
      builder = NeuralNetworkBuilder(
          input_features,
          output_features,
          disable_rank5_shape_mapping=True,
      )
      builder.add_embedding_nd(
          name="embedding_nd",
          input_name="data",
          output_name="out",
          vocab_size=vocab_size,
          embedding_size=embed_size,
          W=_convert_array_to_nbit_quantized_bytes(
              W.flatten(), 2
          ).tobytes(),
          b=bias,
          is_quantized_weight=True,
          quantization_type="lut",
          nbits=2,
          quant_lut=quant_lut,
      )
  
      mlmodel = MLModel(
          builder.spec, compute_units=ComputeUnit.CPU_ONLY
      )
      data = np.reshape(np.array([2.0, 2.0, 1.0, 0.0]), (4, 1))
      data_dict = {"data": data}
      out = mlmodel.predict(data_dict)["out"]
      expected_out = np.zeros((4, embed_size), dtype=np.float32)
      expected_out[0, :] = [
          quant_lut[W[0, 2]],
          quant_lut[W[1, 2]],
      ] + bias
      expected_out[1, :] = [
          quant_lut[W[0, 2]],
          quant_lut[W[1, 2]],
      ] + bias
      expected_out[2, :] = [
          quant_lut[W[0, 1]],
          quant_lut[W[1, 1]],
      ] + bias
      expected_out[3, :] = [
          quant_lut[W[0, 0]],
          quant_lut[W[1, 0]],
      ] + bias
      self.assertTrue(out.shape == expected_out.shape)
      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 3 for calling the BasicNumericCorrectnessTest_1015NewLayers obj's underlying member method code with example usage: obj.test_lut_quant_embedding_nd_2bit() without return types