code: def test_rnn_quantization():
      data_low = -1
      data_high = 1
  
      def check_rnn_quantization(
          num_layers,
          bidirectional,
          seq_len,
          batch_size,
          input_dim,
          state_size,
      ):
          data_shape = (seq_len, batch_size, input_dim)
  
          rnn_fp32 = mx.gluon.rnn.LSTM(
              hidden_size=state_size,
              num_layers=num_layers,
              bidirectional=bidirectional,
          )
  
          data = mx.np.random.uniform(
              low=data_low, high=data_high, size=data_shape
          )
          states_shape = (
              num_layers * 2 if bidirectional else num_layers,
              batch_size,
              state_size,
          )
          states = [
              mx.np.zeros((states_shape)) for _ in range(batch_size)
          ]
  
          rnn_fp32.initialize()
          rnn_fp32.hybridize()
          ref_out = rnn_fp32(data, states)
  
          class RNNDataLoader(mx.gluon.data.DataLoader):
              def __init__(self, data, states):
                  super().__init__(mx.gluon.data.SimpleDataset([]), 1)
                  self.data = data
                  self.states = states
  
              def __iter__(self):
                  return self
  
              def __next__(self):
                  return [self.data, self.states]
  
              def __bool__(self):
                  return bool(self.dataiter.iter_next())
  
          calib_data = RNNDataLoader(data, states)
          quant_rnn = mx.contrib.quant.quantize_net(
              rnn_fp32,
              quantized_dtype="auto",
              quantize_mode="full",
              calib_data=calib_data,
              calib_mode="naive",
              num_calib_batches=1,
              device=mx.current_device(),
          )
          qout = quant_rnn(data, states)
  
          qsym, _ = quant_rnn.export(None)
          assert qsym.tojson().find("quantized_rnn") != -1
  
          ref_out = [ref_out[0], ref_out[1][0], ref_out[1][1]]
          for i in range(len(qout)):
              mse = onp.mean(
                  (ref_out[i].asnumpy() - qout[i].asnumpy()) ** 2
              )
              assert mse < 0.001
  
      check_rnn_quantization(1, False, 5, 2, 16, 16)
      check_rnn_quantization(1, True, 5, 2, 16, 16)
  
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 29 for calling a global function with example usage: test_rnn_quantization() and returns: self, list, bool