class_docstr: Length-extrapolatable positional embedding (xPos) from [Sun et al 2022](https://arxiv.org/abs/2212.10554v1).
  This applies an exponential decay to the RoPE rotation matrix.
  
  Args:
      dim (int): Embedding dimension.
      smoothing (float): Smoothing factor applied to the decay rates.
      base_scale (int): Base decay rate, given in terms of scaling time.
      device (torch.device, optional): Device on which to initialize the module.
      dtype (torch.dtype): dtype to use to generate the embedding.
class_docstr_tok: ["Length-extrapolatable","positional","embedding","(","xPos",")","from","[","Sun","et","al","2022","]","(","https",":","\/\/arxiv.org\/abs\/2212.10554v1",")",".","This","applies","an","exponential","decay","to","the","RoPE","rotation","matrix",".","Args",":","dim","(","int",")",":","Embedding","dimension",".","smoothing","(","float",")",":","Smoothing","factor","applied","to","the","decay","rates",".","base_scale","(","int",")",":","Base","decay","rate",",","given","in","terms","of","scaling","time",".","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,
      smoothing: float = 0.4,
      base_scale: int = 512,
      device=None,
      dtype: torch.dtype = torch.float32,
  ):
      super().__init__()
      assert dim % 2 == 0
      assert dtype in [torch.float64, torch.float32]
      self.dtype = dtype
      self.base_scale = base_scale
  
      half_dim = dim // 2
      adim = torch.arange(half_dim, device=device, dtype=dtype)
      decay_rates = (adim / half_dim + smoothing) / (1.0 + smoothing)
      self.register_buffer("decay_rates", decay_rates)
      self.decay: tp.Optional[torch.Tensor] = 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 XPos object from inherited base classes: nn with example: obj = XPos(dim, smoothing, base_scale, device, dtype)