code: def baichuan_13b_get_alibi_mask(self, tensor, seq_length_with_past):
      if self.training:
          slopes = torch.Tensor(_get_interleave(self.n_head))
          position_point = (
              torch.arange(seq_length_with_past)
              - seq_length_with_past
              + 1
          )
          position_point = (
              position_point.unsqueeze(0)
              .unsqueeze(0)
              .expand(self.n_head, seq_length_with_past, -1)
          )
          diag = torch.diag(position_point[0])
          position_point = position_point - diag.unsqueeze(0).unsqueeze(
              0
          ).transpose(-1, -2)
          alibi = slopes.unsqueeze(1).unsqueeze(1) * position_point
          mask = _buffered_future_mask(
              tensor, seq_length_with_past, alibi, self.n_head
          )
      else:
          if self.first_run:
              # Override the default max_cache_pos=4096 for memory considerations
              self.max_cache_pos = (
                  seq_length_with_past + MASK_BLOCK_SIZE
              )
              self.first_run = False
              self.register_buffer(
                  "future_mask",
                  baichuan_13b_gen_alibi_mask(
                      tensor, self.n_head, self.max_cache_pos
                  ),
                  persistent=False,
              )
          if seq_length_with_past > self.max_cache_pos:
              # When max_cache_pos is not enough for current sequence length,
              # increase by MASK_BLOCK_SIZE and recalculate future_mask.
              self.max_cache_pos = (
                  seq_length_with_past + MASK_BLOCK_SIZE
              )
              self.register_buffer(
                  "future_mask",
                  baichuan_13b_gen_alibi_mask(
                      tensor, self.n_head, self.max_cache_pos
                  ),
                  persistent=False,
              )
          mask = self.future_mask[
              : self.n_head,
              :seq_length_with_past,
              :seq_length_with_past,
          ]
      return mask
  
file_path: BigDL/python/llm/src/bigdl/llm/transformers/models/baichuan2.py
imports: import math
  from typing import Optional, Tuple
  import torch
  import torch.utils.checkpoint
  from torch.nn import functional
  from bigdl.llm.ggml.quantize import ggml_tensor_qtype
  from bigdl.llm.transformers.models.utils import init_kv_cache, extend_kv_cache, append_kv_cache
  from bigdl.llm.transformers.models.utils import apply_rotary_pos_emb
  from bigdl.llm.transformers.models.utils import apply_rotary_pos_emb_no_cache_xpu
  from bigdl.llm.transformers.models.utils import mlp_fusion_check
  from transformers.utils import logging
label_desc: Use image node_id 9 for calling a global function with example usage: baichuan_13b_get_alibi_mask(tensor, seq_length_with_past) and returns: mask