code: def _forward(self, inp, attn_mask=None, conditioning=None):
      residual = inp
  
      if self.pre_lnorm:
          # layer normalization
          inp = self.layer_norm(inp, conditioning)
  
      n_head, d_head = self.n_head, self.d_head
  
      head_q, head_k, head_v = torch.chunk(self.qkv_net(inp), 3, dim=2)
  
      head_q = head_q.view(inp.size(0), inp.size(1), n_head, d_head)
      head_k = head_k.view(inp.size(0), inp.size(1), n_head, d_head)
      head_v = head_v.view(inp.size(0), inp.size(1), n_head, d_head)
  
      q = head_q.permute(2, 0, 1, 3).reshape(-1, inp.size(1), d_head)
      k = head_k.permute(2, 0, 1, 3).reshape(-1, inp.size(1), d_head)
      v = head_v.permute(2, 0, 1, 3).reshape(-1, inp.size(1), d_head)
  
      attn_score = torch.bmm(q, k.transpose(1, 2))
      attn_score.mul_(self.scale)
  
      if attn_mask is not None:
          attn_mask = attn_mask.unsqueeze(1).to(attn_score.dtype)
          attn_mask = attn_mask.repeat(n_head, attn_mask.size(2), 1)
          attn_score.masked_fill_(
              attn_mask.to(torch.bool), -float("inf")
          )
  
      attn_prob = F.softmax(attn_score, dim=2)
      attn_prob = self.dropatt(attn_prob)
      attn_vec = torch.bmm(attn_prob, v)
  
      attn_vec = attn_vec.view(n_head, inp.size(0), inp.size(1), d_head)
      attn_vec = (
          attn_vec.permute(1, 2, 0, 3)
          .contiguous()
          .view(inp.size(0), inp.size(1), n_head * d_head)
      )
  
      # linear projection
      attn_out = self.o_net(attn_vec)
      attn_out = self.drop(attn_out)
  
      if self.pre_lnorm:
          # residual connection
          output = residual + attn_out
      else:
          # residual connection + layer normalization
          output = self.layer_norm(residual + attn_out, conditioning)
  
      return output
  
imports: from typing import Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.collections.tts.modules.submodules import ConditionalInput, ConditionalLayerNorm, LinearNorm
  from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths
  from nemo.core.classes import NeuralModule, adapter_mixins, typecheck
  from nemo.core.neural_types.elements import EncodedRepresentation, LengthsType, MaskType, TokenIndex
  from nemo.core.neural_types.neural_type import NeuralType
label_desc: Use image node_id 3 for calling the MultiHeadAttn obj's underlying member method code with example usage: obj._forward(inp, attn_mask, conditioning) and returns: output