code: def test_dynamic_decode_rnn(time_major, maximum_iterations):
      sequence_length = [3, 4, 3, 1, 0]
      batch_size = 5
      max_time = 8
      input_depth = 7
      cell_depth = 10
      max_out = max(sequence_length)
  
      cell = tf.keras.layers.LSTMCell(cell_depth)
      sampler = sampler_py.TrainingSampler(time_major=time_major)
      my_decoder = basic_decoder.BasicDecoder(
          cell=cell,
          sampler=sampler,
          output_time_major=time_major,
          maximum_iterations=maximum_iterations,
      )
  
      @tf.function(
          input_signature=(
              tf.TensorSpec(
                  [None, None, input_depth], dtype=tf.float32
              ),
              tf.TensorSpec([None], dtype=tf.int32),
          )
      )
      def _decode(inputs, sequence_length):
          batch_size_t = tf.shape(sequence_length)[0]
          initial_state = cell.get_initial_state(
              batch_size=batch_size_t, dtype=inputs.dtype
          )
          return my_decoder(
              inputs,
              initial_state=initial_state,
              sequence_length=sequence_length,
          )
  
      inputs = tf.random.normal([batch_size, max_time, input_depth])
      if time_major:
          inputs = tf.transpose(inputs, perm=[1, 0, 2])
      final_outputs, _, final_sequence_length = _decode(
          inputs, sequence_length
      )
  
      def _t(shape):
          if time_major:
              return (shape[1], shape[0]) + shape[2:]
          return shape
  
      assert (batch_size,) == tuple(
          final_sequence_length.shape.as_list()
      )
      # Mostly a smoke test
      time_steps = max_out
      expected_length = sequence_length
      if maximum_iterations is not None:
          time_steps = min(max_out, maximum_iterations)
          expected_length = [
              min(x, maximum_iterations) for x in expected_length
          ]
      assert (
          _t((batch_size, time_steps, cell_depth))
          == final_outputs.rnn_output.shape
      )
      assert (
          _t((batch_size, time_steps)) == final_outputs.sample_id.shape
      )
      np.testing.assert_array_equal(
          expected_length, final_sequence_length
      )
  
file_path: addons/tensorflow_addons/seq2seq/tests/decoder_test.py
imports: import numpy
  import pytest
  import tensorflow
  from tensorflow_addons.seq2seq import basic_decoder
  from tensorflow_addons.seq2seq import decoder
  from tensorflow_addons.seq2seq import sampler
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 1 for calling a global function with example usage: test_dynamic_decode_rnn(time_major, maximum_iterations) and returns: my_decoder, shape, unknown