code: def _get_wavlm_encoder(
      in_features: int,
      embed_dim: int,
      dropout_input: float,
      pos_conv_kernel: int,
      pos_conv_groups: int,
      num_layers: int,
      num_heads: int,
      num_buckets: int,
      max_distance: int,
      attention_dropout: float,
      ff_interm_features: int,
      ff_interm_dropout: float,
      dropout: float,
      layer_norm_first: bool,
      layer_drop: float,
  ) -> Encoder:
      """
      Construct encoder for WavLM model :cite:`chen2022wavlm`. The structure of the encoder and most of the argments are
      the same as in :py:func:`_get_encoder` so refer there for documentation. The only difference from Wav2Vec2 encoder
      is usage of `WavLMSelfAttention` instead of `SelfAttention` and two additional parameters: `num_buckets` and
      `max_distance`.
      Args:
          in_features (int): See :py:func:`_get_encoder`.
          embed_dim (int): See :py:func:`_get_encoder`.
          dropout_input (float): See :py:func:`_get_encoder`.
          pos_conv_kernel (int): See :py:func:`_get_encoder`.
          pos_conv_groups (int): See :py:func:`_get_encoder`.
          num_layers (int): See :py:func:`_get_encoder`.
          num_heads (int): See :py:func:`_get_encoder`.
          num_buckets (int): Number of buckets for relative position embedding.
          max_distance (int): Maximum distance for relative position embedding.
          attention_dropout (float): See :py:func:`_get_encoder`.
          ff_interm_features (int): See :py:func:`_get_encoder`.
          ff_interm_dropout (float): See :py:func:`_get_encoder`.
          dropout (float): See :py:func:`_get_encoder`.
          layer_norm_first (bool): See :py:func:`_get_encoder`.
          layer_drop (float): See :py:func:`_get_encoder`.
  
      """
      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 i in range(num_layers):
          attention = WavLMSelfAttention(
              embed_dim=embed_dim,
              num_heads=num_heads,
              num_buckets=num_buckets,
              max_distance=max_distance,
              dropout=attention_dropout,
              has_relative_attention_bias=(
                  i == 0
              ),  # Position embedding is only necessary in the first layer.
          )
          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 4 for calling a global function with example usage: _get_wavlm_encoder(in_features, embed_dim, dropout_input, pos_conv_kernel, pos_conv_groups, num_layers, num_heads, num_buckets, max_distance, attention_dropout, ff_interm_features, ff_interm_dropout, dropout, layer_norm_first, layer_drop) and returns: Encoder