class_docstr: Scaled dot-product attention mechanism.
code: def forward(self, q, k, v, attn_mask=None):
      # q: [B, head, F, model_dim]
      scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(
          self.scale
      )  # [B,Head, F, F]
      if attn_mask:
          scores = scores.masked_fill_(attn_mask, -numpy.inf)
      scores = self.softmax(scores)
      scores = self.dropout(scores)  # [B,head, F, F]
      context = torch.matmul(scores, v)  # output
      return scores, context
  
imports: import os
  import math
  import numpy
  import torch
  from torch import nn
  from towhee.models.layers.layers_with_relprop import Einsum, Linear, Dropout, Softmax
label_desc: Use image node_id 2 for calling the Attention obj's underlying member method code with example usage: obj.forward(q, k, v, attn_mask) and returns: scores,  context