class_docstr: Multi-Head Attention module.
  
  Args:
      n_head (int): The number of heads in the
          multiheadattention models (default=8).
      d_model (int): The number of expected features
          in the decoder inputs (default=512).
      d_k (int): Total number of features in key.
      d_v (int): Total number of features in value.
      dropout (float): Dropout layer on attn_output_weights.
      qkv_bias (bool): Add bias in projection layer. Default: False.
code: def forward(self, q, k, v, mask=None):
      batch_size, len_q, _ = q.size()
      _, len_k, _ = k.size()
  
      q = self.linear_q(q).view(
          batch_size, len_q, self.n_head, self.d_k
      )
      k = self.linear_k(k).view(
          batch_size, len_k, self.n_head, self.d_k
      )
      v = self.linear_v(v).view(
          batch_size, len_k, self.n_head, self.d_v
      )
  
      q, k, v = q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2)
  
      if mask is not None:
          if mask.dim() == 3:
              mask = mask.unsqueeze(1)
          elif mask.dim() == 2:
              mask = mask.unsqueeze(1).unsqueeze(1)
  
      attn_out, _ = self.attention(q, k, v, mask=mask)
  
      attn_out = (
          attn_out.transpose(1, 2)
          .contiguous()
          .view(batch_size, len_q, self.dim_v)
      )
  
      attn_out = self.fc(attn_out)
      attn_out = self.proj_drop(attn_out)
  
      return attn_out
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmocr.registry import MODELS
label_desc: Use image node_id 2 for calling the MultiHeadAttention obj's underlying member method code with example usage: obj.forward(q, k, v, mask) and returns: attn_out