code: def native_sdp(
      query,
      key,
      value,
      attention_mask,
      bsz,
      q_len,
      kv_seq_len,
      head_dim,
      num_heads,
  ):
      attn_weights = torch.matmul(
          query, key.transpose(2, 3)
      ) / math.sqrt(head_dim)
  
      attn_weights_size = (bsz, num_heads, q_len, kv_seq_len)
      if attn_weights.size() != attn_weights_size:
          invalidInputError(
              False,
              f"Attention weights should be of size {attn_weights_size}, "
              f"but is {attn_weights.size()}",
          )
  
      if attention_mask is not None:
          attn_mask_size = (bsz, 1, q_len, kv_seq_len)
          if attention_mask.size() != attn_mask_size:
              invalidInputError(
                  False,
                  f"Attention mask should be of size {attn_mask_size}, "
                  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(value.dtype)
      attn_output = torch.matmul(attn_weights, value)
      return attn_output, attn_weights
  
imports: import torch
  import warnings
  import importlib
  import torch.nn
  from typing import Optional, Tuple, Union, List
  import math
  import os
  import torch.nn.functional
  from bigdl.llm.transformers.models.utils import init_kv_cache, extend_kv_cache, append_kv_cache
  from bigdl.llm.transformers.models.utils import is_enough_kv_cache_room_4_31, apply_rotary_pos_emb, is_enough_kv_cache_room_4_36
  from bigdl.llm.transformers.models.utils import apply_rotary_pos_emb_no_cache_xpu
  from bigdl.llm.transformers.models.utils import use_flash_attention, use_esimd_sdp
  from bigdl.llm.transformers.models.utils import mlp_fusion_check
  from transformers.modeling_outputs import BaseModelOutputWithPast
  from bigdl.llm.transformers.low_bit_linear import SYM_INT4, FP8E5
  from bigdl.llm.ggml.quantize import ggml_tensor_qtype
  from bigdl.llm.utils.common import invalidInputError
label_desc: Use image node_id 9 for calling a global function with example usage: native_sdp(query, key, value, attention_mask, bsz, q_len, kv_seq_len, head_dim, num_heads) and returns: attn_output,  attn_weights