class_docstr: E-Branchformer encoder module.
class_docstr_tok: ["E-Branchformer","encoder","module","."]
code: def __init__(
      self,
      input_size: int,
      output_size: int = 256,
      attention_heads: int = 4,
      attention_layer_type: str = "rel_selfattn",
      pos_enc_layer_type: str = "rel_pos",
      rel_pos_type: str = "latest",
      cgmlp_linear_units: int = 2048,
      cgmlp_conv_kernel: int = 31,
      use_linear_after_conv: bool = False,
      gate_activation: str = "identity",
      num_blocks: int = 12,
      dropout_rate: float = 0.1,
      positional_dropout_rate: float = 0.1,
      attention_dropout_rate: float = 0.0,
      input_layer: Optional[str] = "conv2d",
      zero_triu: bool = False,
      padding_idx: int = -1,
      layer_drop_rate: float = 0.0,
      max_pos_emb_len: int = 5000,
      use_ffn: bool = False,
      macaron_ffn: bool = False,
      ffn_activation_type: str = "swish",
      linear_units: int = 2048,
      positionwise_layer_type: str = "linear",
      merge_conv_kernel: int = 3,
      interctc_layer_idx=None,
      interctc_use_conditioning: bool = False,
  ):
      assert check_argument_types()
      super().__init__()
      self._output_size = output_size
  
      if rel_pos_type == "legacy":
          if pos_enc_layer_type == "rel_pos":
              pos_enc_layer_type = "legacy_rel_pos"
          if attention_layer_type == "rel_selfattn":
              attention_layer_type = "legacy_rel_selfattn"
      elif rel_pos_type == "latest":
          assert attention_layer_type != "legacy_rel_selfattn"
          assert pos_enc_layer_type != "legacy_rel_pos"
      else:
          raise ValueError("unknown rel_pos_type: " + rel_pos_type)
  
      if pos_enc_layer_type == "abs_pos":
          pos_enc_class = PositionalEncoding
      elif pos_enc_layer_type == "scaled_abs_pos":
          pos_enc_class = ScaledPositionalEncoding
      elif pos_enc_layer_type == "rel_pos":
          assert attention_layer_type == "rel_selfattn"
          pos_enc_class = RelPositionalEncoding
      elif pos_enc_layer_type == "legacy_rel_pos":
          assert attention_layer_type == "legacy_rel_selfattn"
          pos_enc_class = LegacyRelPositionalEncoding
          logging.warning(
              "Using legacy_rel_pos and it will be deprecated in the future."
          )
      else:
          raise ValueError(
              "unknown pos_enc_layer: " + pos_enc_layer_type
          )
  
      if input_layer == "linear":
          self.embed = torch.nn.Sequential(
              torch.nn.Linear(input_size, output_size),
              torch.nn.LayerNorm(output_size),
              torch.nn.Dropout(dropout_rate),
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv1d1":
          self.embed = Conv1dSubsampling1(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv1d2":
          self.embed = Conv1dSubsampling2(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv1d3":
          self.embed = Conv1dSubsampling3(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv2d":
          self.embed = Conv2dSubsampling(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv2d1":
          self.embed = Conv2dSubsampling1(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv2d2":
          self.embed = Conv2dSubsampling2(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv2d6":
          self.embed = Conv2dSubsampling6(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "conv2d8":
          self.embed = Conv2dSubsampling8(
              input_size,
              output_size,
              dropout_rate,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer == "embed":
          self.embed = torch.nn.Sequential(
              torch.nn.Embedding(
                  input_size, output_size, padding_idx=padding_idx
              ),
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif isinstance(input_layer, torch.nn.Module):
          self.embed = torch.nn.Sequential(
              input_layer,
              pos_enc_class(
                  output_size, positional_dropout_rate, max_pos_emb_len
              ),
          )
      elif input_layer is None:
          if input_size == output_size:
              self.embed = torch.nn.Sequential(
                  pos_enc_class(
                      output_size,
                      positional_dropout_rate,
                      max_pos_emb_len,
                  )
              )
          else:
              self.embed = torch.nn.Linear(input_size, output_size)
      else:
          raise ValueError("unknown input_layer: " + input_layer)
  
      activation = get_activation(ffn_activation_type)
      if positionwise_layer_type == "linear":
          positionwise_layer = PositionwiseFeedForward
          positionwise_layer_args = (
              output_size,
              linear_units,
              dropout_rate,
              activation,
          )
      elif positionwise_layer_type is None:
          logging.warning("no macaron ffn")
      else:
          raise ValueError("Support only linear.")
  
      if attention_layer_type == "selfattn":
          encoder_selfattn_layer = MultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
          )
      elif attention_layer_type == "legacy_rel_selfattn":
          assert pos_enc_layer_type == "legacy_rel_pos"
          encoder_selfattn_layer = LegacyRelPositionMultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
          )
          logging.warning(
              "Using legacy_rel_selfattn and it will be deprecated in the future."
          )
      elif attention_layer_type == "rel_selfattn":
          assert pos_enc_layer_type == "rel_pos"
          encoder_selfattn_layer = RelPositionMultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
              zero_triu,
          )
      elif attention_layer_type == "fast_selfattn":
          assert pos_enc_layer_type in ["abs_pos", "scaled_abs_pos"]
          encoder_selfattn_layer = FastSelfAttention
          encoder_selfattn_layer_args = (
              output_size,
              attention_heads,
              attention_dropout_rate,
          )
      else:
          raise ValueError(
              "unknown encoder_attn_layer: " + attention_layer_type
          )
  
      cgmlp_layer = ConvolutionalGatingMLP
      cgmlp_layer_args = (
          output_size,
          cgmlp_linear_units,
          cgmlp_conv_kernel,
          dropout_rate,
          use_linear_after_conv,
          gate_activation,
      )
  
      self.encoders = repeat(
          num_blocks,
          lambda lnum: EBranchformerEncoderLayer(
              output_size,
              encoder_selfattn_layer(*encoder_selfattn_layer_args),
              cgmlp_layer(*cgmlp_layer_args),
              positionwise_layer(*positionwise_layer_args)
              if use_ffn
              else None,
              positionwise_layer(*positionwise_layer_args)
              if use_ffn and macaron_ffn
              else None,
              dropout_rate,
              merge_conv_kernel,
          ),
          layer_drop_rate,
      )
      self.after_norm = LayerNorm(output_size)
  
      if interctc_layer_idx is None:
          interctc_layer_idx = []
      self.interctc_layer_idx = interctc_layer_idx
      if len(interctc_layer_idx) > 0:
          assert (
              0 < min(interctc_layer_idx)
              and max(interctc_layer_idx) < num_blocks
          )
      self.interctc_use_conditioning = interctc_use_conditioning
      self.conditioning_layer = None
  
imports: import logging
  from typing import List, Optional, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.ctc import CTC
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.layers.cgmlp import ConvolutionalGatingMLP
  from espnet2.asr.layers.fastformer import FastSelfAttention
  from espnet.nets.pytorch_backend.nets_utils import get_activation, make_pad_mask
  from espnet.nets.pytorch_backend.transformer.attention import LegacyRelPositionMultiHeadedAttention, MultiHeadedAttention, RelPositionMultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.embedding import LegacyRelPositionalEncoding, PositionalEncoding, RelPositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
  from espnet.nets.pytorch_backend.transformer.positionwise_feed_forward import PositionwiseFeedForward
  from espnet.nets.pytorch_backend.transformer.repeat import repeat
  from espnet.nets.pytorch_backend.transformer.subsampling import Conv1dSubsampling1, Conv1dSubsampling2, Conv1dSubsampling3, Conv2dSubsampling, Conv2dSubsampling1, Conv2dSubsampling2, Conv2dSubsampling6, Conv2dSubsampling8, TooShortUttError, check_short_utt
label_desc: Use image node_id 1 to create a new EBranchformerEncoder object from inherited base classes: AbsEncoder with example: obj = EBranchformerEncoder(input_size, output_size, attention_heads, attention_layer_type, pos_enc_layer_type, rel_pos_type, cgmlp_linear_units, cgmlp_conv_kernel, use_linear_after_conv, gate_activation, num_blocks, dropout_rate, positional_dropout_rate, attention_dropout_rate, input_layer, zero_triu, padding_idx, layer_drop_rate, max_pos_emb_len, use_ffn, macaron_ffn, ffn_activation_type, linear_units, positionwise_layer_type, merge_conv_kernel, interctc_layer_idx, interctc_use_conditioning)