class_docstr: E-Branchformer encoder module.
class_docstr_tok: ["E-Branchformer","encoder","module","."]
docstr: Calculate forward propagation.
  
  Args:
      xs_pad (torch.Tensor): Input tensor (#batch, L, input_size).
      ilens (torch.Tensor): Input length (#batch).
      prev_states (torch.Tensor): Not to be used now.
      ctc (CTC): Intermediate CTC module.
      max_layer (int): Layer depth below which InterCTC is applied.
  Returns:
      torch.Tensor: Output tensor (#batch, L, output_size).
      torch.Tensor: Output length (#batch).
      torch.Tensor: Not to be used now.
docstr_tok: ["Calculate","forward","propagation",".","Args",":","xs_pad","(","torch.Tensor",")",":","Input","tensor","(","#","batch",",","L",",","input_size",")",".","ilens","(","torch.Tensor",")",":","Input","length","(","#","batch",")",".","prev_states","(","torch.Tensor",")",":","Not","to","be","used","now",".","ctc","(","CTC",")",":","Intermediate","CTC","module",".","max_layer","(","int",")",":","Layer","depth","below","which","InterCTC","is","applied",".","Returns",":","torch.Tensor",":","Output","tensor","(","#","batch",",","L",",","output_size",")",".","torch.Tensor",":","Output","length","(","#","batch",")",".","torch.Tensor",":","Not","to","be","used","now","."]
code: def forward(
      self,
      xs_pad: torch.Tensor,
      ilens: torch.Tensor,
      prev_states: torch.Tensor = None,
      ctc: CTC = None,
      max_layer: int = None,
  ) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]:
      """Calculate forward propagation.
  
      Args:
          xs_pad (torch.Tensor): Input tensor (#batch, L, input_size).
          ilens (torch.Tensor): Input length (#batch).
          prev_states (torch.Tensor): Not to be used now.
          ctc (CTC): Intermediate CTC module.
          max_layer (int): Layer depth below which InterCTC is applied.
      Returns:
          torch.Tensor: Output tensor (#batch, L, output_size).
          torch.Tensor: Output length (#batch).
          torch.Tensor: Not to be used now.
      """
  
      masks = (~make_pad_mask(ilens)[:, None, :]).to(xs_pad.device)
  
      if (
          isinstance(self.embed, Conv2dSubsampling)
          or isinstance(self.embed, Conv1dSubsampling1)
          or isinstance(self.embed, Conv1dSubsampling2)
          or isinstance(self.embed, Conv1dSubsampling3)
          or isinstance(self.embed, Conv2dSubsampling1)
          or isinstance(self.embed, Conv2dSubsampling2)
          or isinstance(self.embed, Conv2dSubsampling6)
          or isinstance(self.embed, Conv2dSubsampling8)
      ):
          short_status, limit_size = check_short_utt(
              self.embed, xs_pad.size(1)
          )
          if short_status:
              raise TooShortUttError(
                  f"has {xs_pad.size(1)} frames and is too short for subsampling "
                  + f"(it needs more than {limit_size} frames), return empty results",
                  xs_pad.size(1),
                  limit_size,
              )
          xs_pad, masks = self.embed(xs_pad, masks)
      elif self.embed is not None:
          xs_pad = self.embed(xs_pad)
  
      intermediate_outs = []
      if len(self.interctc_layer_idx) == 0:
          if max_layer is not None and 0 <= max_layer < len(
              self.encoders
          ):
              for layer_idx, encoder_layer in enumerate(self.encoders):
                  xs_pad, masks = encoder_layer(xs_pad, masks)
                  if layer_idx >= max_layer:
                      break
          else:
              xs_pad, masks = self.encoders(xs_pad, masks)
      else:
          for layer_idx, encoder_layer in enumerate(self.encoders):
              xs_pad, masks = encoder_layer(xs_pad, masks)
  
              if layer_idx + 1 in self.interctc_layer_idx:
                  encoder_out = xs_pad
  
                  if isinstance(encoder_out, tuple):
                      encoder_out = encoder_out[0]
  
                  intermediate_outs.append((layer_idx + 1, encoder_out))
  
                  if self.interctc_use_conditioning:
                      ctc_out = ctc.softmax(encoder_out)
  
                      if isinstance(xs_pad, tuple):
                          xs_pad = list(xs_pad)
                          xs_pad[0] = xs_pad[
                              0
                          ] + self.conditioning_layer(ctc_out)
                          xs_pad = tuple(xs_pad)
                      else:
                          xs_pad = xs_pad + self.conditioning_layer(
                              ctc_out
                          )
  
      if isinstance(xs_pad, tuple):
          xs_pad = xs_pad[0]
  
      xs_pad = self.after_norm(xs_pad)
      olens = masks.squeeze(1).sum(1)
      if len(intermediate_outs) > 0:
          return (xs_pad, intermediate_outs), olens, None
      return xs_pad, olens, 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 3 for calling the EBranchformerEncoder obj's underlying member method code with example usage: obj.forward(xs_pad, ilens, prev_states, ctc, max_layer) and returns: xs_pad,  olens,  None, xs_pad,  intermediate_outs,  olens,  None