class_docstr: Represents a Conformer block as described in
  :cite:t:`https://doi.org/10.48550/arxiv.2005.08100`.
docstr: :param ffn1:
      The bottom macaron-like feed-forward network.
  :param self_attn:
      The self attention layer.
  :param conv:
      The Conformer convolution module.
  :param ffn2:
      The top macaron-like feed-forward network.
  :param dropout_p:
      The dropout probability on outputs of the self attention layer, the
      feed-forward networks, and the Conformer convolution module.
  :param layer_norm_factory:
      The factory to construct the Layer Normalization modules.
docstr_tok: [":","param","ffn1",":","The","bottom","macaron-like","feed-forward","network",".",":","param","self_attn",":","The","self","attention","layer",".",":","param","conv",":","The","Conformer","convolution","module",".",":","param","ffn2",":","The","top","macaron-like","feed-forward","network",".",":","param","dropout_p",":","The","dropout","probability","on","outputs","of","the","self","attention","layer",",","the","feed-forward","networks",",","and","the","Conformer","convolution","module",".",":","param","layer_norm_factory",":","The","factory","to","construct","the","Layer","Normalization","modules","."]
code: def __init__(
      self,
      ffn1: FeedForwardNetwork,
      self_attn: MultiheadAttention,
      conv: ConformerConvolution,
      ffn2: FeedForwardNetwork,
      *,
      dropout_p: float = 0.1,
      layer_norm_factory: Optional[LayerNormFactory] = None,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
  ) -> None:
      """
      :param ffn1:
          The bottom macaron-like feed-forward network.
      :param self_attn:
          The self attention layer.
      :param conv:
          The Conformer convolution module.
      :param ffn2:
          The top macaron-like feed-forward network.
      :param dropout_p:
          The dropout probability on outputs of the self attention layer, the
          feed-forward networks, and the Conformer convolution module.
      :param layer_norm_factory:
          The factory to construct the Layer Normalization modules.
      """
      model_dim = self_attn.model_dim
  
      super().__init__(model_dim)
  
      if layer_norm_factory is None:
          layer_norm_factory = create_standard_layer_norm
  
      self.ffn1_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      self.ffn1 = ffn1
  
      if dropout_p > 0.0:
          self.ffn1_dropout = Dropout(dropout_p)
      else:
          self.register_module("ffn1_dropout", None)
  
      self.self_attn_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      self.self_attn = self_attn
  
      if dropout_p > 0.0:
          self.self_attn_dropout = Dropout(dropout_p)
      else:
          self.register_module("self_attn_dropout", None)
  
      self.conv_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      self.conv = conv
  
      if dropout_p > 0.0:
          self.conv_dropout = Dropout(dropout_p)
      else:
          self.register_module("conv_dropout", None)
  
      self.ffn2_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      self.ffn2 = ffn2
  
      if dropout_p > 0.0:
          self.ffn2_dropout = Dropout(dropout_p)
      else:
          self.register_module("ffn2_dropout", None)
  
      self.layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
file_path: fairseq2/src/fairseq2/models/conformer/block.py
imports: from typing import Optional, Tuple
  from torch import Tensor
  from torch.nn import Dropout
  from fairseq2.models.conformer.convolution import ConformerConvolution
  from fairseq2.nn.normalization import LayerNorm
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.nn.transformer import AttentionMask, FeedForwardNetwork, LayerNormFactory, MultiheadAttention, TransformerEncoderLayer, create_standard_layer_norm
  from fairseq2.typing import DataType, Device, finaloverride
label_desc: Use image node_id 1 to create a new ConformerBlock object from inherited base classes: TransformerEncoderLayer with example: obj = ConformerBlock(ffn1, _attn, conv, ffn2)