code: def apply_rotary_pos_emb(q, k, cos, sin, position_ids):
      gather_indices = position_ids[
          :, None, :, None
      ]  # [bs, 1, seq_len, 1]
      gather_indices = gather_indices.repeat(
          1, cos.shape[1], 1, cos.shape[3]
      )
      cos = torch.gather(
          cos.repeat(gather_indices.shape[0], 1, 1, 1),
          2,
          gather_indices,
      )
      sin = torch.gather(
          sin.repeat(gather_indices.shape[0], 1, 1, 1),
          2,
          gather_indices,
      )
      q_embed = (q * cos) + (rotate_half(q) * sin)
      k_embed = (k * cos) + (rotate_half(k) * sin)
      return q_embed, k_embed
  
imports: import math
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from transformers.activations import ACT2FN
  from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
  from transformers.modeling_utils import PreTrainedModel
  from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from transformers.models.llama.configuration_llama import LlamaConfig
label_desc: Use image node_id 4 for calling a global function with example usage: apply_rotary_pos_emb(q, k, cos, sin, position_ids) and returns: q_embed,  k_embed