code: def check_rnn_layer_forward(
      layer, inputs, states=None, run_only=False, device=mx.cpu()
  ):
      layer.initialize(device=device)
      inputs = inputs.to_device(device)
      inputs.attach_grad()
      if states is not None:
          if isinstance(states, (list, tuple)):
              states = [s.to_device(device) for s in states]
          else:
              states = states.to_device(device)
      with mx.autograd.record():
          if states is None:
              out = layer(inputs)
          else:
              out = layer(inputs, states)
          if states is not None:
              assert isinstance(out, (list, tuple)) and len(out) == 2
              out = out[0]
          else:
              assert isinstance(out, mx.np.ndarray)
          out.backward()
  
      np_out = out.asnumpy()
      np_dx = inputs.grad.asnumpy()
  
      layer.hybridize()
  
      with mx.autograd.record():
          if states is not None:
              out = layer(inputs, states)
              assert isinstance(out, (list, tuple)) and len(out) == 2
              out = out[0]
          else:
              out = layer(inputs)
              assert isinstance(out, mx.np.ndarray)
          out.backward()
  
      if states is not None:
          layer(inputs, states)  # test is_training = false
      else:
          layer(inputs)
  
      if not run_only:
          mx.test_utils.assert_almost_equal(
              np_out, out.asnumpy(), rtol=1e-3, atol=1e-5
          )
          mx.test_utils.assert_almost_equal(
              np_dx, inputs.grad.asnumpy(), 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 19 for calling a global function with example usage: check_rnn_layer_forward(layer, inputs, states, run_only, device) without return types