code: def forward(
      self,
      hidden_states,
      head_mask: Optional[torch.Tensor] = None,
      output_attentions: bool = False,
  ) -> Union[Tuple[torch.Tensor, torch.Tensor], Tuple[torch.Tensor]]:
      mixed_query_layer = self.query(hidden_states)
  
      key_layer = self.transpose_for_scores(self.key(hidden_states))
      value_layer = self.transpose_for_scores(self.value(hidden_states))
      query_layer = self.transpose_for_scores(mixed_query_layer)
  
      # Take the dot product between "query" and "key" to get the raw attention scores.
      attention_scores = torch.matmul(
          query_layer, key_layer.transpose(-1, -2)
      )
  
      attention_scores = attention_scores / math.sqrt(
          self.attention_head_size
      )
  
      # Normalize the attention scores to probabilities.
      attention_probs = nn.functional.softmax(attention_scores, dim=-1)
  
      # This is actually dropping out entire tokens to attend to, which might
      # seem a bit unusual, but is taken from the original Transformer paper.
      attention_probs = self.dropout(attention_probs)
  
      # Mask heads if we want to
      if head_mask is not None:
          attention_probs = attention_probs * head_mask
  
      context_layer = torch.matmul(attention_probs, value_layer)
  
      context_layer = context_layer.permute(0, 2, 1, 3).contiguous()
      new_context_layer_shape = context_layer.size()[:-2] + (
          self.all_head_size,
      )
      context_layer = context_layer.view(new_context_layer_shape)
  
      outputs = (
          (context_layer, attention_probs)
          if output_attentions
          else (context_layer,)
      )
  
      return outputs
  
imports: import math
  from typing import Optional, Set, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, ImageClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...pytorch_utils import find_pruneable_heads_and_indices, prune_linear_layer
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_vivit import VivitConfig
label_desc: Use image node_id 3 for calling the VivitSelfAttention obj's underlying member method code with example usage: obj.forward(hidden_states, head_mask, output_attentions) and returns: outputs