code: def compute_attn_outputs_weights(
      query_states,
      key_states,
      value_states,
      bsz,
      q_len,
      kv_seq_len,
      num_heads,
      head_dim,
      hidden_size,
      attention_mask,
  ):
      attn_weights = torch.matmul(
          query_states, key_states.transpose(2, 3)
      ) / math.sqrt(head_dim)
  
      if attn_weights.size() != (bsz, num_heads, q_len, kv_seq_len):
          invalidInputError(
              False,
              f"Attention weights should be of size {(bsz, num_heads, q_len, kv_seq_len)},"
              f" but is {attn_weights.size()}",
          )
  
      if attention_mask is not None:
          if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
              invalidInputError(
                  False,
                  f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)},"
                  f" but is {attention_mask.size()}",
              )
  
          attn_weights = attn_weights + attention_mask
  
      # upcast attention to fp32
      attn_weights = nn.functional.softmax(
          attn_weights, dim=-1, dtype=torch.float32
      ).to(query_states.dtype)
      attn_output = torch.matmul(attn_weights, value_states)
  
      if attn_output.size() != (bsz, num_heads, q_len, head_dim):
          invalidInputError(
              f"`attn_output` should be of size {(bsz, num_heads, q_len, head_dim)},"
              f" but is {attn_output.size()}"
          )
  
      attn_output = attn_output.transpose(1, 2).contiguous()
      attn_output = attn_output.reshape(bsz, q_len, hidden_size)
  
      return attn_output, attn_weights
  
file_path: BigDL/python/llm/src/bigdl/llm/transformers/models/mistral.py
imports: import math
  from typing import Optional, Tuple
  import torch
  from torch import nn
  import torch.nn.functional
  from bigdl.llm.utils.common import invalidInputError
  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, apply_rotary_pos_emb_no_cache_xpu
  from bigdl.llm.transformers.models.utils import is_enough_kv_cache_room_4_31, is_enough_kv_cache_room_4_36
  from bigdl.llm.transformers.low_bit_linear import SYM_INT4, FP8E5
  from bigdl.llm.transformers.models.utils import use_flash_attention
label_desc: Use image node_id 4 for calling a global function with example usage: compute_attn_outputs_weights(query_states, key_states, value_states, bsz, q_len, kv_seq_len, num_heads, head_dim, hidden_size, attention_mask) and returns: attn_output,  attn_weights