code: def _dynamic_unroll_multi_step(
      cell,
      inputs,
      reset_mask,
      initial_state,
      zero_state,
      dtype,
      parallel_iterations,
      swap_memory,
      iterations,
      const_batch_size,
      training,
  ):
      """Helper for dynamic_unroll which uses a tf.while_loop."""
  
      # Convert all inputs to TensorArrays
      def ta_and_unstack(x):
          return tf.TensorArray(
              dtype=x.dtype, size=iterations, element_shape=x.shape[1:]
          ).unstack(x)
  
      inputs_tas = tf.nest.map_structure(ta_and_unstack, inputs)
      if reset_mask is None:
          reset_mask_ta = None
      else:
          reset_mask_ta = ta_and_unstack(reset_mask)
  
      # Create a TensorArray for each output
      def create_output_ta(s):
          return tf.TensorArray(
              dtype=_infer_state_dtype(dtype, initial_state),
              size=iterations,
              element_shape=(
                  tf.TensorShape([const_batch_size]).concatenate(
                      _maybe_tensor_shape_from_tensor(s)
                  )
              ),
          )
  
      output_tas = tf.nest.map_structure(
          create_output_ta, cell.output_size
      )
  
      def pred(time, *unused_args):
          return time < iterations
  
      def body(time, state, output_tas):
          """Internal while_loop body.
  
          Args:
            time: time
            state: rnn state @ time
            output_tas: output tensorarrays
  
          Returns:
            - time + 1
            - state: rnn state @ time + 1
            - output_tas: output tensorarrays with values written @ time
            - masks_ta: optional mask tensorarray with mask written @ time
          """
          input_ = tf.nest.map_structure(
              lambda ta: ta.read(time), inputs_tas
          )
          if reset_mask_ta is not None:
              is_reset = reset_mask_ta.read(time)
              state = tf.nest.map_structure(
                  lambda s_zero, s: _maybe_reset_state(
                      is_reset, s_zero, s
                  ),
                  zero_state,
                  state,
              )
  
          outputs, next_state = cell(input_, state, training=training)
  
          output_tas = tf.nest.map_structure(
              lambda ta, x: ta.write(time, x), output_tas, outputs
          )
  
          return (time + 1, next_state, output_tas)
  
      # Create a new scope in which the caching device is either
      # determined by the parent scope, or is set to place the cached
      # Variable using the same placement as for the rest of the RNN.
      with tf.compat.v1.variable_scope(
          tf.compat.v1.get_variable_scope()
      ) as varscope:
          if (
              not tf.executing_eagerly()
              and varscope.caching_device is None
          ):
              varscope.set_caching_device(lambda op: op.device)
  
          _, final_state, output_tas = tf.while_loop(
              cond=pred,
              body=body,
              loop_vars=(
                  tf.constant(0, name="time"),
                  initial_state,
                  output_tas,
              ),
              parallel_iterations=parallel_iterations,
              swap_memory=swap_memory,
              maximum_iterations=iterations,
          )
  
      outputs = tf.nest.map_structure(lambda ta: ta.stack(), output_tas)
  
      if isinstance(iterations, int):
          # TensorArray.stack() doesn't set a static value for dimension 0,
          # even if the size is known. Set the shapes here.
          iterations_shape = tf.TensorShape([iterations])
          tf.nest.map_structure(
              lambda t: t.set_shape(
                  iterations_shape.concatenate(t.shape[1:])
              ),
              outputs,
          )
  
      # Convert everything back to batch major
      outputs = tf.nest.map_structure(
          common.transpose_batch_time, outputs
      )
  
      return (outputs, final_state)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  from tf_agents.utils import common
label_desc: Use image node_id 6 for calling a global function with example usage: _dynamic_unroll_multi_step(cell, inputs, reset_mask, initial_state, zero_state, dtype, parallel_iterations, swap_memory, iterations, const_batch_size, training) and returns: outputs,  final_state, tf, tf, unknown, unknown,  next_state,  output_tas