code: def test_quantize_model():
      def check_params(params, qparams, qsym=None):
          if qsym is None:
              assert len(params) == len(qparams)
              for k, v in params.items():
                  assert k in qparams
                  assert same(v.asnumpy(), qparams[k].asnumpy())
          else:
              qparams_ground_truth = mx.contrib.quant._quantize_params(
                  qsym, params, min_max_dict={}
              )
              assert len(qparams) == len(qparams_ground_truth)
              for k, v in qparams_ground_truth.items():
                  assert k in qparams
                  assert same(v.asnumpy(), qparams[k].asnumpy())
  
      def check_qsym_calibrated(qsym):
          attrs = qsym.attr_dict()
          for k, v in attrs.items():
              if k.find("requantize_") != -1:
                  assert "min_calib_range" in v
                  assert "max_calib_range" in v
  
      def check_qsym_qdtype(qsym, qdtype):
          attrs = qsym.attr_dict()
          for k, v in attrs.items():
              if k.find("_quantize") != -1:
                  assert "out_type" in v
                  assert v["out_type"] == qdtype
  
      def skip_not_supported():
          if is_test_for_native_cpu():
              print(
                  "skipped testing quantize_model for native cpu since it is not supported yet"
              )
              return True
          elif qdtype == "int8" and is_test_for_dnnl():
              print(
                  "skipped testing quantize_model for oneDNN cpu int8 since it is not supported yet"
              )
              return True
          elif qdtype == "uint8" and is_test_for_gpu():
              print(
                  "skipped testing quantize_model for gpu uint8 since it is not supported yet"
              )
              return True
          return False
  
      def check_quantize_model(qdtype):
          if is_test_for_native_cpu():
              print(
                  "skipped testing quantize_model for native cpu since it is not supported yet"
              )
              return
          elif qdtype == "int8" and is_test_for_dnnl():
              print(
                  "skipped testing quantize_model for oneDNN cpu int8 since it is not supported yet"
              )
              return
          elif qdtype == "uint8" and is_test_for_gpu():
              print(
                  "skipped testing quantize_model for gpu uint8 since it is not supported yet"
              )
              return
  
          standard_net = FP32Net()
          standard_net.initialize()
          batch_size = 4
          data_shape = (batch_size, 4, 10, 10)
  
          length = batch_size  # specify num of outputs from split op
          multi_out_net = FP32MultipleOutputs(length)
          multi_out_net.initialize()
          multi_out_data_shape = (length, 4, 4, 10, 10)
  
          for net, dshape in zip(
              (standard_net, multi_out_net),
              (data_shape, multi_out_data_shape),
          ):
              data = mx.np.random.uniform(low=0, high=1, size=dshape)
              net.hybridize()
              net(data)
              sym, _ = net.export(None)
              arg_params, aux_params = collect_block_args_aux(net, sym)
  
              (
                  qsym,
                  qarg_params,
                  qaux_params,
              ) = mx.contrib.quant.quantize_model(
                  sym=sym,
                  arg_params=arg_params,
                  aux_params=aux_params,
                  device=mx.current_device(),
                  quantized_dtype=qdtype,
                  calib_mode="none",
                  quantize_mode="full",
              )
              check_params(arg_params, qarg_params, qsym)
              check_params(aux_params, qaux_params)
  
              calib_data = mx.np.random.uniform(size=dshape)
              calib_data = mx.gluon.data.DataLoader(
                  calib_data, batch_size=batch_size
              )
              (
                  qsym,
                  qarg_params,
                  qaux_params,
              ) = mx.contrib.quant.quantize_model(
                  sym=sym,
                  arg_params=arg_params,
                  aux_params=aux_params,
                  device=mx.current_device(),
                  quantized_dtype=qdtype,
                  calib_mode="naive",
                  calib_data=calib_data,
                  num_calib_batches=1,
                  quantize_mode="full",
              )
              check_params(arg_params, qarg_params, qsym)
              check_params(aux_params, qaux_params)
              check_qsym_calibrated(qsym)
              check_qsym_qdtype(qsym, qdtype)
  
      def check_quantize_model_multiple_inputs(qdtype):
          if skip_not_supported():
              return
  
          net = FP32MultipleInputs()
          net.initialize()
          net.hybridize()
          dshape = (64, 4, 10, 10)
          data = [
              mx.np.random.uniform(low=0, high=1, size=dshape),
              mx.np.random.uniform(low=0, high=1, size=dshape),
          ]
          net(*data)
          sym, _ = net.export(None)
          arg_params, aux_params = collect_block_args_aux(net, sym)
  
          (
              qsym,
              qarg_params,
              qaux_params,
          ) = mx.contrib.quant.quantize_model(
              sym=sym,
              arg_params=arg_params,
              aux_params=aux_params,
              device=mx.current_device(),
              quantized_dtype=qdtype,
              calib_mode="none",
              quantize_mode="full",
          )
          check_params(arg_params, qarg_params, qsym)
          check_params(aux_params, qaux_params)
  
          calib_data = [
              mx.np.random.uniform(size=dshape),
              mx.np.random.uniform(size=dshape),
          ]
          calib_data = mx.gluon.data.DataLoader(
              mx.gluon.data.ArrayDataset(*calib_data), batch_size=4
          )
          (
              qsym,
              qarg_params,
              qaux_params,
          ) = mx.contrib.quant.quantize_model(
              sym=sym,
              arg_params=arg_params,
              aux_params=aux_params,
              device=mx.current_device(),
              quantized_dtype=qdtype,
              calib_mode="naive",
              calib_data=calib_data,
              data_names=["data0", "data1"],
              num_calib_batches=1,
              quantize_mode="full",
          )
          check_params(arg_params, qarg_params, qsym)
          check_params(aux_params, qaux_params)
          check_qsym_calibrated(qsym)
          check_qsym_qdtype(qsym, qdtype)
  
      for qdtype in ["int8", "uint8"]:
          check_quantize_model(qdtype)
          check_quantize_model_multiple_inputs(qdtype)
  
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 23 for calling a global function with example usage: test_quantize_model() and returns: False, True, True, True