code: def test_quantized_embedding():
      def check_quantized_embedding(data_shape, input_dim, output_dim):
          if is_test_for_gpu():
              print(
                  "skipped testing test_quantized_embedding for gpu since it is not supported yet"
              )
              return
  
          def maxabs(a, b):
              return mx.np.maximum(mx.np.abs(a), mx.np.abs(b))
  
          data = (
              mx.np.random.uniform(
                  low=0, high=input_dim, size=data_shape
              )
              .astype("int32")
              .astype("float32")
          )
          embedding_fp32 = mx.gluon.nn.Embedding(
              input_dim=input_dim, output_dim=output_dim
          )
          embedding_fp32.initialize()
          embedding_fp32(data)
          npx.waitall()
          fp32_params = embedding_fp32.collect_params()
          weight_shape = fp32_params["weight"].shape
          int8_range = 127.0
          new_params = dict()
          weight = (
              mx.np.random.uniform(
                  low=-int8_range, high=int8_range, size=weight_shape
              )
              .astype("int32")
              .astype("float32")
          )
          new_params["weight"] = weight
          embedding_fp32.load_dict(
              new_params, cast_dtype=True, dtype_source="saved"
          )
  
          output = embedding_fp32(data)
  
          weight_min = mx.np.min(weight).astype("float32")
          weight_max = mx.np.max(weight).astype("float32")
          weight_range = maxabs(weight_min, weight_max)
  
          class QuantEmbedding(mx.gluon.nn.HybridBlock):
              def __init__(
                  self,
                  input_dim=input_dim,
                  output_dim=output_dim,
                  **kwargs,
              ):
                  super(QuantEmbedding, self).__init__(**kwargs)
                  self._kwargs = {
                      "input_dim": input_dim,
                      "output_dim": output_dim,
                  }
  
                  self.weight = mx.gluon.Parameter(
                      "weight",
                      dtype="float32",
                      shape=weight_shape,
                      allow_deferred_init=True,
                  )
                  self.min_weight = mx.gluon.Parameter(
                      "min_weight",
                      dtype="float32",
                      shape=(1),
                      allow_deferred_init=True,
                  )
                  self.max_weight = mx.gluon.Parameter(
                      "max_weight",
                      dtype="float32",
                      shape=(1),
                      allow_deferred_init=True,
                  )
  
              def forward(self, x):
                  device = x.device
                  weight = self.weight.data().to_device(device)
                  min_weight = self.min_weight.data().to_device(device)
                  max_weight = self.max_weight.data().to_device(device)
                  out = npx.quantized_embedding(
                      data=x,
                      weight=weight,
                      min_weight=min_weight,
                      max_weight=max_weight,
                      **self._kwargs,
                  )
                  return out
  
          embedding_int8 = QuantEmbedding(
              input_dim=input_dim, output_dim=output_dim
          )
          qargs = {
              "weight": weight.astype("int8"),
              "min_weight": mx.np.array([-weight_range]),
              "max_weight": mx.np.array([weight_range]),
          }
  
          embedding_int8.load_dict(
              qargs, cast_dtype=True, dtype_source="saved"
          )
  
          qoutput, min_range, max_range = embedding_int8(data)
  
          assert_almost_equal(output.asnumpy(), qoutput.asnumpy())
  
      check_quantized_embedding((1,), 1000, 256)
      check_quantized_embedding((1,), 1024, 512)
      check_quantized_embedding((32,), 1000, 256)
      check_quantized_embedding((32,), 1024, 512)
  
imports: import os
  import mxnet
  import numpy
  from mxnet import npx
  from mxnet.util import use_np
  from mxnet.gluon.model_zoo import vision
  from mxnet.test_utils import assert_almost_equal, assert_exception, rand_ndarray, rand_shape_nd, same, DummyIter
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.io import NDArrayIter
  import unittest
  import operator
label_desc: Use image node_id 17 for calling a global function with example usage: test_quantized_embedding() and returns: mx, out