class_docstr: Rotary positional embedding (RoPE) from [Su et al 2022](https://arxiv.org/abs/2104.09864).
  
  Args:
      dim (int): Embedding dimension (twice the number of frequencies).
      max_period (float): Maximum period of the rotation frequencies.
      xpos (bool): Use xPos, applies an exponential decay to rotation matrix.
      scale (float): Scale of positional embedding, set to 0 to deactivate.
      device (torch.device, optional): Device on which to initialize the module.
      dtype (torch.dtype): dtype to use to generate the embedding.
class_docstr_tok: ["Rotary","positional","embedding","(","RoPE",")","from","[","Su","et","al","2022","]","(","https",":","\/\/arxiv.org\/abs\/2104.09864",")",".","Args",":","dim","(","int",")",":","Embedding","dimension","(","twice","the","number","of","frequencies",")",".","max_period","(","float",")",":","Maximum","period","of","the","rotation","frequencies",".","xpos","(","bool",")",":","Use","xPos",",","applies","an","exponential","decay","to","rotation","matrix",".","scale","(","float",")",":","Scale","of","positional","embedding",",","set","to","0","to","deactivate",".","device","(","torch.device",",","optional",")",":","Device","on","which","to","initialize","the","module",".","dtype","(","torch.dtype",")",":","dtype","to","use","to","generate","the","embedding","."]
code: def __init__(
      self,
      dim: int,
      max_period: float = 10000.0,
      xpos: bool = False,
      scale: float = 1.0,
      device=None,
      dtype: torch.dtype = torch.float32,
  ):
      super().__init__()
      assert dim % 2 == 0
      self.scale = scale
      assert dtype in [torch.float64, torch.float32]
      self.dtype = dtype
  
      adim = torch.arange(0, dim, 2, device=device, dtype=dtype)[
          : (dim // 2)
      ]
      frequencies = 1.0 / (max_period ** (adim / dim))
      self.register_buffer("frequencies", frequencies)
      self.rotation: tp.Optional[torch.Tensor] = None
  
      self.xpos = (
          XPos(dim, device=device, dtype=dtype) if xpos else None
      )
  
file_path: audiocraft/audiocraft/modules/rope.py
imports: import typing
  from torch import nn
  import torch
label_desc: Use image node_id 1 to create a new RotaryEmbedding object from inherited base classes: nn with example: obj = RotaryEmbedding(dim, max_period, xpos, scale, device, dtype)