class_docstr: Multi-headed attention.
  
  See "Attention Is All You Need" for more details.
code: def _append_prev_key_padding_mask(
      key_padding_mask: Optional[Tensor],
      prev_key_padding_mask: Optional[Tensor],
      batch_size: int,
      src_len: int,
      static_kv: bool,
  ) -> Optional[Tensor]:
      # saved key padding masks have shape (bsz, seq_len)
      if prev_key_padding_mask is not None and static_kv:
          new_key_padding_mask = prev_key_padding_mask
      elif (
          prev_key_padding_mask is not None
          and key_padding_mask is not None
      ):
          new_key_padding_mask = torch.cat(
              [prev_key_padding_mask.float(), key_padding_mask.float()],
              dim=1,
          )
      # During incremental decoding, as the padding token enters and
      # leaves the frame, there will be a time when prev or current
      # is None
      elif prev_key_padding_mask is not None:
          if src_len > prev_key_padding_mask.size(1):
              filler = torch.zeros(
                  (batch_size, src_len - prev_key_padding_mask.size(1)),
                  device=prev_key_padding_mask.device,
              )
              new_key_padding_mask = torch.cat(
                  [prev_key_padding_mask.float(), filler.float()], dim=1
              )
          else:
              new_key_padding_mask = prev_key_padding_mask.float()
      elif key_padding_mask is not None:
          if src_len > key_padding_mask.size(1):
              filler = torch.zeros(
                  (batch_size, src_len - key_padding_mask.size(1)),
                  device=key_padding_mask.device,
              )
              new_key_padding_mask = torch.cat(
                  [filler.float(), key_padding_mask.float()], dim=1
              )
          else:
              new_key_padding_mask = key_padding_mask.float()
      else:
          new_key_padding_mask = prev_key_padding_mask
      return new_key_padding_mask
  
imports: import math
  import numpy
  from typing import Dict, Optional, Tuple
  import torch
  from torch import Tensor, nn
  import torch.nn.functional
  from torch.nn import LayerNorm, Parameter
  from lavis.models.beats.modules import GradMultiply, SamePad, get_activation_fn, GLU_Linear, quant_noise
label_desc: Use image node_id 6 for calling the MultiheadAttention obj's underlying member method code with example usage: obj._append_prev_key_padding_mask(key_padding_mask, prev_key_padding_mask, batch_size, src_len, static_kv) and returns: new_key_padding_mask