class_docstr: Transformer encoder layer.
  
  Attributes:
    mlp_dim: Dimension of the mlp on top of attention block.
    num_heads: Number of self-attention heads.
    dtype: The dtype of the computation (default: float32).
    dropout_rate: Dropout rate.
    attention_dropout_rate: Dropout for attention heads.
    stochastic_depth: probability of dropping a layer linearly grows from 0 to
      the provided value.
  
  Returns:
    output after transformer encoder block.
docstr: Applies Encoder1DBlock module.
  
  Args:
    inputs_q: Input data used to generate query.
    inputs_kv: Input data used to generate key/value.
    input_mask: Input mask, used for text input.
    added_tape_len: Length of the tape that is added to the original input, in
      terms of number of tape tokens.
    deterministic: Deterministic or not (to apply dropout).
  
  Returns:
    Output after transformer encoder block.
docstr_tok: ["Applies","Encoder1DBlock","module",".","Args",":","inputs_q",":","Input","data","used","to","generate","query",".","inputs_kv",":","Input","data","used","to","generate","key\/value",".","input_mask",":","Input","mask",",","used","for","text","input",".","added_tape_len",":","Length","of","the","tape","that","is","added","to","the","original","input",",","in","terms","of","number","of","tape","tokens",".","deterministic",":","Deterministic","or","not","(","to","apply","dropout",")",".","Returns",":","Output","after","transformer","encoder","block","."]
code: def __call__(
      self,  # pytype: disable=annotation-type-mismatch  # jax-ndarray
      inputs_q: jnp.ndarray,
      inputs_kv: jnp.ndarray = None,
      input_mask: Optional[jnp.ndarray] = None,
      added_tape_len: int = 0,
      deterministic: bool = None,
  ) -> jnp.ndarray:
      """Applies Encoder1DBlock module.
  
      Args:
        inputs_q: Input data used to generate query.
        inputs_kv: Input data used to generate key/value.
        input_mask: Input mask, used for text input.
        added_tape_len: Length of the tape that is added to the original input, in
          terms of number of tape tokens.
        deterministic: Deterministic or not (to apply dropout).
  
      Returns:
        Output after transformer encoder block.
      """
      assert inputs_q.ndim == 3
      # Attention block.
      x_q = nn.LayerNorm(dtype=self.dtype)(inputs_q)
      if inputs_kv is not None:
          assert inputs_kv.ndim == 3
          x_kv = nn.LayerNorm(dtype=self.dtype)(inputs_kv)
      else:
          x_kv = x_q
      if input_mask is not None:
          attention_mask = input_mask[:, None, None, :] * jnp.ones(
              [1, 1, x_q.shape[1], 1]
          )
      else:
          attention_mask = None
  
      x = nn.MultiHeadDotProductAttention(
          num_heads=self.num_heads,
          dtype=self.dtype,
          kernel_init=nn.initializers.xavier_uniform(),
          broadcast_dropout=False,
          deterministic=deterministic,
          dropout_rate=self.attention_dropout_rate,
      )(x_q, x_kv, mask=attention_mask)
      x = nn.Dropout(rate=self.dropout_rate)(x, deterministic)
      x = nn_layers.StochasticDepth(rate=self.stochastic_depth)(
          x, deterministic
      )
      x = x + inputs_q
  
      # MLP block.
      y = nn.LayerNorm(dtype=self.dtype)(x)
      use_tap_mlp = (
          self.ac_config.get("enc_tt_mlp_dim", 0) and added_tape_len
      )
      if use_tap_mlp:
          # Slice out y, and y_tapes:
          y, y_tapes = jnp.split(
              y, [(y.shape[1] - added_tape_len)], axis=1
          )
          y_tapes = MlpBlock(
              mlp_dim=self.ac_config.enc_tt_mlp_dim,
              dtype=self.dtype,
              dropout_rate=self.ac_config.enc_tt_dropout_rate,
              activation_fn=nn.glu,
              kernel_init=nn.initializers.xavier_uniform(),
              bias_init=nn.initializers.normal(stddev=1e-6),
              name="tape_mlp",
          )(y_tapes, deterministic=deterministic)
  
      y = MlpBlock(
          mlp_dim=self.mlp_dim,
          dtype=self.dtype,
          dropout_rate=self.dropout_rate,
          activation_fn=nn.gelu,
          kernel_init=nn.initializers.xavier_uniform(),
          bias_init=nn.initializers.normal(stddev=1e-6),
      )(y, deterministic=deterministic)
      if use_tap_mlp:
          y = jnp.concatenate([y, y_tapes], axis=1)
  
      y = nn_layers.StochasticDepth(rate=self.stochastic_depth)(
          y, deterministic
      )
      return y + x
  
imports: from typing import Any, Callable, Optional, Sequence, Tuple
  from absl import logging
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  from scenic.model_lib.layers import nn_layers
label_desc: Use image node_id 1 for calling the Encoder1DBlock obj's underlying member method code with example usage: obj.__call__(inputs_q, inputs_kv, input_mask, added_tape_len, deterministic) and returns: unknown