code: def test_embeddingND_quantize(compute_units):
      input_features = [("data", datatypes.Array(10, 1))]
      output_features = [("output", None)]
      builder = neural_network.NeuralNetworkBuilder(
          input_features,
          output_features,
          disable_rank5_shape_mapping=True,
      )
  
      builder.add_embedding_nd(
          name="embedding_nd",
          input_name="data",
          output_name="output",
          vocab_size=300,
          embedding_size=20,
          W=np.random.rand(20, 300),
      )
  
      spec = builder.spec
      model_fp32 = coremltools.models.MLModel(
          spec, compute_units=compute_units
      )
      assert (
          len(
              spec.neuralNetwork.layers[
                  0
              ].embeddingND.weights.floatValue
          )
          == 6000
      )
  
      # quantize to FP16
      model_fp16 = quantization_utils.quantize_weights(
          model_fp32, nbits=16
      )
      assert model_fp16.compute_unit == compute_units
      spec_fp16 = model_fp16.get_spec()
      assert (
          len(
              spec_fp16.neuralNetwork.layers[
                  0
              ].embeddingND.weights.floatValue
          )
          == 0
      )
      assert (
          len(
              spec_fp16.neuralNetwork.layers[
                  0
              ].embeddingND.weights.float16Value
          )
          == 2 * 6000
      )
  
      # quantize to uint8
      model_uint8 = quantization_utils.quantize_weights(
          model_fp32, nbits=8
      )
      assert model_uint8.compute_unit == compute_units
      spec_uint8 = model_uint8.get_spec()
      assert (
          len(
              spec_uint8.neuralNetwork.layers[
                  0
              ].embeddingND.weights.floatValue
          )
          == 0
      )
      assert (
          len(
              spec_uint8.neuralNetwork.layers[
                  0
              ].embeddingND.weights.float16Value
          )
          == 0
      )
      assert (
          len(
              spec_uint8.neuralNetwork.layers[
                  0
              ].embeddingND.weights.rawValue
          )
          == 6000
      )
  
      # quantize to uint5
      model_uint5 = quantization_utils.quantize_weights(
          model_fp32, nbits=5
      )
      assert model_uint5.compute_unit == compute_units
      spec_uint5 = model_uint5.get_spec()
      assert (
          len(
              spec_uint5.neuralNetwork.layers[
                  0
              ].embeddingND.weights.floatValue
          )
          == 0
      )
      assert (
          len(
              spec_uint5.neuralNetwork.layers[
                  0
              ].embeddingND.weights.float16Value
          )
          == 0
      )
      assert (
          len(
              spec_uint5.neuralNetwork.layers[
                  0
              ].embeddingND.weights.rawValue
          )
          == 3750
      )
  
imports: import itertools
  import unittest
  import numpy
  import pytest
  import coremltools
  import coremltools.models.datatypes
  from coremltools import ComputeUnit
  from coremltools.models import _QUANTIZATION_MODE_LINEAR_QUANTIZATION, neural_network
  from coremltools.models.neural_network import quantization_utils
  from coremltools.models.neural_network.quantization_utils import MatrixMultiplyLayerSelector, _quantize_spec_weights, activate_int8_int8_matrix_multiplications
label_desc: Use image node_id 1 for calling the TestQuantizeWeightsAPI obj's underlying member method code with example usage: obj.test_embeddingND_quantize(compute_units) without return types