code: def test_lm():
      n_vocab = 3
      n_layers = 2
      n_units = 2
      batchsize = 5
      for typ in ["lstm"]:  # TODO(anyone) gru
          rnnlm_ch = lm_chainer.ClassifierWithState(
              lm_chainer.RNNLM(n_vocab, n_layers, n_units, typ=typ)
          )
          rnnlm_th = lm_pytorch.ClassifierWithState(
              lm_pytorch.RNNLM(n_vocab, n_layers, n_units, typ=typ)
          )
          transfer_lm(rnnlm_ch.predictor, rnnlm_th.predictor)
  
          # test prediction equality
          x = torch.from_numpy(
              numpy.random.randint(n_vocab, size=batchsize)
          ).long()
          with torch.no_grad(), chainer.no_backprop_mode(), chainer.using_config(
              "train", False
          ):
              rnnlm_th.predictor.eval()
              state_th, y_th = rnnlm_th.predictor(None, x.long())
              state_ch, y_ch = rnnlm_ch.predictor(None, x.data.numpy())
              for k in state_ch.keys():
                  for n in range(len(state_th[k])):
                      print(k, n)
                      print(state_th[k][n].data.numpy())
                      print(state_ch[k][n].data)
                      numpy.testing.assert_allclose(
                          state_th[k][n].data.numpy(),
                          state_ch[k][n].data,
                          1e-5,
                      )
              numpy.testing.assert_allclose(
                  y_th.data.numpy(), y_ch.data, 1e-5
              )
  
file_path: espnet/test/test_lm.py
imports: from test.test_beam_search import prepare, rnn_args
  import chainer
  import numpy
  import pytest
  import torch
  import espnet.lm.chainer_backend.lm
  import espnet.nets.pytorch_backend.lm.default
  from espnet.nets.beam_search import beam_search
  from espnet.nets.lm_interface import dynamic_import_lm
  from espnet.nets.scorers.length_bonus import LengthBonus
label_desc: Use image node_id 3 for calling a global function with example usage: test_lm() without return types