code: def core_attn(
      self,
      query,
      key,
      value,
      causal_mask=None,
      attention_mask=None,
      head_mask=None,
  ):
      if query.size(2) != 1 or query.device.type != "xpu":
          # We have no CPU fp8 matmul implementation for now, so just upscale to fp32
          key, value = restore_fp8_kv_cache(key, value, query.dtype)
          attn_weights = torch.matmul(query, key.transpose(-1, -2))
      else:
          import linear_q4_0
  
          attn_weights = linear_q4_0.query_key_fp8_matmul(query, key)
  
      if self.scale_attn_weights:
          if self.use_cache_quantization:
              size_temp = value[0].size(-1)
          else:
              size_temp = value.size(-1)
          attn_weights = attn_weights / (size_temp**0.5)
  
      mask_value = torch.finfo(attn_weights.dtype).min
      if causal_mask is not None:
          attn_weights = torch.where(
              causal_mask,
              attn_weights.to(attn_weights.dtype),
              mask_value,
          )
  
      if attention_mask is not None:
          attn_weights = attn_weights + attention_mask
  
      if self.softmax_in_fp32:
          attn_weights = torch.nn.functional.softmax(
              attn_weights.float(), dim=-1
          )
      else:
          attn_weights = torch.nn.functional.softmax(
              attn_weights, dim=-1
          )
  
      attn_weights = attn_weights.type(query.dtype)
      attn_weights = self.attn_dropout(attn_weights)
  
      if head_mask is not None:
          attn_weights = attn_weights * head_mask
  
      if query.size(2) != 1 or query.device.type != "xpu":
          # We have no CPU fp8 matmul implementation for now, so just upscale to fp32
          attn_output = torch.matmul(attn_weights, value)
      else:
          import linear_q4_0
  
          attn_output = linear_q4_0.attn_value_fp8_matmul(
              attn_weights, value.transpose(-1, -2)
          )
  
      attn_output = attn_output.transpose(1, 2)
  
      return attn_output, attn_weights
  
file_path: BigDL/python/llm/src/bigdl/llm/transformers/models/qwen.py
imports: import importlib
  import math
  from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  from transformers.utils import logging
  from bigdl.llm.transformers.models.utils import extend_kv_cache, init_kv_cache, append_kv_cache
  from bigdl.llm.transformers.models.utils import init_fp8_kv_cache, extend_fp8_kv_cache, append_fp8_kv_cache, restore_fp8_kv_cache
  from bigdl.llm.transformers.models.utils import rotate_half, quantize_kv_cache
  from bigdl.llm.transformers.models.utils import mlp_fusion_check
  from bigdl.llm.utils.common import invalidInputError, invalidOperationError
  from bigdl.llm.ggml.quantize import ggml_tensor_qtype
label_desc: Use image node_id 3 for calling a global function with example usage: core_attn(query, key, value, causal_mask, attention_mask, head_mask) and returns: attn_output,  attn_weights