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.encoder.sentence_encoder.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
      )
      # project the all tokens that is taking whole positions
      gl_masked_positions = mx.npx.arange_like(gl_input_ids, axis=1)
      gl_masked_positions = gl_masked_positions + mx.np.zeros_like(
          gl_input_ids
      )
  
      fs_input_ids = torch.from_numpy(input_ids).cuda(gpu)
  
      fairseq_model.model.eval()
  
      gl_all_hiddens, gl_pooled, gl_mlm_scores = gluon_model(
          gl_input_ids, gl_valid_length, gl_masked_positions
      )
  
      fs_mlm_scores, fs_extra = fairseq_model.model.cuda(gpu)(
          fs_input_ids, return_all_hiddens=True
      )
      fs_all_hiddens = fs_extra["inner_states"]
  
      # checking all_encodings_outputs
      num_layers = fairseq_model.args.encoder_layers
      for i in range(num_layers + 1):
          gl_hidden = gl_all_hiddens[i].asnumpy()
          fs_hidden = fs_all_hiddens[i]
          fs_hidden = fs_hidden.transpose(0, 1)
          fs_hidden = fs_hidden.detach().cpu().numpy()
          for j in range(batch_size):
              assert_allclose(
                  gl_hidden[j, : valid_length[j], :],
                  fs_hidden[j, : valid_length[j], :],
                  1e-3,
                  1e-3,
              )
      # checking masked_language_scores
      gl_mlm_scores = gl_mlm_scores.asnumpy()
      fs_mlm_scores = fs_mlm_scores.detach().cpu().numpy()
      for j in range(batch_size):
          assert_allclose(
              gl_mlm_scores[j, : valid_length[j], :],
              fs_mlm_scores[j, : valid_length[j], :],
              1e-3,
              1e-3,
          )
  
imports: import os
  import re
  import sys
  import json
  import shutil
  import logging
  import argparse
  import mxnet
  import numpy
  from numpy.testing import assert_allclose
  import torch
  from gluonnlp.data.vocab import Vocab
  from gluonnlp.utils.misc import sha1sum, logging_config, naming_convention
  from fairseq.models.roberta import RobertaModel
  from gluonnlp.models.roberta import RobertaModel, RobertaForMLM
  from gluonnlp.data.tokenizers import HuggingFaceByteBPETokenizer
label_desc: Use image node_id 6 for calling a global function with example usage: test_model(fairseq_model, gluon_model, gpu) without return types