class_docstr: Multi-headed attention.
  
  See "Attention Is All You Need" for more details.
class_docstr_tok: ["Multi-headed","attention",".","See","``","Attention","Is","All","You","Need","''","for","more","details","."]
code: def _pad_masks(
      self,
      key_padding_mask: Optional[Tensor],
      attn_mask: Optional[Tensor],
  ) -> Tuple[Optional[Tensor], Optional[Tensor]]:
      if attn_mask is not None:
          shape = attn_mask.size()[:-1] + torch.Size([1])
          attn_mask = torch.cat(
              [attn_mask, attn_mask.new_zeros(shape)], dim=-1
          )
      if key_padding_mask is not None:
          shape = key_padding_mask.size()[:-1] + torch.Size([1])
          key_padding_mask = torch.cat(
              [
                  key_padding_mask,
                  key_padding_mask.new_zeros(shape),
              ],
              dim=-1,
          )
      return key_padding_mask, attn_mask
  
imports: import math
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from torch.nn import Parameter
  from fairseq import utils
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from fairseq.modules.quant_noise import quant_noise
  from fairseq.models.fairseq_incremental_decoder import FairseqIncrementalDecoder
label_desc: Use image node_id 7 for calling the MultiheadAttention obj's underlying member method code with example usage: obj._pad_masks(key_padding_mask, attn_mask) and returns: key_padding_mask,  attn_mask