class_docstr: Querying Transformer (Q-Former), used in BLIP-2.
class_docstr_tok: ["Querying","Transformer","(","Q-Former",")",",","used","in","BLIP-2","."]
docstr: Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
  
  Arguments:
      attention_mask (`torch.Tensor`):
          Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
      input_shape (`Tuple[int]`):
          The shape of the input to the model.
      device (`torch.device`):
          The device of the input to the model.
  
  Returns:
      `torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.
docstr_tok: ["Makes","broadcastable","attention","and","causal","masks","so","that","future","and","masked","tokens","are","ignored",".","Arguments",":","attention_mask","(","`","torch.Tensor","`",")",":","Mask","with","ones","indicating","tokens","to","attend","to",",","zeros","for","tokens","to","ignore",".","input_shape","(","`","Tuple","[","int","]","`",")",":","The","shape","of","the","input","to","the","model",".","device","(","`","torch.device","`",")",":","The","device","of","the","input","to","the","model",".","Returns",":","`","torch.Tensor","`","The","extended","attention","mask",",","with","a","the","same","dtype","as","`","attention_mask.dtype","`","."]
code: def get_extended_attention_mask(
      self,
      attention_mask: torch.Tensor,
      input_shape: Tuple[int],
      device: torch.device,
      has_query: bool = False,
  ) -> torch.Tensor:
      """
      Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
  
      Arguments:
          attention_mask (`torch.Tensor`):
              Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
          input_shape (`Tuple[int]`):
              The shape of the input to the model.
          device (`torch.device`):
              The device of the input to the model.
  
      Returns:
          `torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.
      """
      # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
      # ourselves in which case we just need to make it broadcastable to all heads.
      if attention_mask.dim() == 3:
          extended_attention_mask = attention_mask[:, None, :, :]
      elif attention_mask.dim() == 2:
          # Provided a padding mask of dimensions [batch_size, seq_length]
          # - the model is an encoder, so make the mask broadcastable to [batch_size, num_heads, seq_length, seq_length]
          extended_attention_mask = attention_mask[:, None, None, :]
      else:
          raise ValueError(
              "Wrong shape for input_ids (shape {}) or attention_mask (shape {})".format(
                  input_shape, attention_mask.shape
              )
          )
  
      # Since attention_mask is 1.0 for positions we want to attend and 0.0 for
      # masked positions, this operation will create a tensor which is 0.0 for
      # positions we want to attend and -10000.0 for masked positions.
      # Since we are adding it to the raw scores before the softmax, this is
      # effectively the same as removing these entirely.
      extended_attention_mask = extended_attention_mask.to(
          dtype=self.dtype
      )  # fp16 compatibility
      extended_attention_mask = (
          1.0 - extended_attention_mask
      ) * -10000.0
      return extended_attention_mask
  
imports: from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from transformers import BertTokenizer
  from transformers.activations import QuickGELUActivation
  from transformers.modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, BaseModelOutputWithPooling, BaseModelOutputWithPoolingAndCrossAttentions
  from transformers.models.blip_2.configuration_blip_2 import Blip2Config, Blip2VisionConfig
  from transformers.models.blip_2.modeling_blip_2 import Blip2Encoder, Blip2PreTrainedModel, Blip2QFormerAttention, Blip2QFormerIntermediate, Blip2QFormerOutput
  from transformers.pytorch_utils import apply_chunking_to_forward
  from transformers.utils import logging, replace_return_docstrings
label_desc: Use image node_id 5 for calling the Blip2QFormerModel obj's underlying member method code with example usage: obj.get_extended_attention_mask(attention_mask, input_shape, device, has_query) and returns: extended_attention_mask