code: def _testDynamicDecodeRNN(
      self, time_major, maximum_iterations=None
  ):  # pylint:disable=invalid-name
      sequence_length = [3, 4, 3, 1, 0]
      batch_size = 5
      max_time = 8
      input_depth = 7
      cell_depth = 10
      max_out = max(sequence_length)
  
      with self.session(use_gpu=True) as sess:
          if time_major:
              inputs = np.random.randn(
                  max_time, batch_size, input_depth
              ).astype(np.float32)
          else:
              inputs = np.random.randn(
                  batch_size, max_time, input_depth
              ).astype(np.float32)
          cell = tf.nn.rnn_cell.LSTMCell(cell_depth)
          helper = seq2seq.TrainingHelper(
              inputs, sequence_length, time_major=time_major
          )
          my_decoder = seq2seq.BasicDecoder(
              cell=cell,
              helper=helper,
              initial_state=cell.zero_state(
                  dtype=tf.float32, batch_size=batch_size
              ),
          )
  
          (
              final_outputs,
              final_state,
              final_sequence_length,
          ) = seq2seq.dynamic_decode(
              my_decoder,
              output_time_major=time_major,
              maximum_iterations=maximum_iterations,
          )
  
          def _t(shape):
              if time_major:
                  return (shape[1], shape[0]) + shape[2:]
              return shape
  
          self.assertIsInstance(
              final_outputs, seq2seq.BasicDecoderOutput
          )
          self.assertIsInstance(
              final_state, tf.nn.rnn_cell.LSTMStateTuple
          )
  
          self.assertEqual(
              (batch_size,),
              tuple(final_sequence_length.get_shape().as_list()),
          )
          self.assertEqual(
              _t((batch_size, None, cell_depth)),
              tuple(final_outputs.rnn_output.get_shape().as_list()),
          )
          self.assertEqual(
              _t((batch_size, None)),
              tuple(final_outputs.sample_id.get_shape().as_list()),
          )
  
          sess.run(tf.global_variables_initializer())
          sess_results = sess.run(
              {
                  "final_outputs": final_outputs,
                  "final_state": final_state,
                  "final_sequence_length": final_sequence_length,
              }
          )
  
          # 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
              ]
          self.assertEqual(
              _t((batch_size, time_steps, cell_depth)),
              sess_results["final_outputs"].rnn_output.shape,
          )
          self.assertEqual(
              _t((batch_size, time_steps)),
              sess_results["final_outputs"].sample_id.shape,
          )
          self.assertCountEqual(
              expected_length, sess_results["final_sequence_length"]
          )
  
imports: from magenta.contrib import seq2seq
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling the DynamicDecodeRNNTest obj's underlying member method code with example usage: obj._testDynamicDecodeRNN(time_major, maximum_iterations) and returns: shape, unknown