code: def _get_encoder(
      in_features: int,
      embed_dim: int,
      dropout_input: float,
      pos_conv_kernel: int,
      pos_conv_groups: int,
      num_layers: int,
      num_heads: int,
      attention_dropout: float,
      ff_interm_features: int,
      ff_interm_dropout: float,
      dropout: float,
      layer_norm_first: bool,
      layer_drop: float,
  ) -> Encoder:
      """
      Args:
          in_features (int): The number of input features.
          embed_dim (int):
              The dimension of embedding.
              This option corresponds to "encoder_embed_dim" from fairseq.
              Expected values are 768 for Base arch, and 1024 for Large arch.
          dropout_input (float):
              The dropout probability applied after the input feature is projected
              to ``embed_dim``.
              This option corresponds to "dropout_input" from fairseq.
              Expected values are 0.1 for both Base and Large arch.
          pos_conv_kernel (int):
              The kernel size of convolutional positional embeddings.
              This option corresponds to "conv_pos" from fairseq.
              Expected values are 128 for both Base and Large arch.
          pos_conv_groups (int):
              The number of groups of convolutional positional embeddings.
              This option corresponds to "conv_pos_groups" from fairseq.
              Expected values are 16 for both Base and Large arch.
          num_layers (int):
              The number of self attention layers in transformer block.
              This option corresponds to "encoder_layers" from fairseq.
              Expected values are 12 for Base and 24 for Large arch.
          num_heads (int):
              The number of heads in self attention layers.
              This option corresponds to "encoder_attention_heads" from fairseq.
              Expected values are 12 for Base and 16 for Large arch.
          attention_dropout (float):
              The dropout probability applied after softmax in self-attention layer.
              This option corresponds to "attention_dropout" from fairseq.
              Expected values are 0.1 for Base and 0.0 for Large arch.
          ff_interm_features (int):
              The dimension of hidden features in feed forward layer.
              This option corresponds to "encoder_ffn_embed_dim" from fairseq.
              Expected values are 3072 for Base and 4096 for Large arch.
          ff_interm_dropout (float):
              The dropout probability applied in feedforward layer.
              This option correspinds to "activation_dropout" from fairseq.
              Expected values are 0.1 for both Base and Large arch.
          dropout (float):
              The dropout probability applied at the end of feed forward layer.
              This option corresponds to "dropout" from fairseq.
              Expected values are 0.1 for Base and 0.0 for Large arch.
          layer_norm_first (bool):
              Control the order of layer norm in transformer layer and each encoder layer.
              If True, in transformer layer, layer norm is applied before features are fed
              to encoder layers. In encoder layer, two layer norms are applied before and after
              self attention.
              If False, in transformer layer, layer norm is applied after features are fed
              to encoder layers. In encoder layer, two layer norms are applied after self
              attention, before and after feed forward.
              This option corresponds to "layer_norm_first" from fairseq.
              Expected values are False for Base and True for Large arch.
          layer_drop (float):
              Probability to drop each encoder layer during training.
              This option corresponds to "layerdrop" from fairseq.
              Expected values are 0.1 for both Base and Large arch.
  
      See Also:
          * "encoder_embed_dim"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L49-L51
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L64
          * "dropout_input"
            - Def, base and large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L75-L78
          * "conv_pos"
            - Def, base and large
              NOTE: The description is wrong.
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L204-L207
            - Usage
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L756
          * "conv_pos_groups"
            - Def, base and large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L208-L211
          * "encoder_layers"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L46-L48
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L63
          * "encoder_attention_heads"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L55-L57
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L66
          * "attention_dropout"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L66-L68
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L60
          * "encoder_ffn_embed_dim"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L52-L54
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L65
          * "activation_dropout"
            - Def
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L69-L71
            - Base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/finetuning/base_960h.yaml#L55
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/finetuning/vox_960h.yaml#L55
          * "dropout"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L63-L65
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L59
          * "layer_norm_first"
            - Def and base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L91-L93
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/pretraining/wav2vec2_large_librivox.yaml#L53
          * "layerdrop"
            - Def
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L72-L74
            - Base
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/finetuning/base_960h.yaml#L54
            - Large
              https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/examples/wav2vec/config/finetuning/vox_960h.yaml#L54
      """
      feature_projection = FeatureProjection(
          in_features, embed_dim, dropout_input
      )
      pos_conv = ConvolutionalPositionalEmbedding(
          embed_dim, pos_conv_kernel, pos_conv_groups
      )
  
      # Original impl
      # https://github.com/pytorch/fairseq/blob/425c36eafff535fe7337f8bdd5ace22ebacc78cb/fairseq/models/wav2vec/wav2vec2.py#L768-L782
      encoder_layers = nn.ModuleList()
      for _ in range(num_layers):
          attention = SelfAttention(
              embed_dim=embed_dim,
              num_heads=num_heads,
              dropout=attention_dropout,
          )
          feed_forward = FeedForward(
              io_features=embed_dim,
              intermediate_features=ff_interm_features,
              intermediate_dropout=ff_interm_dropout,
              output_dropout=dropout,
          )
          encoder_layers.append(
              EncoderLayer(
                  attention=attention,
                  dropout=dropout,
                  layer_norm_first=layer_norm_first,
                  feed_forward=feed_forward,
              )
          )
      transformer = Transformer(
          pos_conv_embed=pos_conv,
          dropout=dropout,
          layers=encoder_layers,
          layer_norm_first=not layer_norm_first,
          layer_drop=layer_drop,
      )
      return Encoder(feature_projection, transformer)
  
imports: import logging
  from typing import List, Optional, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import Module, Parameter
  from .wavlm_attention import WavLMSelfAttention
label_desc: Use image node_id 3 for calling a global function with example usage: _get_encoder(in_features, embed_dim, dropout_input, pos_conv_kernel, pos_conv_groups, num_layers, num_heads, attention_dropout, ff_interm_features, ff_interm_dropout, dropout, layer_norm_first, layer_drop) and returns: Encoder