code: def test_model(tf_model_path, gluon_model):
      # test data
      ctx = mx.cpu()
  
      seed = 123
      batch_size = 3
      seq_length = 32
      vocab_size = gluon_model._backbone_model._vocab_size
      np.random.seed(seed)
      input_ids = np.random.randint(
          0, vocab_size, (batch_size, seq_length)
      )
  
      with open(os.path.join(tf_model_path, "hparams.json"), "r") as hf:
          tf_cfg = json.load(hf)
      hparams = HParams(
          n_vocab=tf_cfg["n_vocab"],
          n_ctx=tf_cfg["n_ctx"],
          n_embd=tf_cfg["n_embd"],
          n_head=tf_cfg["n_head"],
          n_layer=tf_cfg["n_layer"],
      )
      tf_start_states = np.zeros(
          (
              batch_size,
              hparams.n_layer,
              2,
              hparams.n_head,
              0,
              hparams.n_embd // hparams.n_head,
          )
      )
      gl_start_states = gluon_model.init_states(batch_size, ctx)
  
      # gluon model
      gl_input_ids = mx.np.array(input_ids, dtype=np.int32, ctx=ctx)
      gl_logits_1, gl_states = gluon_model(
          gl_input_ids, gl_start_states
      )
      gl_logits_2, _ = gluon_model(gl_input_ids, gl_states)
  
      # tf model
      with tf.Session(graph=tf.Graph()) as sess:
          tf.set_random_seed(None)
          tf_context = tf.placeholder(
              tf.int32, [batch_size, seq_length]
          )
          tf_past = tf.placeholder(
              tf.float32,
              [
                  batch_size,
                  hparams.n_layer,
                  2,
                  hparams.n_head,
                  None,
                  hparams.n_embd // hparams.n_head,
              ],
          )
          tf_lm_output = model.model(
              hparams=hparams,
              X=tf_context,
              past=tf_past,
              reuse=tf.AUTO_REUSE,
          )
  
          tf_saver = tf.train.Saver()
          tf_ckpt = tf.train.latest_checkpoint(tf_model_path)
          tf_saver.restore(sess, tf_ckpt)
  
          tf_output_1 = sess.run(
              tf_lm_output,
              feed_dict={
                  tf_context: input_ids,
                  tf_past: tf_start_states,
              },
          )
          tf_logits_1 = tf_output_1["logits"]
          tf_present = tf_output_1["present"]
  
          tf_output_2 = sess.run(
              tf_lm_output,
              feed_dict={tf_context: input_ids, tf_past: tf_present},
          )
          tf_logits_2 = tf_output_2["logits"]
  
      for j in range(batch_size):
          assert_allclose(
              gl_logits_1[j, :, :].asnumpy(),
              tf_logits_1[j, :, :],
              1e-3,
              1e-3,
          )
      for j in range(batch_size):
          assert_allclose(
              gl_logits_2[j, :, :].asnumpy(),
              tf_logits_2[j, :, :],
              1e-3,
              1e-3,
          )
  
imports: import os
  import re
  import json
  import shutil
  import logging
  import argparse
  import tensorflow
  from tensorflow.contrib.training import HParams
  from gpt_2.src import model
  import mxnet
  import numpy
  from numpy.testing import assert_allclose
  from gluonnlp.data.vocab import Vocab
  from gluonnlp.utils.misc import sha1sum, logging_config, naming_convention
  from gluonnlp.models.gpt2 import GPT2Model, GPT2ForLM
label_desc: Use image node_id 7 for calling a global function with example usage: test_model(tf_model_path, gluon_model) without return types