code: def apply_rotary_pos_emb(q, k, cos, sin, offset: int = 0):
      cos = cos[..., offset : q.shape[-2] + offset, :]
      sin = sin[..., offset : q.shape[-2] + offset, :]
      q_embed = (q * cos) + (rotate_half(q) * sin)
      k_embed = (k * cos) + (rotate_half(k) * sin)
      return q_embed, k_embed
  
imports: from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import Tensor, nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...file_utils import add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
  from ...modeling_utils import PreTrainedModel
  from ...utils import logging
  from .configuration_gpt_neox_japanese import GPTNeoXJapaneseConfig
label_desc: Use image node_id 2 for calling a global function with example usage: apply_rotary_pos_emb(q, k, cos, sin, offset) and returns: q_embed,  k_embed