class_docstr: This class implements the Branchformer encoder.
  
  Arguments
  ---------
  num_layers : int
      Number of layers.
  d_model : int
      Embedding dimension size.
  nhead : int
      Number of attention heads.
  kernel_size : int, optional
      Kernel size of convolution model.
  kdim : int, optional
      Dimension of the key.
  vdim : int, optional
      Dimension of the value.
  activation: torch.nn.Module
       Activation function used in each Confomer layer.
  dropout : int, optional
      Dropout for the encoder.
  attention_type: str, optional
      type of attention layer, e.g. regulaMHA for regular MultiHeadAttention.
  csgu_linear_units: int, optional
      Number of neurons in the hidden linear units of the CSGU Module.
  gate_activation: torch.nn.Module, optional
       Activation function used at the gate of the CSGU module.
  use_linear_after_conv: bool, optional
      If True, will apply a linear transformation of size input_size//2.
  
  
  Example
  -------
  >>> import torch
  >>> x = torch.rand((8, 60, 512))
  >>> pos_emb = torch.rand((1, 2*60-1, 512))
  >>> net = BranchformerEncoder(1, 512, 8)
  >>> output, _ = net(x, pos_embs=pos_emb)
  >>> output.shape
  torch.Size([8, 60, 512])
class_docstr_tok: ["This","class","implements","the","Branchformer","encoder",".","Arguments","--","--","--","--","-","num_layers",":","int","Number","of","layers",".","d_model",":","int","Embedding","dimension","size",".","nhead",":","int","Number","of","attention","heads",".","kernel_size",":","int",",","optional","Kernel","size","of","convolution","model",".","kdim",":","int",",","optional","Dimension","of","the","key",".","vdim",":","int",",","optional","Dimension","of","the","value",".","activation",":","torch.nn.Module","Activation","function","used","in","each","Confomer","layer",".","dropout",":","int",",","optional","Dropout","for","the","encoder",".","attention_type",":","str",",","optional","type","of","attention","layer",",","e.g",".","regulaMHA","for","regular","MultiHeadAttention",".","csgu_linear_units",":","int",",","optional","Number","of","neurons","in","the","hidden","linear","units","of","the","CSGU","Module",".","gate_activation",":","torch.nn.Module",",","optional","Activation","function","used","at","the","gate","of","the","CSGU","module",".","use_linear_after_conv",":","bool",",","optional","If","True",",","will","apply","a","linear","transformation","of","size","input_size\/\/2",".","Example","--","--","--","-",">",">",">","import","torch",">",">",">","x","=","torch.rand","(","(","8",",","60",",","512",")",")",">",">",">","pos_emb","=","torch.rand","(","(","1",",","2","*","60-1",",","512",")",")",">",">",">","net","=","BranchformerEncoder","(","1",",","512",",","8",")",">",">",">","output",",","_","=","net","(","x",",","pos_embs=pos_emb",")",">",">",">","output.shape","torch.Size","(","[","8",",","60",",","512","]",")"]
docstr: Arguments
  ----------
  src : torch.Tensor
      The sequence to the encoder layer.
  src_mask : torch.Tensor, optional
      The mask for the src sequence.
  src_key_padding_mask : torch.Tensor, optional
      The mask for the src keys per batch.
  pos_embs: torch.Tensor, torch.nn.Module,
      Module or tensor containing the input sequence positional embeddings
      If custom pos_embs are given it needs to have the shape (1, 2*S-1, E)
      where S is the sequence length, and E is the embedding dimension.
docstr_tok: ["Arguments","--","--","--","--","--","src",":","torch.Tensor","The","sequence","to","the","encoder","layer",".","src_mask",":","torch.Tensor",",","optional","The","mask","for","the","src","sequence",".","src_key_padding_mask",":","torch.Tensor",",","optional","The","mask","for","the","src","keys","per","batch",".","pos_embs",":","torch.Tensor",",","torch.nn.Module",",","Module","or","tensor","containing","the","input","sequence","positional","embeddings","If","custom","pos_embs","are","given","it","needs","to","have","the","shape","(","1",",","2","*","S-1",",","E",")","where","S","is","the","sequence","length",",","and","E","is","the","embedding","dimension","."]
code: def forward(
      self,
      src,
      src_mask: Optional[torch.Tensor] = None,
      src_key_padding_mask: Optional[torch.Tensor] = None,
      pos_embs: Optional[torch.Tensor] = None,
      dynchunktrain_config=None,
  ):
      """
      Arguments
      ----------
      src : torch.Tensor
          The sequence to the encoder layer.
      src_mask : torch.Tensor, optional
          The mask for the src sequence.
      src_key_padding_mask : torch.Tensor, optional
          The mask for the src keys per batch.
      pos_embs: torch.Tensor, torch.nn.Module,
          Module or tensor containing the input sequence positional embeddings
          If custom pos_embs are given it needs to have the shape (1, 2*S-1, E)
          where S is the sequence length, and E is the embedding dimension.
      """
      assert (
          dynchunktrain_config is None
      ), "Dynamic Chunk Training unsupported for this encoder"
  
      if self.attention_type == "RelPosMHAXL":
          if pos_embs is None:
              raise ValueError(
                  "The chosen attention type for the Branchformer is RelPosMHAXL. For this attention type, the positional embeddings are mandatory"
              )
  
      output = src
      attention_lst = []
      for enc_layer in self.layers:
          output, attention = enc_layer(
              output,
              src_mask=src_mask,
              src_key_padding_mask=src_key_padding_mask,
              pos_embs=pos_embs,
          )
          attention_lst.append(attention)
      output = self.norm(output)
  
      return output, attention_lst
  
file_path: speechbrain/speechbrain/lobes/models/transformer/Branchformer.py
imports: import torch
  import torch.nn
  from typing import Optional
  from speechbrain.nnet.attention import RelPosMHAXL, MultiheadAttention
  from speechbrain.nnet.normalization import LayerNorm
  from speechbrain.lobes.models.convolution import ConvolutionalSpatialGatingUnit
  from speechbrain.lobes.models.transformer.hypermixing import HyperMixing
label_desc: Use image node_id 2 for calling the BranchformerEncoder obj's underlying member method code with example usage: obj.forward(src, src_mask, src_key_padding_mask, pos_embs, dynchunktrain_config) and returns: output,  attention_lst