def _single_lstm(input_emb, input_len, hidden_size, is_fwd, use_cudnn):
  """Compute the outputs of a single LSTM (subroutine of stacked_bilstm).

  Be careful if used anywhere outside of stacked_bilstm, which converts the
  sequences to the time-major format expected by this function.

  Args:
    input_emb: <float32> [sequence_length, batch_size, emb]
    input_len: <int32> [batch_size]
    hidden_size: Number of units in the LSTM cell.
    is_fwd: Boolean indicator the directionality of the LSTM.
    use_cudnn: Boolean indicating the use of cudnn.

  Returns:
    output_emb: <float32> [sequence_length, batch_size, emb]
  """
  if not is_fwd:
    input_emb = tf.reverse_sequence(
        input_emb,
        input_len,
        seq_axis=0,
        batch_axis=1)
  if use_cudnn:
    lstm = contrib_cudnn_rnn.CudnnLSTM(
        num_layers=1,
        num_units=hidden_size,
        input_mode=cudnn_rnn_ops.CUDNN_INPUT_LINEAR_MODE,
        direction=cudnn_rnn_ops.CUDNN_RNN_UNIDIRECTION)
    lstm.build(input_emb.shape)
    output_emb, _ = lstm(input_emb)
  else:
    cell = contrib_cudnn_rnn.CudnnCompatibleLSTMCell(hidden_size)
    cell = contrib_rnn.MultiRNNCell([cell])
    output_emb, _ = tf.nn.dynamic_rnn(
        cell=cell,
        inputs=input_emb,
        sequence_length=input_len,
        dtype=tf.float32,
        time_major=True)
  if not is_fwd:
    output_emb = tf.reverse_sequence(
        output_emb,
        input_len,
        seq_axis=0,
        batch_axis=1)
  return output_emb
Compute the outputs of a single LSTM (subroutine of stacked_bilstm).

  Be careful if used anywhere outside of stacked_bilstm, which converts the
  sequences to the time-major format expected by this function.

  Args:
    input_emb: <float32> [sequence_length, batch_size, emb]
    input_len: <int32> [batch_size]
    hidden_size: Number of units in the LSTM cell.
    is_fwd: Boolean indicator the directionality of the LSTM.
    use_cudnn: Boolean indicating the use of cudnn.

  Returns:
    output_emb: <float32> [sequence_length, batch_size, emb]
  
language/common/layers/cudnn_layers.py