code: def rotate_half(x, interleaved=False):
      if not interleaved:
          x1, x2 = x.chunk(2, dim=-1)
          return torch.cat((-x2, x1), dim=-1)
      else:
          x1, x2 = x[..., ::2], x[..., 1::2]
          return rearrange(
              torch.stack((-x2, x1), dim=-1),
              "... d two -> ... (d two)",
              two=2,
          )
  
imports: import math
  from typing import Optional, Tuple, Union
  import torch
  from einops import rearrange, repeat
  from flash_attn.ops.triton.rotary import apply_rotary
label_desc: Use image node_id 1 for calling a global function with example usage: rotate_half(x, interleaved) and returns: torch, rearrange