code: def check_rnn_forward_backward(
      layer, merged_inputs, hybridize, merge_outputs, deterministic
  ):
      input_size = 5
      if merged_inputs:
          inputs = mx.np.ones((8, 3, 5))
          inputs.attach_grad()
      else:
          inputs = [mx.np.ones((8, 5)) for _ in range(3)]
          for x in inputs:
              x.attach_grad()
  
      if hybridize:
          layer.hybridize()
      layer.initialize()
  
      with mx.autograd.record():
          out = layer.unroll(3, inputs, merge_outputs=merge_outputs)[0]
          mx.autograd.backward(out)
  
      if hasattr(layer, "i2h_weight"):
          assert layer.i2h_weight.shape[1] == input_size, (
              layer.i2h_weight.shape[1],
              input_size,
          )
  
      if merge_outputs:
          np_out = out.asnumpy()
      else:
          np_out = _np.stack([x.asnumpy() for x in out], axis=1)
  
      if merged_inputs:
          np_dx = inputs.grad.asnumpy()
      else:
          np_dx = _np.stack([x.grad.asnumpy() for x in inputs], axis=1)
  
      with mx.autograd.record():
          out = layer.unroll(
              3, inputs, merge_outputs=not merge_outputs
          )[0]
          mx.autograd.backward(out)
  
      if merged_inputs:
          input_grads = inputs.grad.asnumpy()
      else:
          input_grads = _np.stack(
              [x.grad.asnumpy() for x in inputs], axis=1
          )
  
      if deterministic:
          if not merge_outputs:
              ref_np_out = out.asnumpy()
          else:
              ref_np_out = _np.stack([x.asnumpy() for x in out], axis=1)
          mx.test_utils.assert_almost_equal(
              np_out, ref_np_out, rtol=1e-3, atol=1e-5
          )
          mx.test_utils.assert_almost_equal(
              np_dx, input_grads, rtol=1e-3, atol=1e-5
          )
  
imports: import mxnet
  from mxnet import gluon, np
  import numpy
  import copy
  from functools import partial
  from numpy.testing import assert_allclose
  from mxnet.gluon.utils import split_rnn_params
  import pytest
  from mxnet.test_utils import almost_equal, assert_almost_equal, default_device
  from common import assert_raises_cudnn_not_satisfied, retry
label_desc: Use image node_id 15 for calling a global function with example usage: check_rnn_forward_backward(layer, merged_inputs, hybridize, merge_outputs, deterministic) without return types