class_docstr: Single-head attention that supports Gating and Downsampling
class_docstr_tok: ["Single-head","attention","that","supports","Gating","and","Downsampling"]
code: def __init__(
      self,
      out_channels,
      embed_dim,
      head_dim,
      head_index,
      dropout=0.0,
      bias=True,
      project_input=True,
      gated=False,
      downsample=False,
      num_heads=1,
  ):
      super().__init__()
      self.embed_dim = embed_dim
      self.dropout_module = FairseqDropout(
          dropout, module_name=self.__class__.__name__
      )
      self.head_index = head_index
      self.head_dim = head_dim
      self.project_input = project_input
      self.gated = gated
      self.downsample = downsample
      self.num_heads = num_heads
      self.projection = None
  
      k_layers = []
      v_layers = []
      if self.downsample:
          k_layers.append(Downsample(self.head_index))
          v_layers.append(Downsample(self.head_index))
          out_proj_size = self.head_dim
      else:
          out_proj_size = self.head_dim * self.num_heads
      if self.gated:
          k_layers.append(
              GatedLinear(self.embed_dim, out_proj_size, bias=bias)
          )
          self.in_proj_q = GatedLinear(
              self.embed_dim, out_proj_size, bias=bias
          )
          v_layers.append(
              GatedLinear(self.embed_dim, out_proj_size, bias=bias)
          )
      else:
          k_layers.append(
              Linear(self.embed_dim, out_proj_size, bias=bias)
          )
          self.in_proj_q = Linear(
              self.embed_dim, out_proj_size, bias=bias
          )
          v_layers.append(
              Linear(self.embed_dim, out_proj_size, bias=bias)
          )
  
      self.in_proj_k = nn.Sequential(*k_layers)
      self.in_proj_v = nn.Sequential(*v_layers)
  
      if self.downsample:
          self.out_proj = Linear(
              out_proj_size, self.head_dim, bias=bias
          )
      else:
          self.out_proj = Linear(out_proj_size, out_channels, bias=bias)
  
      self.scaling = self.head_dim**-0.5
  
file_path: fairseq/fairseq/modules/downsampled_multihead_attention.py
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from fairseq.modules.scalar_bias import scalar_bias
label_desc: Use image node_id 1 to create a new SingleHeadAttention object from inherited base classes: nn with example: obj = SingleHeadAttention(out_channels, embed_dim, head_dim, head_index, dropout, bias, project_input, gated, downsample, num_heads)