class_docstr: Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
  [`LDMBertEncoderLayer`].
  
  Args:
      config: LDMBertConfig
      embed_tokens (nn.Embedding): output embedding
class_docstr_tok: ["Transformer","encoder","consisting","of","*","config.encoder_layers","*","self","attention","layers",".","Each","layer","is","a","[","`","LDMBertEncoderLayer","`","]",".","Args",":","config",":","LDMBertConfig","embed_tokens","(","nn.Embedding",")",":","output","embedding"]
docstr: Args:
      input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
          Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
          provide it.
  
          Indices can be obtained using [`BartTokenizer`]. See [`PreTrainedTokenizer.encode`] and
          [`PreTrainedTokenizer.__call__`] for details.
  
          [What are input IDs?](../glossary#input-ids)
      attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
          Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
  
          - 1 for tokens that are **not masked**,
          - 0 for tokens that are **masked**.
  
          [What are attention masks?](../glossary#attention-mask)
      head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
          Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:
  
          - 1 indicates the head is **not masked**,
          - 0 indicates the head is **masked**.
  
      inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
          Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
          This is useful if you want more control over how to convert `input_ids` indices into associated vectors
          than the model's internal embedding lookup matrix.
      output_attentions (`bool`, *optional*):
          Whether or not to return the attentions tensors of all attention layers. See `attentions` under
          returned tensors for more detail.
      output_hidden_states (`bool`, *optional*):
          Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
          for more detail.
      return_dict (`bool`, *optional*):
          Whether or not to return a [`~utils.BaseModelOutput`] instead of a plain tuple.
docstr_tok: ["Args",":","input_ids","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",")",":","Indices","of","input","sequence","tokens","in","the","vocabulary",".","Padding","will","be","ignored","by","default","should","you","provide","it",".","Indices","can","be","obtained","using","[","`","BartTokenizer","`","]",".","See","[","`","PreTrainedTokenizer.encode","`","]","and","[","`","PreTrainedTokenizer.__call__","`","]","for","details",".","[","What","are","input","IDs","?","]","(","..","\/glossary","#","input-ids",")","attention_mask","(","`","torch.Tensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Mask","to","avoid","performing","attention","on","padding","token","indices",".","Mask","values","selected","in","`","[","0",",","1","]","`",":","-","1","for","tokens","that","are","*","*","not","masked","*","*",",","-","0","for","tokens","that","are","*","*","masked","*","*",".","[","What","are","attention","masks","?","]","(","..","\/glossary","#","attention-mask",")","head_mask","(","`","torch.Tensor","`","of","shape","`","(","encoder_layers",",","encoder_attention_heads",")","`",",","*","optional","*",")",":","Mask","to","nullify","selected","heads","of","the","attention","modules",".","Mask","values","selected","in","`","[","0",",","1","]","`",":","-","1","indicates","the","head","is","*","*","not","masked","*","*",",","-","0","indicates","the","head","is","*","*","masked","*","*",".","inputs_embeds","(","`","torch.FloatTensor","`","of","shape","`","(","batch_size",",","sequence_length",",","hidden_size",")","`",",","*","optional","*",")",":","Optionally",",","instead","of","passing","`","input_ids","`","you","can","choose","to","directly","pass","an","embedded","representation",".","This","is","useful","if","you","want","more","control","over","how","to","convert","`","input_ids","`","indices","into","associated","vectors","than","the","model","'s","internal","embedding","lookup","matrix",".","output_attentions","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","attentions","tensors","of","all","attention","layers",".","See","`","attentions","`","under","returned","tensors","for","more","detail",".","output_hidden_states","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","hidden","states","of","all","layers",".","See","`","hidden_states","`","under","returned","tensors","for","more","detail",".","return_dict","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","a","[","`","~utils.BaseModelOutput","`","]","instead","of","a","plain","tuple","."]
code: def forward(
      self,
      input_ids: torch.LongTensor = None,
      attention_mask: Optional[torch.Tensor] = None,
      position_ids: Optional[torch.LongTensor] = None,
      head_mask: Optional[torch.Tensor] = None,
      inputs_embeds: Optional[torch.FloatTensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple, BaseModelOutput]:
      r"""
      Args:
          input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
              Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
              provide it.
  
              Indices can be obtained using [`BartTokenizer`]. See [`PreTrainedTokenizer.encode`] and
              [`PreTrainedTokenizer.__call__`] for details.
  
              [What are input IDs?](../glossary#input-ids)
          attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
              Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
  
              - 1 for tokens that are **not masked**,
              - 0 for tokens that are **masked**.
  
              [What are attention masks?](../glossary#attention-mask)
          head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
              Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:
  
              - 1 indicates the head is **not masked**,
              - 0 indicates the head is **masked**.
  
          inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
              Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
              This is useful if you want more control over how to convert `input_ids` indices into associated vectors
              than the model's internal embedding lookup matrix.
          output_attentions (`bool`, *optional*):
              Whether or not to return the attentions tensors of all attention layers. See `attentions` under
              returned tensors for more detail.
          output_hidden_states (`bool`, *optional*):
              Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
              for more detail.
          return_dict (`bool`, *optional*):
              Whether or not to return a [`~utils.BaseModelOutput`] instead of a plain tuple.
      """
      output_attentions = (
          output_attentions
          if output_attentions is not None
          else self.config.output_attentions
      )
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      # retrieve input_ids and inputs_embeds
      if input_ids is not None and inputs_embeds is not None:
          raise ValueError(
              "You cannot specify both input_ids and inputs_embeds at the same time"
          )
      elif input_ids is not None:
          input_shape = input_ids.size()
          input_ids = input_ids.view(-1, input_shape[-1])
      elif inputs_embeds is not None:
          input_shape = inputs_embeds.size()[:-1]
      else:
          raise ValueError(
              "You have to specify either input_ids or inputs_embeds"
          )
  
      if inputs_embeds is None:
          inputs_embeds = self.embed_tokens(input_ids)
  
      seq_len = input_shape[1]
      if position_ids is None:
          position_ids = torch.arange(
              seq_len, dtype=torch.long, device=inputs_embeds.device
          ).expand((1, -1))
      embed_pos = self.embed_positions(position_ids)
  
      hidden_states = inputs_embeds + embed_pos
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
  
      # expand attention_mask
      if attention_mask is not None:
          # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
          attention_mask = _expand_mask(
              attention_mask, inputs_embeds.dtype
          )
  
      encoder_states = () if output_hidden_states else None
      all_attentions = () if output_attentions else None
  
      # check if head_mask has a correct number of layers specified if desired
      if head_mask is not None:
          if head_mask.size()[0] != (len(self.layers)):
              raise ValueError(
                  f"The head_mask should be specified for {len(self.layers)} layers, but it is for"
                  f" {head_mask.size()[0]}."
              )
  
      for idx, encoder_layer in enumerate(self.layers):
          if output_hidden_states:
              encoder_states = encoder_states + (hidden_states,)
          if self.gradient_checkpointing and self.training:
  
              def create_custom_forward(module):
                  def custom_forward(*inputs):
                      return module(*inputs, output_attentions)
  
                  return custom_forward
  
              layer_outputs = torch.utils.checkpoint.checkpoint(
                  create_custom_forward(encoder_layer),
                  hidden_states,
                  attention_mask,
                  (head_mask[idx] if head_mask is not None else None),
              )
          else:
              layer_outputs = encoder_layer(
                  hidden_states,
                  attention_mask,
                  layer_head_mask=(
                      head_mask[idx] if head_mask is not None else None
                  ),
                  output_attentions=output_attentions,
              )
  
          hidden_states = layer_outputs[0]
  
          if output_attentions:
              all_attentions = all_attentions + (layer_outputs[1],)
  
      hidden_states = self.layer_norm(hidden_states)
  
      if output_hidden_states:
          encoder_states = encoder_states + (hidden_states,)
  
      if not return_dict:
          return tuple(
              v
              for v in [hidden_states, encoder_states, all_attentions]
              if v is not None
          )
      return BaseModelOutput(
          last_hidden_state=hidden_states,
          hidden_states=encoder_states,
          attentions=all_attentions,
      )
  
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 4 for calling the LDMBertEncoder obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, position_ids, head_mask, inputs_embeds, output_attentions, output_hidden_states, return_dict) and returns: BaseModelOutput, tuple, custom_forward, module