code: def test_model(fairseq_model, gluon_model, gpu):
      print("testing model")
      ctx = mx.gpu(gpu) if gpu is not None else mx.cpu()
      batch_size = 3
      seq_length = 32
      vocab_size = len(fairseq_model.task.dictionary)
      padding_id = fairseq_model.model.decoder.padding_idx
      input_ids = np.random.randint(  # skip padding_id
          padding_id + 1, vocab_size, (batch_size, seq_length)
      )
      valid_length = np.random.randint(
          seq_length // 2, seq_length, (batch_size,)
      )
  
      for i in range(
          batch_size
      ):  # add padding, for fairseq padding mask
          input_ids[i, valid_length[i] :] = padding_id
  
      gl_input_ids = mx.np.array(input_ids, dtype=np.int32, ctx=ctx)
      gl_valid_length = mx.np.array(
          valid_length, dtype=np.int32, ctx=ctx
      )
      gl_dec_out = gluon_model(
          gl_input_ids, gl_valid_length, gl_input_ids, gl_valid_length
      )
  
      fs_input_ids = torch.from_numpy(input_ids).cuda(gpu)
      fairseq_model.model.eval()
      fs_dec_out, fs_extra = fairseq_model.model.cuda(gpu)(
          fs_input_ids,
          valid_length,
          fs_input_ids,
          return_all_hiddens=True,
      )
  
      # checking decoder output
      gl_dec_out = gl_dec_out.asnumpy()
      fs_dec_out = fs_dec_out.detach().cpu().numpy()
      for j in range(batch_size):
          assert_allclose(
              gl_dec_out[j, : valid_length[j], :],
              fs_dec_out[j, : valid_length[j], :],
              1e-3,
              1e-3,
          )
  
file_path: gluon-nlp/scripts/conversion_toolkits/convert_fairseq_bart.py
imports: import os
  import shutil
  import logging
  import argparse
  import mxnet
  import numpy
  from numpy.testing import assert_allclose
  import torch
  from fairseq.models.bart import BARTModel
  from gluonnlp.utils.misc import sha1sum, logging_config, naming_convention
  from gluonnlp.models.bart import BartModel
  from convert_fairseq_roberta import convert_vocab
label_desc: Use image node_id 4 for calling a global function with example usage: test_model(fairseq_model, gluon_model, gpu) without return types