code: def __init__(
      self,
      q_dim,
      kv_dim,
      num_heads=8,
      qkv_bias=False,
      qk_scale=None,
      attn_drop=0.0,
      proj_drop=0.0,
      cosine_attention=False,
  ):
      super().__init__()
      self.num_heads = num_heads
      head_dim = q_dim // num_heads
      self.scale = qk_scale or head_dim**-0.5
  
      self.q_proj = nn.Linear(q_dim, q_dim, bias=qkv_bias)
      self.kv_proj = nn.Linear(kv_dim, 2 * q_dim, bias=qkv_bias)
      self.attn_drop = nn.Dropout(attn_drop)
      self.proj = nn.Linear(q_dim, q_dim)
      self.proj_drop = nn.Dropout(proj_drop)
  
      self.cosine_attention = cosine_attention
  
      if cosine_attention:
          self.logit_scale = nn.Parameter(
              torch.log(10 * torch.ones((num_heads, 1, 1))),
              requires_grad=True,
          )
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  import numpy
  from dataclasses import dataclass
  from fairseq.modules import LayerNorm, SamePad, SamePad2d, TransposeLast
label_desc: Use image node_id 1 to create a new EncDecAttention object from inherited base classes: nn with example: obj = EncDecAttention(q_dim, kv_dim, num_heads, qkv_bias, qk_scale, attn_drop, proj_drop, cosine_attention)