code: def test_transformer_inference(
      train_hybridize,
      inference_hybridize,
      enc_pre_norm,
      dec_pre_norm,
      enc_units,
      dec_units,
      enc_num_layers,
      dec_num_layers,
      enc_recurrent,
      dec_recurrent,
      tie_weights,
      layout,
  ):
      src_seq_length = 20
      tgt_seq_length = 15
      src_vocab_size = 32
      tgt_vocab_size = 32
      if enc_units != dec_units:
          shared_embed = False
      else:
          shared_embed = True
      model = TransformerModel(
          src_vocab_size=src_vocab_size,
          tgt_vocab_size=tgt_vocab_size,
          max_src_length=src_seq_length,
          max_tgt_length=tgt_seq_length,
          enc_units=enc_units,
          enc_hidden_size=64,
          enc_num_heads=4,
          enc_num_layers=enc_num_layers,
          enc_pre_norm=enc_pre_norm,
          enc_recurrent=enc_recurrent,
          dec_units=dec_units,
          dec_hidden_size=64,
          dec_num_heads=4,
          dec_num_layers=dec_num_layers,
          dec_pre_norm=dec_pre_norm,
          dec_recurrent=dec_recurrent,
          shared_embed=shared_embed,
          tie_weights=tie_weights,
          dropout=0.0,
          layout=layout,
      )
      inference_model = TransformerInference(model=model)
      model.initialize()
      if train_hybridize:
          model.hybridize()
      verify_nmt_model(model)
      if inference_hybridize:
          inference_model.hybridize()
      verify_nmt_inference(
          train_model=model, inference_model=inference_model
      )
  
file_path: gluon-nlp/tests/test_models_transformer.py
imports: import numpy
  import mxnet
  import pytest
  from numpy.testing import assert_allclose
  from gluonnlp.models.transformer import TransformerEncoder, TransformerDecoder, TransformerModel, TransformerInference, transformer_cfg_reg
  from gluonnlp.attention_cell import gen_mem_attn_mask, gen_self_attn_mask
  from gluonnlp.utils.testing import verify_nmt_model, verify_nmt_inference
  from gluonnlp.utils.testing import verify_backbone_fp16
  from gluonnlp.utils.parameter import count_parameters, deduplicate_param_dict
label_desc: Use image node_id 2 for calling a global function with example usage: test_transformer_inference(train_hybridize, inference_hybridize, enc_pre_norm, dec_pre_norm, enc_units, dec_units, enc_num_layers, dec_num_layers, enc_recurrent, dec_recurrent, tie_weights, layout) without return types