code: def check_layer_bidirectional(size, in_size, proj_size):
      class RefBiLSTM(gluon.Block):
          def __init__(self, size, proj_size, **kwargs):
              super(RefBiLSTM, self).__init__(**kwargs)
              self._lstm_fwd = gluon.rnn.LSTM(
                  size, projection_size=proj_size, bidirectional=False
              )
              self._lstm_bwd = gluon.rnn.LSTM(
                  size, projection_size=proj_size, bidirectional=False
              )
  
          def forward(self, inpt):
              fwd = self._lstm_fwd(inpt)
              bwd_inpt = mx.np.flip(inpt, 0)
              bwd = self._lstm_bwd(bwd_inpt)
              bwd = mx.np.flip(bwd, 0)
              return mx.np.concatenate([fwd, bwd], axis=2)
  
      weights = {}
      for d in ["l", "r"]:
          weights["{}0_i2h_weight".format(d)] = mx.np.random.uniform(
              size=(size * 4, in_size)
          )
          if proj_size:
              weights[
                  "{}0_h2h_weight".format(d)
              ] = mx.np.random.uniform(size=(size * 4, proj_size))
              weights[
                  "{}0_h2r_weight".format(d)
              ] = mx.np.random.uniform(size=(proj_size, size))
          else:
              weights[
                  "{}0_h2h_weight".format(d)
              ] = mx.np.random.uniform(size=(size * 4, size))
          weights["{}0_i2h_bias".format(d)] = mx.np.random.uniform(
              size=(size * 4,)
          )
          weights["{}0_h2h_bias".format(d)] = mx.np.random.uniform(
              size=(size * 4,)
          )
  
      if proj_size:
          params = (
              weights["{}0_{}_{}".format(d, g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for d in ["l", "r"]
              for g in ["i2h", "h2h", "h2r"]
              if g != "h2r" or t != "bias"
          )
      else:
          params = (
              weights["{}0_{}_{}".format(d, g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for d in ["l", "r"]
              for g in ["i2h", "h2h"]
          )
  
      net_params_concat = mx.np.concatenate(params)
      if proj_size:
          params_left = (
              weights["l0_{}_{}".format(g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for g in ["i2h", "h2h", "h2r"]
              if g != "h2r" or t != "bias"
          )
      else:
          params_left = (
              weights["l0_{}_{}".format(g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for g in ["i2h", "h2h"]
          )
      if proj_size:
          params_right = (
              weights["r0_{}_{}".format(g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for g in ["i2h", "h2h", "h2r"]
              if g != "h2r" or t != "bias"
          )
      else:
          params_right = (
              weights["r0_{}_{}".format(g, t)].reshape(-1)
              for t in ["weight", "bias"]
              for g in ["i2h", "h2h"]
          )
      net_ref_left_params = mx.np.concatenate(params_left)
      net_ref_right_params = mx.np.concatenate(params_right)
      net = gluon.rnn.LSTM(
          size, projection_size=proj_size, bidirectional=True
      )
      ref_net = RefBiLSTM(size, proj_size)
      net.initialize()
      ref_net.initialize()
      net_params = net.collect_params()
      ref_net_params = ref_net.collect_params()
      net_params["rnn_param"].set_data(net_params_concat)
      ref_net_params["_lstm_fwd.rnn_param"].set_data(
          net_ref_left_params
      )
      ref_net_params["_lstm_bwd.rnn_param"].set_data(
          net_ref_right_params
      )
  
      data = mx.np.random.uniform(size=(11, 10, in_size))
      mx.test_utils.assert_allclose(net(data), ref_net(data), rtol=1e-6)
  
imports: import sys
  import os
  import time
  import random
  import mxnet
  import multiprocessing
  from mxnet.test_utils import check_consistency, set_default_device, assert_almost_equal, rand_ndarray, environment
  import numpy
  import math
  from mxnet import autograd
  import pytest
  from common import assert_raises_cudnn_not_satisfied, run_in_spawned_process, random_seed
  from test_gluon import *
  from test_loss import *
  from test_numpy_loss import *
  from test_gluon_rnn import *
label_desc: Use image node_id 6 for calling a global function with example usage: check_layer_bidirectional(size, in_size, proj_size) and returns: mx