class_docstr: Tests :class:`~texar.torch.modules.GPT2Decoder`
      
docstr: Tests the functionality of automatically collecting trainable
  variables.
code: def test_trainable_variables(self):
      r"""Tests the functionality of automatically collecting trainable
      variables.
      """
  
      inputs = tf.placeholder(dtype=tf.int32, shape=[2, 3])
  
      def get_variable_num(n_layers: int) -> int:
          return 1 + 1 + n_layers * 16 + 2
  
      # case 1: GPT2 small
      decoder = GPT2Decoder()
      _ = decoder(inputs=inputs)
      self.assertEqual(
          len(decoder.trainable_variables), get_variable_num(12)
      )
  
      # case 2: GPT2 medium
      hparams = {
          "pretrained_model_name": "gpt2-medium",
      }
      decoder = GPT2Decoder(hparams=hparams)
      _ = decoder(inputs=inputs)
      self.assertEqual(
          len(decoder.trainable_variables), get_variable_num(24)
      )
  
      # case 2: GPT2 large
      hparams = {
          "pretrained_model_name": "gpt2-large",
      }
      decoder = GPT2Decoder(hparams=hparams)
      _ = decoder(inputs=inputs)
      self.assertEqual(
          len(decoder.trainable_variables), get_variable_num(36)
      )
  
      # case 3: self-designed GPT2
      hparams = {
          "pretrained_model_name": None,
          "decoder": {
              "num_blocks": 6,
          },
      }
      decoder = GPT2Decoder(hparams=hparams)
      _ = decoder(inputs=inputs)
      self.assertEqual(
          len(decoder.trainable_variables), get_variable_num(6)
      )
  
file_path: texar/tests/modules/decoders/gpt2_decoder_test.py
imports: import tensorflow
  from texar.tf.modules.decoders.gpt2_decoder import GPT2Decoder
  from texar.tf.modules.decoders.transformer_decoders import TransformerDecoderOutput
  from texar.tf.utils.test import pretrained_test
label_desc: Use image node_id 2 for calling the GPT2DecoderTest obj's underlying member method code with example usage: obj.test_trainable_variables() and returns: unknown