class_docstr: Tests :class:`~texar.torch.modules.GPT2Encoder` class.
      
docstr: Tests the priority of the encoder arch parameter.
          
code: def test_hparams(self):
      """Tests the priority of the encoder arch parameter."""
  
      inputs = tf.placeholder(dtype=tf.int32, shape=[None, None])
  
      # case 1: set "pretrained_mode_name" by constructor argument
      hparams = {
          "pretrained_model_name": "gpt2-medium",
      }
      encoder = GPT2Encoder(
          pretrained_model_name="gpt2-small", hparams=hparams
      )
      _ = encoder(inputs)
      self.assertEqual(encoder.hparams.encoder.num_blocks, 12)
  
      # case 2: set "pretrained_mode_name" by hparams
      hparams = {
          "pretrained_model_name": "gpt2-small",
          "encoder": {"num_blocks": 6},
      }
      encoder = GPT2Encoder(hparams=hparams)
      _ = encoder(inputs)
      self.assertEqual(encoder.hparams.encoder.num_blocks, 12)
  
      # case 3: set to None in both hparams and constructor argument
      hparams = {
          "pretrained_model_name": None,
          "encoder": {"num_blocks": 6},
      }
      encoder = GPT2Encoder(hparams=hparams)
      _ = encoder(inputs)
      self.assertEqual(encoder.hparams.encoder.num_blocks, 6)
  
      # case 4: using default hparams
      encoder = GPT2Encoder()
      _ = encoder(inputs)
      self.assertEqual(encoder.hparams.encoder.num_blocks, 12)
  
file_path: texar/tests/modules/encoders/gpt2_encoder_test.py
imports: import tensorflow
  from texar.tf.modules.encoders.gpt2_encoder import GPT2Encoder
  from texar.tf.utils.test import pretrained_test
label_desc: Use image node_id 2 for calling the GPT2EncoderTest obj's underlying member method code with example usage: obj.test_hparams() without return types