code: def _prepare_decoder_attention_mask(
      self: LlamaModel,
      attention_mask: torch.BoolTensor,
      input_shape: torch.Size,
      inputs_embeds: torch.Tensor,
      past_key_values_length: int,
  ) -> Optional[torch.Tensor]:
      """
      Decoder attetion mask
      """
      if past_key_values_length > 0 and attention_mask is not None:
          attention_mask = torch.cat(
              tensors=(
                  torch.full(
                      size=(input_shape[0], past_key_values_length),
                      fill_value=True,
                      dtype=attention_mask.dtype,
                      device=attention_mask.device,
                  ),
                  attention_mask,
              ),
              dim=-1,
          )  # (bsz, past_key_values_length + q_len)
      if attention_mask is not None and torch.all(attention_mask):
          return None  # Faster
      return attention_mask
  
file_path: ColossalAI/applications/Colossal-LLaMA-2/colossal_llama2/utils/flash_attention_patch.py
imports: from types import MethodType
  from typing import Optional, Tuple
  import torch
  import torch.nn.functional
  from einops import rearrange
  from flash_attn.bert_padding import pad_input, unpad_input
  from flash_attn.flash_attn_interface import flash_attn_func, flash_attn_varlen_kvpacked_func
  from flash_attn.ops.rms_norm import rms_norm
  from transformers.models.llama.modeling_llama import LlamaAttention, LlamaForCausalLM, LlamaModel, LlamaRMSNorm, apply_rotary_pos_emb, repeat_kv
  from colossalai.logging import get_dist_logger
label_desc: Use image node_id 1 for calling a global function with example usage: _prepare_decoder_attention_mask(attention_mask, input_shape, inputs_embeds, past_key_values_length) and returns: attention_mask, None