code: def test_quantized_rnn():
      def check_quantized_rnn(
          num_layers,
          bidirectional,
          seq_len,
          batch_size,
          input_dim,
          state_size,
      ):
          ndir = 2 if bidirectional else 1
          size = ndir * state_size * 4
          first_lyr_param_size = (input_dim + state_size + 2) * size
          other_lyr_param_size = (
              state_size * ndir + state_size + 2
          ) * size
          full_param_size = (
              first_lyr_param_size
              + (num_layers - 1) * other_lyr_param_size
          )
  
          data = mx.np.random.uniform(
              -1, 1, (seq_len, batch_size, input_dim)
          )
          state = mx.np.random.uniform(
              -1, 1, (num_layers * ndir, batch_size, state_size)
          )
          state_cell = mx.np.random.uniform(
              0, 1, (num_layers * ndir, batch_size, state_size)
          )
          params = mx.np.random.normal(0, 1, (full_param_size,))
  
          out = npx.rnn(
              data=data,
              parameters=params,
              mode="lstm",
              state=state,
              state_size=state_size,
              state_cell=state_cell,
              num_layers=num_layers,
              bidirectional=bidirectional,
          )
  
          data_min = mx.np.min(data)
          data_max = mx.np.max(data)
          data_scale = mx.np.array(
              128.0 / (data_max - data_min)
          ).reshape((1,))
          data_shift = mx.np.array(
              128.0 - data_max * data_scale
          ).reshape((1,))
  
          qdata = (data * data_scale + data_shift + 0.5).astype("uint8")
          qout = npx.contrib_quantized_rnn(
              data=qdata,
              parameters=params,
              mode="lstm",
              state=state,
              state_size=state_size,
              state_cell=state_cell,
              num_layers=num_layers,
              bidirectional=bidirectional,
              data_scale=data_scale,
              data_shift=data_shift,
          )
  
          mse = onp.mean((out.asnumpy() - qout.asnumpy()) ** 2)
          assert mse < 0.001
  
      check_quantized_rnn(1, False, 5, 2, 16, 16)
      check_quantized_rnn(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 30 for calling a global function with example usage: test_quantized_rnn() without return types