class_docstr: Represents a Conformer convolution module as described in
  :cite:t:`https://doi.org/10.48550/arxiv.2005.08100`.
class_docstr_tok: ["Represents","a","Conformer","convolution","module","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.2005.08100","`","."]
docstr: :param model_dim:
      The dimensionality of the model.
  :param depthwise_kernel_size:
      The kernel size of the depthwise convolution.
  :param causal_depthwise_conv:
      If ``True``, uses a causal depthwise convolution similar to that
      described in Section 2.1 of :cite:t:`https://doi.org/10.48550/arxiv.1609.03499`.
  :param norm_type:
      The type of normalization to apply after the depthwise convolution.
  :param depthwise_activation:
      The activation to apply to outputs of the depthwise convolution. If
      ``None``, :func:`~torch.nn.SiLU` (a.k.a. swish) will be used.
docstr_tok: [":","param","model_dim",":","The","dimensionality","of","the","model",".",":","param","depthwise_kernel_size",":","The","kernel","size","of","the","depthwise","convolution",".",":","param","causal_depthwise_conv",":","If","``","True","``",",","uses","a","causal","depthwise","convolution","similar","to","that","described","in","Section","2.1","of",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.1609.03499","`",".",":","param","norm_type",":","The","type","of","normalization","to","apply","after","the","depthwise","convolution",".",":","param","depthwise_activation",":","The","activation","to","apply","to","outputs","of","the","depthwise","convolution",".","If","``","None","``",",",":","func",":","`","~torch.nn.SiLU","`","(","a.k.a",".","swish",")","will","be","used","."]
code: def __init__(
      self,
      model_dim: int,
      depthwise_kernel_size: int,
      *,
      causal_depthwise_conv: bool = False,
      norm_type: Literal["batch_norm", "layer_norm"] = "batch_norm",
      depthwise_activation: Optional[Module] = None,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
  ) -> None:
      """
      :param model_dim:
          The dimensionality of the model.
      :param depthwise_kernel_size:
          The kernel size of the depthwise convolution.
      :param causal_depthwise_conv:
          If ``True``, uses a causal depthwise convolution similar to that
          described in Section 2.1 of :cite:t:`https://doi.org/10.48550/arxiv.1609.03499`.
      :param norm_type:
          The type of normalization to apply after the depthwise convolution.
      :param depthwise_activation:
          The activation to apply to outputs of the depthwise convolution. If
          ``None``, :func:`~torch.nn.SiLU` (a.k.a. swish) will be used.
      """
      super().__init__()
  
      self.model_dim = model_dim
  
      # We treat the dimensionality of the model as the number of input
      # channels to the first pointwise convolution.
      self.pointwise_conv1 = Conv1d(
          model_dim,
          # We apply GLU to outputs to bring them back to `model_dim`.
          model_dim * 2,
          kernel_size=1,
          bias=False,
          device=device,
          dtype=dtype,
      )
  
      self.pointwise_conv1_activation = GLU(dim=1)
  
      self.depthwise_conv = Conv1d(
          model_dim,
          model_dim,
          depthwise_kernel_size,
          padding="same" if not causal_depthwise_conv else 0,
          # We want to perform depthwise convolution.
          groups=model_dim,
          bias=False,
          device=device,
          dtype=dtype,
      )
  
      self.causal_depthwise_conv = causal_depthwise_conv
  
      if norm_type not in ("batch_norm", "layer_norm"):
          raise ValueError(
              f"`norm_type` must be 'batch_norm' or 'layer_norm', but is '{norm_type}' instead."
          )
  
      if norm_type == "batch_norm":
          self.batch_norm = BatchNorm1d(
              model_dim, device=device, dtype=dtype
          )
      else:
          self.register_module("batch_norm", None)
  
      if norm_type == "layer_norm":
          self.layer_norm = StandardLayerNorm(
              model_dim, bias=True, device=device, dtype=dtype
          )
      else:
          self.register_module("layer_norm", None)
  
      if depthwise_activation is None:
          self.depthwise_activation = SiLU()  # a.k.a. swish
      else:
          self.depthwise_activation = depthwise_activation
  
      self.pointwise_conv2 = Conv1d(
          model_dim,
          model_dim,
          kernel_size=1,
          bias=False,
          device=device,
          dtype=dtype,
      )
  
file_path: fairseq2/src/fairseq2/models/conformer/convolution.py
imports: from typing import Literal, Optional
  from torch import Tensor
  from torch.nn import GLU, BatchNorm1d, Conv1d, Module, SiLU
  from torch.nn.functional import pad
  from fairseq2.nn.normalization import LayerNorm, StandardLayerNorm
  from fairseq2.nn.padding import PaddingMask, apply_padding_mask
  from fairseq2.typing import DataType, Device
label_desc: Use image node_id 1 to create a new ConformerConvolution object from inherited base classes: Module with example: obj = ConformerConvolution(model_dim, depthwise_kernel_size)