code: def forward(
      self,
      hidden_states: Optional[Tuple[torch.FloatTensor]],
      layer_past: Optional[Tuple[torch.Tensor]] = None,
      attention_mask: Optional[torch.FloatTensor] = None,
      head_mask: Optional[torch.FloatTensor] = None,
      encoder_hidden_states: Optional[torch.Tensor] = None,
      encoder_attention_mask: Optional[torch.FloatTensor] = None,
      use_cache: Optional[bool] = False,
      output_attentions: Optional[bool] = False,
  ) -> Union[
      Tuple[torch.Tensor],
      Optional[Tuple[torch.Tensor, Tuple[torch.FloatTensor, ...]]],
  ]:
      adjust_tensors_for_parallel_(hidden_states, attention_mask)
      residual = hidden_states
      hidden_states = self.ln_1(hidden_states)
      attn_outputs = self.attn(
          hidden_states,
          layer_past=layer_past,
          attention_mask=attention_mask,
          head_mask=head_mask,
          use_cache=use_cache,
          output_attentions=output_attentions,
      )
      attn_output = attn_outputs[
          0
      ]  # output_attn: a, present, (attentions)
      outputs = attn_outputs[1:]
      hidden_states = self.attention_adapters(
          attn_output, residual, None
      )
  
      if encoder_hidden_states is not None:
          # add one self-attention block for cross-attention
          if not hasattr(self, "crossattention"):
              raise ValueError(
                  f"If `encoder_hidden_states` are passed, {self} has to be instantiated with "
                  "cross-attention layers by setting `config.add_cross_attention=True`"
              )
          residual = hidden_states
          hidden_states = self.ln_cross_attn(hidden_states)
          cross_attn_outputs = self.crossattention(
              hidden_states,
              attention_mask=attention_mask,
              head_mask=head_mask,
              encoder_hidden_states=encoder_hidden_states,
              encoder_attention_mask=encoder_attention_mask,
              output_attentions=output_attentions,
          )
          attn_output = cross_attn_outputs[0]
          # residual connection
          hidden_states = residual + attn_output
          outputs = (
              outputs + cross_attn_outputs[2:]
          )  # add cross attentions if we output attention weights
  
      residual = hidden_states
      hidden_states = self.ln_2(hidden_states)
      feed_forward_hidden_states = self.mlp(hidden_states)
      # residual connection
      hidden_states = self.output_adapters(
          feed_forward_hidden_states, residual, None
      )
  
      if use_cache:
          outputs = (hidden_states,) + outputs
      else:
          outputs = (hidden_states,) + outputs[1:]
  
      return outputs
  
file_path: adapters/src/adapters/models/gpt2/modeling_gpt2.py
imports: from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from transformers.models.gpt2.modeling_gpt2 import GPT2Attention, GPT2Block
  from ...composition import adjust_tensors_for_parallel, adjust_tensors_for_parallel_
  from .mixin_gpt2 import GPT2AttentionAdaptersMixin, GPT2DecoderBlockAdaptersMixin
label_desc: Use image node_id 1 for calling the GPT2BlockWithAdapters obj's underlying member method code with example usage: obj.forward(hidden_states, layer_past, attention_mask, head_mask, encoder_hidden_states, encoder_attention_mask, use_cache, output_attentions) and returns: outputs