class_docstr: This corresponds to the Block class in the timm implementation.
class_docstr_tok: ["This","corresponds","to","the","Block","class","in","the","timm","implementation","."]
code: def forward(
      self,
      hidden_states: torch.Tensor,
      head_mask: Optional[torch.Tensor] = None,
      output_attentions: bool = False,
      relative_position_bias: Optional[BeitRelativePositionBias] = None,
  ) -> Union[Tuple[torch.Tensor], Tuple[torch.Tensor, torch.Tensor]]:
      self_attention_outputs = self.attention(
          self.layernorm_before(
              hidden_states
          ),  # in BEiT, layernorm is applied before self-attention
          head_mask,
          output_attentions=output_attentions,
          relative_position_bias=relative_position_bias,
      )
      attention_output = self_attention_outputs[0]
      outputs = self_attention_outputs[
          1:
      ]  # add self attentions if we output attention weights
  
      # apply lambda_1 if present
      if self.lambda_1 is not None:
          attention_output = self.lambda_1 * attention_output
  
      # first residual connection
      hidden_states = self.attention_adapters.bottleneck_layer_forward(
          self.drop_path(attention_output), hidden_states, None
      )
  
      # in BEiT, layernorm is also applied after self-attention
      layer_output = self.layernorm_after(hidden_states)
  
      layer_output = self.intermediate(layer_output)
      layer_output = self.output(layer_output)
  
      if self.lambda_2 is not None:
          layer_output = self.lambda_2 * layer_output
  
      # second residual connection
      layer_output = self.output_adapters.bottleneck_layer_forward(
          self.drop_path(layer_output), hidden_states, None
      )
  
      outputs = (layer_output,) + outputs
  
      return outputs
  
file_path: adapters/src/adapters/models/beit/modeling_beit.py
imports: import math
  from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from transformers.models.beit.modeling_beit import BeitLayer, BeitRelativePositionBias, BeitSelfAttention
  from .mixin_beit import BeitLayerAdaptersMixin, BeitSelfAttentionAdaptersMixin
label_desc: Use image node_id 1 for calling the BeitLayerWithAdapters obj's underlying member method code with example usage: obj.forward(hidden_states, head_mask, output_attentions, relative_position_bias) and returns: outputs