code: def apply_rotary_emb(x: Tensor, freqs_cis: Tensor) -> Tensor:
      xshaped = x.float().reshape(*x.shape[:-1], -1, 2)
      freqs_cis = freqs_cis.view(
          1, xshaped.size(1), 1, xshaped.size(3), 2
      )
      x_out2 = torch.stack(
          [
              xshaped[..., 0] * freqs_cis[..., 0]
              - xshaped[..., 1] * freqs_cis[..., 1],
              xshaped[..., 1] * freqs_cis[..., 0]
              + xshaped[..., 0] * freqs_cis[..., 1],
          ],
          -1,
      )
  
      x_out2 = x_out2.flatten(3)
      return x_out2.type_as(x)
  
imports: from dataclasses import dataclass
  from typing import Optional
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 3 for calling a global function with example usage: apply_rotary_emb(x, freqs_cis) and returns: x_out2