code: def testTransformer(self):
      batch_size = 3
      input_length = 5
      target_length = 7
      vocab_size = 9
      hparams = transformer_revnet_test()
      p_hparams = problem_hparams.test_problem_hparams(
          vocab_size, vocab_size, hparams
      )
      hparams.problem_hparams = p_hparams
      inputs = np.random.randint(
          vocab_size, size=(batch_size, input_length, 1, 1)
      )
      targets = np.random.randint(
          vocab_size, size=(batch_size, target_length, 1, 1)
      )
      features = {
          "inputs": tf.constant(inputs, dtype=tf.int32),
          "targets": tf.constant(targets, dtype=tf.int32),
          "target_space_id": tf.constant(1, dtype=tf.int32),
      }
      model = transformer_revnet.TransformerRevnet(
          hparams, tf_estimator.ModeKeys.TRAIN, p_hparams
      )
      logits, _ = model(features)
      grads = tf.gradients(
          tf.reduce_mean(logits),
          [features["inputs"]] + tf.global_variables(),
      )
      grads = [g for g in grads if g is not None]
  
      with self.test_session() as session:
          session.run(tf.global_variables_initializer())
          logits_val, _ = session.run([logits, grads])
      self.assertEqual(
          logits_val.shape,
          (batch_size, target_length, 1, 1, vocab_size),
      )
  
file_path: tensor2tensor/tensor2tensor/models/research/transformer_revnet_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from tensor2tensor.data_generators import problem_hparams
  from tensor2tensor.models.research import transformer_revnet
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 1 for calling the TransformerRevnetTest obj's underlying member method code with example usage: obj.testTransformer() without return types