code: def sample_sequence_uniformly_with_state(
      sequence: tf.Tensor,
      num_steps: int,
      is_training: bool = True,
      state: Optional[builders.ProcessorState] = None,
  ) -> tf.Tensor:
      """mfp sample_sequence_uniformly with state."""
  
      sequence_length = tf.shape(input=sequence)[0]
      sequence_length = tf.cast(sequence_length, tf.int32)
      stride = tf.cast(sequence_length // num_steps, tf.int32)
  
      if state and "sample_sequence_uniformly_indices" in state:
          indices = state["sample_sequence_uniformly_indices"]
      else:
          if stride > 0:
              indices = tf.math.multiply(tf.range(num_steps), stride)
              if is_training:
                  indices = indices + tf.random.uniform(
                      shape=(1, num_steps),
                      minval=0,
                      maxval=stride,
                      dtype=tf.int32,
                  )
          else:
              if is_training:
                  indices = tf.sort(
                      tf.random.uniform(
                          shape=(1, num_steps),
                          minval=0,
                          maxval=sequence_length,
                          dtype=tf.int32,
                      )
                  )
              else:
                  stride_float = tf.cast(
                      sequence_length / num_steps, tf.float32
                  )
                  indices = tf.cast(
                      tf.range(num_steps, dtype=tf.float32)
                      * stride_float,
                      tf.int32,
                  )
          if state is not None:
              state["sample_sequence_uniformly_indices"] = indices
  
      if is_training:
          indices = indices[0]
  
      indices.set_shape((num_steps,))
      output = tf.gather(sequence, indices)
      return output
  
imports: from typing import Optional, Union
  from absl import logging
  from dmvr import builders
  from dmvr import processors
  import ml_collections
  import tensorflow
label_desc: Use image node_id 11 for calling a global function with example usage: sample_sequence_uniformly_with_state(sequence, num_steps, is_training, state) and returns: output