code: def apply_rotary_pos_emb(t: Tensor, freqs: Tensor) -> Tensor:
      """Apply rotary positional embedding to input tensor T.
  
      check https://kexue.fm/archives/8265 for detailed formulas
  
      Args:
          t (Tensor): Input tensor T is of shape [seq_length, ... , dim]
          freqs (Tensor): Rotary Positional embedding tensor freq is of shape [seq_length, ..., dim]
  
      Returns:
          Tensor: The input tensor after applying RoPE
      """
      rot_dim = freqs.shape[-1]
  
      # ideally t_pass is empty so rotary pos embedding is applied to all tensor t
      t, t_pass = t[..., :rot_dim], t[..., rot_dim:]
  
      # first part is cosine component
      # second part is sine component, need to change signs with _rotate_half method
      cos_ = torch.cos(freqs).to(t.dtype)
      sin_ = torch.sin(freqs).to(t.dtype)
  
      t = (t * cos_) + (_rotate_half(t) * sin_)
      return torch.cat((t, t_pass), dim=-1)
  
file_path: megatron-lm/megatron/core/models/common/embeddings/rotary_pos_embedding.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING
  import torch
  from torch import Tensor, nn
  from megatron.core import parallel_state
label_desc: Use image node_id 3 for calling a global function with example usage: apply_rotary_pos_emb(t, freqs) and returns: torch