# Path: mesh_tensorflow/ops_with_redefined_builtins.py



import gin
import tensorflow.compat.v1 as tf
from mesh_tensorflow import ops_with_redefined_builtins as mtf
    alpha: alpha for length penalty.
    states: list of mtf.Tensor
    eos_id: ID for end of sentence.
    stop_early: a boolean - stop once best sequence is provably determined.
    decode_length: a mtf Scalar of dtype tf.int32 - maximum length of decodes
    use_tpu: a boolean
    dtype: a tf.dtype
    layout: an optional string
    mesh_shape: an optional string
    num_prefilter: an optional integer
  Returns:
    Tuple of
    (decoded beams [batch, beam, length]
     decoding probabilities [batch, beam_size])
  """
  batch_dim, beam_dim, length_dim = initial_ids.shape.dims
  batch_and_beam_dim = mtf.Dimension(
      batch_dim.name, batch_dim.size * beam_dim.size)
  mesh = initial_ids.mesh

  batch_by_beam = mtf.Shape([batch_dim, beam_dim])
  initial_log_probs = mtf.broadcast(
      mtf.one_hot(
          mtf.constant(mesh, 0, dtype=tf.int32),
          beam_dim,
          on_value=0.0,
          off_value=-INF,
          dtype=dtype),
      batch_by_beam)


# Path: mesh_tensorflow/ops_with_redefined_builtins.py



# Path: mesh_tensorflow/beam_search.py
import gin
import tensorflow.compat.v1 as tf
from mesh_tensorflow import ops_with_redefined_builtins as mtf

    alpha: alpha for length penalty.
    states: list of mtf.Tensor
    eos_id: ID for end of sentence.
    stop_early: a boolean - stop once best sequence is provably determined.
    decode_length: a mtf Scalar of dtype tf.int32 - maximum length of decodes
    use_tpu: a boolean
    dtype: a tf.dtype
    layout: an optional string
    mesh_shape: an optional string
    num_prefilter: an optional integer
  Returns:
    Tuple of
    (decoded beams [batch, beam, length]
     decoding probabilities [batch, beam_size])
  """
  batch_dim, beam_dim, length_dim = initial_ids.shape.dims
  batch_and_beam_dim = mtf.Dimension(
      batch_dim.name, batch_dim.size * beam_dim.size)
  mesh = initial_ids.mesh

  batch_by_beam = mtf.Shape([batch_dim, beam_dim])
  initial_log_probs = mtf.broadcast(
      mtf.one_hot(
          mtf.constant(mesh, 0, dtype=tf.int32),
          beam_dim,
          on_value=0.0,
          off_value=-INF,
          dtype=dtype),
      batch_by_beam)


  length_scalar = mtf.constant(mesh, length_dim.size, dtype=tf.int32)