code: def test_rotary(cfg):
      PE = RotaryEmbedding(dim=cfg["hidden_size"])
      rotary_embedding = PE(cfg["max_seq_len"])
  
      x = torch.rand(
          cfg["max_seq_len"],
          1,
          cfg["num_attention_heads"],
          cfg["hidden_size"],
      )
      x_rotary = apply_rotary_pos_emb(x, rotary_embedding)
      assert x_rotary.shape == x.shape
  
      hd = cfg["hidden_size"] // 2
      x_rotary_test = torch.cat(
          (
              x[..., :hd] * rotary_embedding[..., :hd].cos()
              + x[..., hd:] * rotary_embedding[..., hd:].sin() * -1,
              x[..., :hd] * rotary_embedding[..., :hd].sin()
              + x[..., hd:] * rotary_embedding[..., hd:].cos(),
          ),
          dim=-1,
      )
      assert torch.equal(x_rotary, x_rotary_test)
  
      offset = random.choice(range(1, cfg["max_seq_len"]))
      rotary_embedding_offset = PE(cfg["max_seq_len"], offset=offset)
      x_rotary = apply_rotary_pos_emb(
          x[: offset + 1], rotary_embedding[: offset + 1]
      )
      x_rotary_offset = apply_rotary_pos_emb(
          x[offset : offset + 1], rotary_embedding_offset[:1]
      )
      assert torch.equal(x_rotary[-1], x_rotary_offset[0])
  
file_path: NeMo/tests/collections/nlp/test_position_embedding.py
imports: import random
  import pytest
  import torch
  from nemo.collections.nlp.modules.common.megatron.layer_type import LayerType
  from nemo.collections.nlp.modules.common.megatron.position_embedding import ALiBiRelativePositionEmbedding, KERPLERelativePositionEmbedding, RotaryEmbedding, SandwichRelativePositionEmbedding, T5RelativePositionEmbedding, XPOSPositionEmbedding
  from nemo.collections.nlp.modules.common.megatron.position_embedding.rotary_position_embedding import apply_rotary_pos_emb
  from nemo.collections.nlp.modules.common.megatron.utils import init_method_normal
label_desc: Use image node_id 6 for calling a global function with example usage: test_rotary(cfg) without return types