class_docstr: A layer unit in encoder. Combines multihead self attention and feed forward.
class_docstr_tok: ["A","layer","unit","in","encoder",".","Combines","multihead","self","attention","and","feed","forward","."]
docstr: Args:
      x (Tensor): Input of shape ``(batch, sequence_length, embed_dim)``.
      attention_mask (Tensor or ``None``, optional): attention mask
          of shape ``(batch, 1, sequence_length, sequence_length)``. (Default: ``None``)
      position_bias (Tensor or ``None``, optional): position bias of shape
          ``(batch_size * num_heads, src_len, src_len)``.
          Only necessary for WavLM model, ``None`` otherwise. (Default: ``None``)
      key_padding_mask (Tensor or ``None``, optional): key padding mask of shape ``(batch_size, src_len)``.
          Only used for WavLM model, ignored otherwise. (Default: ``None``)
  Returns:
      (x, position_bias): Shapes are the same as in the input. Position bias is only relevant for WaLM model,
          ``None`` otherwise.
docstr_tok: ["Args",":","x","(","Tensor",")",":","Input","of","shape","``","(","batch",",","sequence_length",",","embed_dim",")","``",".","attention_mask","(","Tensor","or","``","None","``",",","optional",")",":","attention","mask","of","shape","``","(","batch",",","1",",","sequence_length",",","sequence_length",")","``",".","(","Default",":","``","None","``",")","position_bias","(","Tensor","or","``","None","``",",","optional",")",":","position","bias","of","shape","``","(","batch_size","*","num_heads",",","src_len",",","src_len",")","``",".","Only","necessary","for","WavLM","model",",","``","None","``","otherwise",".","(","Default",":","``","None","``",")","key_padding_mask","(","Tensor","or","``","None","``",",","optional",")",":","key","padding","mask","of","shape","``","(","batch_size",",","src_len",")","``",".","Only","used","for","WavLM","model",",","ignored","otherwise",".","(","Default",":","``","None","``",")","Returns",":","(","x",",","position_bias",")",":","Shapes","are","the","same","as","in","the","input",".","Position","bias","is","only","relevant","for","WaLM","model",",","``","None","``","otherwise","."]
code: def forward(
      self,
      x: Tensor,
      attention_mask: Optional[Tensor] = None,
      position_bias: Optional[Tensor] = None,
      key_padding_mask: Optional[Tensor] = None,
  ) -> Tuple[Tensor, Optional[Tensor]]:
      """
      Args:
          x (Tensor): Input of shape ``(batch, sequence_length, embed_dim)``.
          attention_mask (Tensor or ``None``, optional): attention mask
              of shape ``(batch, 1, sequence_length, sequence_length)``. (Default: ``None``)
          position_bias (Tensor or ``None``, optional): position bias of shape
              ``(batch_size * num_heads, src_len, src_len)``.
              Only necessary for WavLM model, ``None`` otherwise. (Default: ``None``)
          key_padding_mask (Tensor or ``None``, optional): key padding mask of shape ``(batch_size, src_len)``.
              Only used for WavLM model, ignored otherwise. (Default: ``None``)
      Returns:
          (x, position_bias): Shapes are the same as in the input. Position bias is only relevant for WaLM model,
              ``None`` otherwise.
      """
      residual = x
  
      if self.layer_norm_first:
          x = self.layer_norm(x)
  
      x, position_bias = self.attention(
          x,
          attention_mask=attention_mask,
          position_bias=position_bias,
          key_padding_mask=key_padding_mask,
      )
  
      x = self.dropout(x)
      x = residual + x
  
      if self.layer_norm_first:
          x = x + self.feed_forward(self.final_layer_norm(x))
      else:
          x = self.layer_norm(x)
          x = self.final_layer_norm(x + self.feed_forward(x))
      return x, position_bias
  
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 2 for calling the EncoderLayer obj's underlying member method code with example usage: obj.forward(x, attention_mask, position_bias, key_padding_mask) and returns: x,  position_bias