class_docstr: Multi-headed attention with Gating and Downsampling
class_docstr_tok: ["Multi-headed","attention","with","Gating","and","Downsampling"]
code: def forward(
      self,
      query,
      key,
      value,
      mask_future_timesteps=False,
      key_padding_mask=None,
      use_scalar_bias=False,
  ):
      src_len, bsz, embed_dim = key.size()
      tgt_len = query.size(0)
      assert embed_dim == self.embed_dim
      assert list(query.size()) == [tgt_len, bsz, embed_dim]
      assert key.size() == value.size()
  
      tgt_size = tgt_len
      if use_scalar_bias:
          tgt_size += 1
  
      attn = []
      attn_weights = []
      if self.downsample:
          for attention_head_number in range(self.num_heads):
              # call the forward of each attention head
              _attn, _attn_weight = self[attention_head_number](
                  query,
                  key,
                  value,
                  mask_future_timesteps,
                  key_padding_mask,
                  use_scalar_bias,
              )
              attn.append(_attn)
              attn_weights.append(_attn_weight)
          full_attn = torch.cat(attn, dim=2)
          full_attn = self.out_proj(full_attn)
          return full_attn, attn_weights[0].clone()
      else:
          _attn, _attn_weight = self.attention_module(
              query,
              key,
              value,
              mask_future_timesteps,
              key_padding_mask,
              use_scalar_bias,
          )
          attn.append(_attn)
          attn_weights.append(_attn_weight)
          full_attn = torch.cat(attn, dim=2)
          full_attn_weights = torch.cat(attn_weights)
          full_attn_weights = full_attn_weights.view(
              bsz, self.num_heads, tgt_size, src_len
          )
          full_attn_weights = (
              full_attn_weights.sum(dim=1) / self.num_heads
          )
          return full_attn, full_attn_weights
  
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 2 for calling the DownsampledMultiHeadAttention obj's underlying member method code with example usage: obj.forward(query, key, value, mask_future_timesteps, key_padding_mask, use_scalar_bias) and returns: full_attn,  attn_weights, full_attn,  full_attn_weights