class_docstr: This is an implementation of Branchformer encoder layer.
  
  Arguments
  ----------
  d_model : int
      The expected size of the input embedding.
  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 Conformer 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_embs = torch.rand((1, 2*60-1, 512))
  >>> net = BranchformerEncoderLayer(nhead=8, d_model=512, kernel_size=3)
  >>> output = net(x, pos_embs=pos_embs)
  >>> output[0].shape
  torch.Size([8, 60, 512])
class_docstr_tok: ["This","is","an","implementation","of","Branchformer","encoder","layer",".","Arguments","--","--","--","--","--","d_model",":","int","The","expected","size","of","the","input","embedding",".","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","Conformer","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_embs","=","torch.rand","(","(","1",",","2","*","60-1",",","512",")",")",">",">",">","net","=","BranchformerEncoderLayer","(","nhead=8",",","d_model=512",",","kernel_size=3",")",">",">",">","output","=","net","(","x",",","pos_embs=pos_embs",")",">",">",">","output","[","0","]",".shape","torch.Size","(","[","8",",","60",",","512","]",")"]
docstr: Arguments
  ----------
  x : 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, optional
      Module or tensor containing the input sequence positional embeddings
docstr_tok: ["Arguments","--","--","--","--","--","x",":","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",",","optional","Module","or","tensor","containing","the","input","sequence","positional","embeddings"]
code: def forward(
      self,
      x,
      src_mask: Optional[torch.Tensor] = None,
      src_key_padding_mask: Optional[torch.Tensor] = None,
      pos_embs: Optional[torch.Tensor] = None,
  ):
      """
      Arguments
      ----------
      x : 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, optional
          Module or tensor containing the input sequence positional embeddings
      """
  
      # Two branches!
      x1 = x
      x2 = x
  
      # Branch 1: Self-attention
      x1 = self.norm_mhsa(x1)
      x1, self_attn = self.mha_layer(
          x1,
          x1,
          x1,
          attn_mask=src_mask,
          key_padding_mask=src_key_padding_mask,
          pos_embs=pos_embs,
      )
      x1 = self.dropout(x1)
  
      # Branch 2: Convolutional gating MLP
      # In ESPnet, masks are not used?! we do the same but warning!
      x2 = self.norm_conv(x2)
      x2 = self.convolution_branch(x2)
      x2 = self.dropout(x2)
  
      # Merge both branches, we only do concatenation as it performs better.
      # According to the original Branchformer paper.
      x = x + self.dropout(self.merge_proj(torch.cat([x1, x2], dim=-1)))
  
      return x, self_attn
  
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 BranchformerEncoderLayer obj's underlying member method code with example usage: obj.forward(x, src_mask, src_key_padding_mask, pos_embs) and returns: x,  self_attn