class_docstr: Tests params, residual capabilities, padding leaks, and output shape.
code: def test_decoder_layer(self, translation_layer_name, output_depth):
      with self.test_session(graph=tf.Graph()) as sess:
          # Check that the output shape is as expected.
          input_tensor = tf.placeholder(
              tf.float32,
              [_BATCH_SIZE, _TOTAL_SEQUENCE_LENGTH, _INPUT_DEPTH],
          )
          encoder_depth = int(_INPUT_DEPTH / 2)
          for prefix in _RESIZE_EXEMPT_LAYER_PREFIXES:
              if prefix in translation_layer_name:
                  output_depth = _INPUT_DEPTH
          translation_layer = layers.DECODER_LAYERS.get(
              translation_layer_name
          )
          output_tensor = _apply_decoder_layer(
              translation_layer,
              input_tensor,
              output_depth,
              encoder_depth,
          )
          self.assertEqual(
              output_tensor.shape.as_list(),
              [_BATCH_SIZE, _TOTAL_SEQUENCE_LENGTH, output_depth],
          )
  
          # Check that the number of parameters is as expected.
          empirical_num_params = _get_empirical_parameters()
          reported_num_params = translation_layer.num_params(
              _INPUT_DEPTH, output_depth, encoder_depth=encoder_depth
          )
          self.assertEqual(empirical_num_params, reported_num_params)
  
          # Check that there is no temporal information leak. Specifically, check
          # that values before `test_index` remain unchanged, while the values
          # after it have changed. Sums are used because two values could
          # potentially be the same between the zero and non-zero portions, even
          # if the masking is working correctly. Note: This assumes that the
          # output at t is dependent on the input at t.
          feed_input = (
              np.random.random(
                  [_BATCH_SIZE, _TOTAL_SEQUENCE_LENGTH, _INPUT_DEPTH]
              )
              / 10.0
          )
          test_index = int(_TOTAL_SEQUENCE_LENGTH / 2)
          transformed_feed_input = _zero_after_index_copy(
              feed_input, test_index
          )
  
          # Produce the outputs for both types of input.
          feed_dict = {
              v: np.random.rand(*v.shape.as_list()) - 0.5
              for v in tf.all_variables()
          }
          feed_dict[input_tensor] = feed_input
          control_output = sess.run(output_tensor, feed_dict)
  
          feed_dict[input_tensor] = transformed_feed_input
          variable_output = sess.run(output_tensor, feed_dict)
  
          self.assertAllClose(
              control_output[:, : test_index + 1],
              variable_output[:, : test_index + 1],
              rtol=1,
          )
  
          with self.assertRaises(
              AssertionError,
              msg="Time-masked portion of output too close to control output.",
          ):
              self.assertAllClose(
                  control_output[:, test_index + 1 :],
                  variable_output[:, test_index + 1 :],
                  rtol=1,
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import itertools
  from absl.testing import parameterized
  import numpy
  from tensor2tensor.layers import common_attention
  from tensor2tensor.models import transformer
  from tensor2tensor.models.neural_architecture_search import nas_layers
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling the LayersTest obj's underlying member method code with example usage: obj.test_decoder_layer(translation_layer_name, output_depth) without return types