docstr: Args:
      hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
      attention_mask (`torch.FloatTensor`): attention mask of size
          `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
      layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
          `(encoder_attention_heads,)`.
      output_attentions (`bool`, *optional*):
          Whether or not to return the attentions tensors of all attention layers. See `attentions` under
          returned tensors for more detail.
docstr_tok: ["Args",":","hidden_states","(","`","torch.FloatTensor","`",")",":","input","to","the","layer","of","shape","`","(","seq_len",",","batch",",","embed_dim",")","`","attention_mask","(","`","torch.FloatTensor","`",")",":","attention","mask","of","size","`","(","batch",",","1",",","tgt_len",",","src_len",")","`","where","padding","elements","are","indicated","by","very","large","negative","values",".","layer_head_mask","(","`","torch.FloatTensor","`",")",":","mask","for","attention","heads","in","a","given","layer","of","size","`","(","encoder_attention_heads",",",")","`",".","output_attentions","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","attentions","tensors","of","all","attention","layers",".","See","`","attentions","`","under","returned","tensors","for","more","detail","."]
code: def forward(
      self,
      hidden_states: torch.FloatTensor,
      attention_mask: torch.FloatTensor,
      layer_head_mask: torch.FloatTensor,
      output_attentions: Optional[bool] = False,
  ) -> Tuple[torch.FloatTensor, Optional[torch.FloatTensor]]:
      """
      Args:
          hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
          attention_mask (`torch.FloatTensor`): attention mask of size
              `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
          layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
              `(encoder_attention_heads,)`.
          output_attentions (`bool`, *optional*):
              Whether or not to return the attentions tensors of all attention layers. See `attentions` under
              returned tensors for more detail.
      """
      residual = hidden_states
      hidden_states = self.self_attn_layer_norm(hidden_states)
      hidden_states, attn_weights, _ = self.self_attn(
          hidden_states=hidden_states,
          attention_mask=attention_mask,
          layer_head_mask=layer_head_mask,
          output_attentions=output_attentions,
      )
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
      hidden_states = residual + hidden_states
  
      residual = hidden_states
      hidden_states = self.final_layer_norm(hidden_states)
      hidden_states = self.activation_fn(self.fc1(hidden_states))
      hidden_states = nn.functional.dropout(
          hidden_states,
          p=self.activation_dropout,
          training=self.training,
      )
      hidden_states = self.fc2(hidden_states)
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
      hidden_states = residual + hidden_states
  
      if hidden_states.dtype == torch.float16 and (
          torch.isinf(hidden_states).any()
          or torch.isnan(hidden_states).any()
      ):
          clamp_value = torch.finfo(hidden_states.dtype).max - 1000
          hidden_states = torch.clamp(
              hidden_states, min=-clamp_value, max=clamp_value
          )
  
      outputs = (hidden_states,)
  
      if output_attentions:
          outputs += (attn_weights,)
  
      return outputs
  
imports: import inspect
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.utils.checkpoint
  from transformers import PretrainedConfig, PreTrainedModel, PreTrainedTokenizer
  from transformers.activations import ACT2FN
  from transformers.modeling_outputs import BaseModelOutput
  from transformers.utils import logging
  from ...models import AutoencoderKL, UNet2DConditionModel, UNet2DModel, VQModel
  from ...schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
label_desc: Use image node_id 2 for calling the LDMBertEncoderLayer obj's underlying member method code with example usage: obj.forward(hidden_states, attention_mask, layer_head_mask, output_attentions) and returns: outputs