class_docstr: Tests :class:`~texar.tf.modules.XLNetEncoder` class.
      
docstr: Tests the functionality of automatically collecting trainable
  variables.
code: def test_trainable_variables(self):
      """Tests the functionality of automatically collecting trainable
      variables.
      """
  
      inputs = tf.placeholder(dtype=tf.int32, shape=[None, None])
  
      # case 1: XLNet with no pre-trained model
      encoder = XLNetEncoder(
          hparams={"pretrained_model_name": None, "untie_r": False}
      )
      encoder(inputs)
  
      n_word_embed_vars = 1
      n_mask_embed_vars = 1
      n_bias_vars = 3  # r_r_bias, r_w_bias, r_s_bias
      n_pos_wise_ff_vars = 6  # 2 kernels + 2 bias + beta + gamma
      n_rel_multi_head_vars = 7  # q,k,v,r,o + beta + gamma
      n_segment_embed_vars = 1
      n_layers = encoder.hparams.num_layers
      n_trainable_variables = (
          n_word_embed_vars
          + n_segment_embed_vars
          + n_mask_embed_vars
          + n_layers * (n_rel_multi_head_vars + n_pos_wise_ff_vars)
          + n_bias_vars
      )
      self.assertEqual(
          len(encoder.trainable_variables), n_trainable_variables
      )
  
      # case 2: XLNet with pre-trained model
      hparams = {"pretrained_model_name": "xlnet-large-cased"}
      encoder = XLNetEncoder(hparams=hparams)
      encoder(inputs)
      n_segment_embed_vars = 1
      n_layers = encoder.hparams.num_layers
      n_trainable_variables = (
          n_word_embed_vars
          + n_segment_embed_vars
          + n_mask_embed_vars
          + n_layers * (n_rel_multi_head_vars + n_pos_wise_ff_vars)
          + n_bias_vars
      )
      self.assertEqual(
          len(encoder.trainable_variables), n_trainable_variables
      )
  
file_path: texar/tests/modules/encoders/xlnet_encoder_test.py
imports: import tensorflow
  from texar.tf.modules.encoders.xlnet_encoder import XLNetEncoder
  from texar.tf.utils.test import pretrained_test
label_desc: Use image node_id 3 for calling the XLNetEncoderTest obj's underlying member method code with example usage: obj.test_trainable_variables() without return types